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); 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); } } } 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; }