2018-08-31 04:36:26 -05:00
|
|
|
const yaml = require('js-yaml');
|
|
|
|
|
|
|
|
exports.emitString = function(object) {
|
|
|
|
return yaml.safeDump(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.emitObject = function(services) {
|
|
|
|
|
|
|
|
services = services.slice(0);
|
|
|
|
if (-1 === services.indexOf('gateway')) {
|
|
|
|
services.push('gateway');
|
|
|
|
}
|
|
|
|
|
|
|
|
const composeFile = {
|
|
|
|
version: '3',
|
|
|
|
services: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const service of services) {
|
|
|
|
composeFile.services[service] = emitService(service);
|
2018-09-02 07:25:51 -05:00
|
|
|
const modulePath = `./services/${service}/compose`;
|
|
|
|
try {
|
|
|
|
require(modulePath)(composeFile.services[service]);
|
|
|
|
console.log('compose');
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
const message = `Cannot find module '${modulePath}'`;
|
|
|
|
if (message !== error.message) {
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 04:36:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return composeFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
function emitService(service) {
|
|
|
|
const definition = {};
|
|
|
|
|
|
|
|
definition.image = `docker.i12e.cha0s.io/cha0s6983/truss-${
|
|
|
|
'production' === process.env.NODE_ENV ? 'production': 'dev'
|
|
|
|
}`;
|
|
|
|
if ('production' === process.env.NODE_ENV) {
|
|
|
|
definition.env_file = [
|
|
|
|
'.env',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
definition.env_file = [
|
|
|
|
'.common.env', `.dev.env`, '.env',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
if ('production' === process.env.NODE_ENV) {
|
|
|
|
definition.volumes = [
|
|
|
|
`./${service}:/var/node/dist`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
definition.volumes = [
|
|
|
|
'./lib:/var/node/lib',
|
|
|
|
`./services/${service}:/var/node/src`,
|
|
|
|
`./dist/dev/${service}:/var/node/dist`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return definition;
|
|
|
|
}
|