-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
46 lines (39 loc) · 1.37 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const spawn = require('child_process').spawn;
const options = require('../package.json').localDev;
const freeport = require('freeport')
console.log(__dirname)
freeport((err, mysqlPort) => {
freeport((err, xdebugPort) => {
freeport((err, dockerPort) => {
dockerPort = dockerPort.toString()
console.log(dockerPort)
const docker = spawn('docker', ['run', '--name', options.name, '--env-file', __dirname + '\\env.list',
'-p', dockerPort + ':80', xdebugPort + ':9000', mysqlPort + ':3306', '-v', __dirname + "\\..:/var/www/html/wp-content/themes/site-theme/",
'-e', 'WP_URL=localhost:' + dockerPort, options.imageName]);
docker.stdout.on('data', (data) => {
console.log(`${data}`);
});
docker.stderr.on('data', (data) => {
console.log(`${data}`);
});
docker.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
var cleanExit = function () {
docker.kill('SIGINT');
const dockerExit = spawn('docker', ['stop', options.name])
dockerExit.stdout.on('data', (data) => {
console.log(`${data}`);
});
dockerExit.stderr.on('data', (data) => {
console.log(`${data}`);
});
dockerExit.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
};
process.on('SIGINT', cleanExit); // catch ctrl-c
process.on('SIGTERM', cleanExit); // catch kill
})
})
})