2018-08-31 04:36:26 -05:00
|
|
|
const path = require('path');
|
|
|
|
const {spawnSync} = require('child_process');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const dotenv = require('dotenv');
|
|
|
|
|
|
|
|
const {emitObject, emitString} = require('./compose');
|
|
|
|
|
2018-09-02 07:25:51 -05:00
|
|
|
['.common.env', '.production.env', '.env'].forEach((filename) => {
|
2018-08-31 04:36:26 -05:00
|
|
|
dotenv.config({path: path.join(__dirname, filename)});
|
|
|
|
});
|
|
|
|
|
|
|
|
const cwd = process.cwd();
|
|
|
|
const distPath = path.join(cwd, 'dist', 'production');
|
|
|
|
|
|
|
|
const services = process.env.SERVICES.split(',');
|
|
|
|
services.push('gateway');
|
|
|
|
|
|
|
|
const composeFile = emitString(emitObject(services));
|
|
|
|
|
|
|
|
spawnSync('mkdir', ['-p', distPath]);
|
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(distPath, 'docker-compose.yml'), composeFile
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.copyFileSync(
|
|
|
|
path.join(cwd, '.common.env'),
|
|
|
|
path.join(distPath, '.env'),
|
|
|
|
);
|
|
|
|
|
|
|
|
fs.appendFileSync(
|
|
|
|
path.join(distPath, '.env'),
|
2018-09-02 07:25:51 -05:00
|
|
|
fs.readFileSync(path.join(cwd, '.production.env')),
|
2018-08-31 04:36:26 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
fs.appendFileSync(
|
|
|
|
path.join(distPath, '.env'),
|
|
|
|
fs.readFileSync(path.join(cwd, '.env')),
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const service of services) {
|
|
|
|
|
|
|
|
const servicePath = path.join(cwd, 'services', service);
|
|
|
|
const serviceDistPath = path.join(distPath, service);
|
|
|
|
|
|
|
|
spawnSync('mkdir', ['-p', serviceDistPath]);
|
|
|
|
|
|
|
|
spawnSync('docker', [
|
|
|
|
'run',
|
|
|
|
'--env-file', './.common.env',
|
2018-09-02 07:25:51 -05:00
|
|
|
'--env-file', './.production.env',
|
2018-08-31 04:36:26 -05:00
|
|
|
'--env-file', './.env',
|
|
|
|
|
|
|
|
'-e', 'DEBUG=truss:*',
|
|
|
|
'-e', 'DEBUG_COLORS=1',
|
|
|
|
'-e', 'DEBUG_HIDE_DATE=1',
|
|
|
|
'-e', 'NODE_PRESERVE_SYMLINKS=1',
|
|
|
|
|
|
|
|
'-v', `${path.join(cwd, 'lib')}:/var/node/lib:ro`,
|
|
|
|
'-v', `${servicePath}:/var/node/src:ro`,
|
|
|
|
'-v', `${serviceDistPath}:/var/node/dist`,
|
|
|
|
|
|
|
|
'docker.i12e.cha0s.io/cha0s6983/truss-dev',
|
|
|
|
|
|
|
|
'yarn', 'run', 'build',
|
|
|
|
], {
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
|
|
|
|
|
|
|
spawnSync('rm', [
|
|
|
|
'-rf',
|
|
|
|
path.join(serviceDistPath, 'node_modules'),
|
|
|
|
path.join(serviceDistPath, 'package.json'),
|
|
|
|
path.join(serviceDistPath, 'yarn.lock'),
|
|
|
|
]);
|
|
|
|
}
|