myt/docker-run.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-11-16 13:23:28 +00:00
const path = require('path');
const execFile = require('child_process').execFile;
2020-11-14 01:38:56 +00:00
const spawn = require('child_process').spawn;
module.exports = async function(command, workspace, ...args) {
2020-11-14 01:38:56 +00:00
const buildArgs = [
'build',
2020-11-14 14:53:13 +00:00
'-t', 'myvc/client',
2020-11-16 13:23:28 +00:00
'-f', path.join(__dirname, 'Dockerfile.client'),
__dirname
2020-11-14 01:38:56 +00:00
];
2020-11-16 13:23:28 +00:00
await new Promise((resolve, reject) => {
execFile('docker', buildArgs, (err, stdout, stderr) => {
if (err)
return reject(err);
resolve({stdout, stderr});
});
})
2020-11-14 01:38:56 +00:00
2020-11-15 18:24:25 +00:00
let runArgs = [
2020-11-14 01:38:56 +00:00
'run',
'-v', `${workspace}:/workspace`,
2020-11-14 14:53:13 +00:00
'myvc/client',
2020-11-14 01:38:56 +00:00
command
];
2020-11-15 18:24:25 +00:00
runArgs = runArgs.concat(args);
2020-11-14 01:38:56 +00:00
2020-11-16 13:23:28 +00:00
await new Promise((resolve, reject) => {
const child = spawn('docker', runArgs, {
stdio: [
process.stdin,
process.stdout,
process.stderr
]
});
child.on('exit', code => resolve(code));
})
2020-11-14 01:38:56 +00:00
};