|
@@ -4,7 +4,6 @@ const hostile = require('hostile');
|
|
const colors = require('colors');
|
|
const colors = require('colors');
|
|
const docker = require('docker-compose');
|
|
const docker = require('docker-compose');
|
|
const log = require('../inc/log');
|
|
const log = require('../inc/log');
|
|
-const shell = require('shelljs');
|
|
|
|
const ProjectEnvironment = require('../classes/ProjectEnvironment');
|
|
const ProjectEnvironment = require('../classes/ProjectEnvironment');
|
|
|
|
|
|
const installHosts = (hosts) => {
|
|
const installHosts = (hosts) => {
|
|
@@ -20,64 +19,44 @@ const installHosts = (hosts) => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-const runServiceHook = (hook, service, projectEnv) => {
|
|
|
|
|
|
+const runServiceStart = (service, projectEnv) => {
|
|
const env = projectEnv.getEnv();
|
|
const env = projectEnv.getEnv();
|
|
const scripts = [
|
|
const scripts = [
|
|
- `${hook}.before`,
|
|
|
|
- `${hook}.before.${env}`,
|
|
|
|
- `${hook}`,
|
|
|
|
- `${hook}.${env}`,
|
|
|
|
- `${hook}.after`,
|
|
|
|
- `${hook}.after.${env}`,
|
|
|
|
|
|
+ 'start.before',
|
|
|
|
+ `start.before.${env}`,
|
|
|
|
+ 'start',
|
|
|
|
+ `start.${env}`,
|
|
|
|
+ 'start.after',
|
|
|
|
+ `start.after.${env}`,
|
|
];
|
|
];
|
|
|
|
|
|
- let scriptArgument = {
|
|
|
|
- service: service,
|
|
|
|
- log: (message) => {
|
|
|
|
- log.log('%s - %s', colors.bold(service), message);
|
|
|
|
- },
|
|
|
|
- env: projectEnv.getEnv(),
|
|
|
|
- shell: (cmd) => {
|
|
|
|
- shell.cd(path.join(projectEnv.getCwd(), service));
|
|
|
|
- const ret = shell.exec(cmd, { fatal: true });
|
|
|
|
- if (ret.code !== 0) {
|
|
|
|
- throw ret.code;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- switch (hook) {
|
|
|
|
- case "start":
|
|
|
|
- scriptArgument.exec = (command, options) => {
|
|
|
|
- const opts = { ...projectEnv.getDockerOptions(), ...options };
|
|
|
|
- return docker.exec(service, command, opts);
|
|
|
|
- };
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
let chain = Promise.resolve();
|
|
let chain = Promise.resolve();
|
|
|
|
|
|
scripts.forEach(script => {
|
|
scripts.forEach(script => {
|
|
chain = chain.then(() => {
|
|
chain = chain.then(() => {
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
|
|
+ return new Promise(resolve => {
|
|
try {
|
|
try {
|
|
- const scriptFunction = require(path.join(projectEnv.getCwd(), service, script));
|
|
|
|
|
|
+ const start = require(path.join(projectEnv.getCwd(), service, script));
|
|
log.log(`\nExecuting %s script for %s...`, colors.bold(script), colors.bold(service));
|
|
log.log(`\nExecuting %s script for %s...`, colors.bold(script), colors.bold(service));
|
|
|
|
|
|
- try {
|
|
|
|
- Promise
|
|
|
|
- .all([scriptFunction({ ...scriptArgument })])
|
|
|
|
- .then(() => {
|
|
|
|
- resolve();
|
|
|
|
- })
|
|
|
|
- .catch((e) => {
|
|
|
|
- reject(e);
|
|
|
|
- });
|
|
|
|
- } catch (ex) {
|
|
|
|
- reject(ex);
|
|
|
|
- }
|
|
|
|
|
|
+ Promise
|
|
|
|
+ .all([start({
|
|
|
|
+ exec: (command, options) => {
|
|
|
|
+ const opts = { ...projectEnv.getDockerOptions(), ...options };
|
|
|
|
+ return docker.exec(service, command, opts);
|
|
|
|
+ },
|
|
|
|
+ log: (message) => {
|
|
|
|
+ log.log('%s - %s', colors.bold(service), message);
|
|
|
|
+ },
|
|
|
|
+ env: projectEnv.getEnv()
|
|
|
|
+ })])
|
|
|
|
+ .catch(() => {
|
|
|
|
+
|
|
|
|
+ })
|
|
|
|
+ .then(() => {
|
|
|
|
+ resolve();
|
|
|
|
+ });
|
|
|
|
+
|
|
} catch (ex) {
|
|
} catch (ex) {
|
|
resolve();
|
|
resolve();
|
|
}
|
|
}
|
|
@@ -85,31 +64,20 @@ const runServiceHook = (hook, service, projectEnv) => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
- return chain.then(() => { });
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-const runServices = async (projectEnv) => {
|
|
|
|
- const services = await projectEnv.getServices();
|
|
|
|
|
|
+ return chain.then(() => {
|
|
|
|
|
|
- let preparePromises = [];
|
|
|
|
- services.forEach(service => {
|
|
|
|
- preparePromises.push(runServiceHook("prepare", service, projectEnv));
|
|
|
|
});
|
|
});
|
|
- try {
|
|
|
|
- await Promise.all(preparePromises);
|
|
|
|
- } catch (e) {
|
|
|
|
- log.error(e);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
+const runServices = async (projectEnv) => {
|
|
await docker.buildAll(projectEnv.getDockerOptions());
|
|
await docker.buildAll(projectEnv.getDockerOptions());
|
|
await docker.upAll(projectEnv.getDockerOptions());
|
|
await docker.upAll(projectEnv.getDockerOptions());
|
|
-
|
|
|
|
- let startPromises = [];
|
|
|
|
|
|
+ const services = await projectEnv.getServices();
|
|
|
|
+ let promises = [];
|
|
services.forEach(service => {
|
|
services.forEach(service => {
|
|
- startPromises.push(runServiceHook("start", service, projectEnv));
|
|
|
|
|
|
+ promises.push(runServiceStart(service, projectEnv));
|
|
});
|
|
});
|
|
- await Promise.all(startPromises);
|
|
|
|
|
|
+ await Promise.all(promises);
|
|
};
|
|
};
|
|
|
|
|
|
module.exports = (env) => {
|
|
module.exports = (env) => {
|