Skip to content

Commit eea133b

Browse files
committed
tasks: centralise all required docker-related tasks in 1 script
- npm run docker -- <pull | run | setup | stop | remove> will now handle all docker-related tasks
1 parent 2d50507 commit eea133b

File tree

6 files changed

+62
-41
lines changed

6 files changed

+62
-41
lines changed

circle.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ machine:
1111

1212
dependencies:
1313
pre:
14-
- docker pull plotly/testbed:latest
14+
- eval $(node tasks/docker.js pull)
1515
post:
16-
- eval $(node tasks/run_docker.js)
16+
- eval $(node tasks/docker.js run)
1717
- npm run cibuild
1818
- npm run pretest
19-
- eval $(node tasks/setup_docker.js)
19+
- eval $(node tasks/docker.js setup)
2020

2121
test:
2222
override:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"watch": "node tasks/watch.js",
3131
"lint": "eslint . || true",
3232
"lint-fix": "eslint . --fix",
33+
"docker": "node tasks/docker.js",
3334
"pretest": "node tasks/pretest.js",
3435
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3536
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",

tasks/docker.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
var constants = require('./util/constants');
2+
var common = require('./util/common');
3+
var containerCommands = require('./util/container_commands');
4+
5+
var isCI = process.env.CIRCLECI;
6+
var arg = process.argv[2];
7+
8+
var msg, cmd, cb, errorCb;
9+
10+
switch(arg) {
11+
12+
case 'pull':
13+
msg = 'Pulling latest docker image';
14+
cmd = 'docker pull ' + constants.testContainerImage;
15+
break;
16+
17+
case 'run':
18+
msg = 'Booting up ' + constants.testContainerName + ' docker container';
19+
cmd = containerCommands.dockerRun;
20+
21+
// if docker-run fails, try docker-start.
22+
errorCb = function(err) {
23+
if(err) common.execCmd('docker start ' + constants.testContainerName);
24+
};
25+
26+
break;
27+
28+
case 'setup':
29+
msg = 'Setting up ' + constants.testContainerName + ' docker container for testing';
30+
cmd = containerCommands.getRunCmd(isCI, containerCommands.setup);
31+
break;
32+
33+
case 'stop':
34+
msg = 'Stopping ' + constants.testContainerName + ' docker container';
35+
cmd = 'docker stop ' + constants.testContainerName;
36+
break;
37+
38+
case 'remove':
39+
msg = 'Removing ' + constants.testContainerName + ' docker container';
40+
cmd = 'docker rm ' + constants.testContainerName;
41+
break;
42+
43+
default:
44+
console.log('Usage: pull, run, setup, stop, remove');
45+
process.exit(0);
46+
break;
47+
}
48+
49+
// Log command string on CircleCI, to then `eval` them,
50+
// which appears to be more reliable then calling `child_process.exec()`
51+
if(isCI) {
52+
console.log(cmd);
53+
}
54+
else {
55+
console.log(msg);
56+
common.execCmd(cmd, cb, errorCb);
57+
}

tasks/run_docker.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

tasks/setup_docker.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

tasks/util/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ module.exports = {
7575
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
7676
pathToSetPlotConfig: path.join(pathToBuild, 'set_plot_config.js'),
7777

78+
testContainerImage: 'plotly/testbed:latest',
7879
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'imagetest',
7980
testContainerPort: '9010',
8081
testContainerUrl: 'http://localhost:9010/',

0 commit comments

Comments
 (0)