-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathtime.docker.js
34 lines (28 loc) · 1.06 KB
/
time.docker.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
const spawn = require("child_process").spawn;
const request = require("request");
const pingIntervalMs = 10;
const args = process.argv.slice(2);
if (args.length == 0) {
console.log('The path of java executable jar must be specified !');
}
const dockerImageName = args[0];
const dockerContainerName = args[1];
spawn("docker", ["run", "--rm", "-d", "--network=host", "--name="+dockerContainerName, dockerImageName+":latest"]);
const startTime = new Date().getTime();
const intervalHandle = setInterval(() => {
request("http://localhost:8080/hello/John", (error, response, body) => {
if (!error && response && response.statusCode === 200 && body) {
const time = new Date().getTime() - startTime;
console.log(time + " ms");
clearInterval(intervalHandle);
spawn("docker", ["stop", dockerContainerName]);
process.exit(0);
} else {
// @ts-ignore
if (!error || !error.code === "ECONNREFUSED") {
console.log(error ? error : response.statusCode);
}
}
}
);
}, pingIntervalMs);