-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (47 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// npm packages
const fs = require('fs');
const path = require('path');
const phpDockerfile = `FROM arm32v7/php:7.3-apache
COPY . /var/www/html/
RUN chmod -R 755 /var/www/html/
EXPOSE 80
EXPOSE 443
`;
// template name
exports.name = 'exoframe-template-arm32v7-php';
// function to check if the template fits this recipe
exports.checkTemplate = async ({tempDockerDir, folder}) => {
// if project already has dockerfile - just exit
try {
const filesList = fs.readdirSync(path.join(tempDockerDir, folder));
if (filesList.includes('index.php')) {
return true;
}
return false;
} catch (e) {
return false;
}
};
// function to execute current template
exports.executeTemplate = async ({username, tempDockerDir, folder, resultStream, util, docker, existing}) => {
try {
// generate dockerfile
const dockerfile = phpDockerfile;
const dfPath = path.join(tempDockerDir, folder, 'Dockerfile');
fs.writeFileSync(dfPath, dockerfile, 'utf-8');
util.writeStatus(resultStream, {message: 'Deploying PHP Apache project..', level: 'info'});
// build docker image
const buildRes = await docker.build({username, folder, resultStream});
util.logger.debug('Build result:', buildRes);
// start image
const container = await docker.start(Object.assign({}, buildRes, {username, folder, existing, resultStream}));
util.logger.debug(container);
// return new deployments
util.writeStatus(resultStream, {message: 'Deployment success!', deployments: [container], level: 'info'});
resultStream.end('');
} catch (e) {
util.logger.debug('build failed!', e);
util.writeStatus(resultStream, {message: e.error, error: e.error, log: e.log, level: 'error'});
resultStream.end('');
}
};