Skip to content

Commit 00f0dbf

Browse files
authored
Merge pull request #924 from plotly/drop-docker-compose
Drop docker-compose
2 parents 937e6ba + 0110983 commit 00f0dbf

File tree

10 files changed

+107
-84
lines changed

10 files changed

+107
-84
lines changed

.npmignore

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ test
88
dist/extras
99

1010
circle.yml
11-
docker-compose.yml
1211
bower.json
1312

1413
.ackrc

circle.yml

+3-3
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:

docker-compose.yml

-20
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"watch": "node tasks/watch.js",
3131
"lint": "eslint --version && 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

+57
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

-18
This file was deleted.

tasks/setup_docker.js

-20
This file was deleted.

tasks/util/common.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
var fs = require('fs');
22
var exec = require('child_process').exec;
33

4-
exports.execCmd = function(cmd, cb) {
4+
exports.execCmd = function(cmd, cb, errorCb) {
5+
cb = cb ? cb : function() {};
6+
errorCb = errorCb ? errorCb : function(err) { if(err) throw err; };
7+
58
exec(cmd, function(err) {
6-
if(err) throw err;
7-
if(cb) cb();
9+
errorCb(err);
10+
cb();
811
})
912
.stdout.pipe(process.stdout);
1013
};

tasks/util/constants.js

+1
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/',

test/image/README.md

+39-19
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
Test plotly.js with Plotly's image testing docker container.
44

55
Requirements:
6-
- `docker` | [installation guidelines](http://docs.docker.com/engine/installation/)
7-
- `docker-machine` (for Mac and Windows users only) | [installation guidelines](https://docs.docker.com/machine/install-machine/)
8-
- `docker-compose` | [installation guidelines](https://docs.docker.com/compose/install/)
6+
- `docker` | [installation guidelines][docker-install]
7+
- `docker-machine` (for Mac and Windows users only) | [installation guidelines][docker-machine-install]
98

109
### Step 0: Start the docker machine (Mac and Windows users only)
1110

@@ -21,7 +20,7 @@ If this is your first time, you'll need to create the machine instead:
2120
docker-machine create --driver virtualbox default
2221
```
2322

24-
Set up the docker environment for `docker-compose`:
23+
Set up the docker environment:
2524

2625
```bash
2726
eval $(docker-machine env default)
@@ -30,25 +29,33 @@ eval $(docker-machine env default)
3029
the above evaluates the output of `docker-machine env default`.
3130

3231

33-
### Step 1: Run the testing container
32+
### Step 1: Setup the testing container
3433

35-
We use `docker-compose` to ease the creation/stopping/deletion of the testing docker container.
34+
After `cd` into your `plotly.js` directory, pull the latest docker image with
3635

37-
Inside your `plotly.js` directory, run
36+
```bash
37+
npm run docker -- pull
38+
```
39+
40+
which calls [`docker-pull`][docker-pull] with the correct arguments grabbing the
41+
latest docker image as listed on [hub.docker.com][docker-hub].
42+
43+
Run the container with
3844

3945
```bash
40-
docker-compose up -d
46+
npm run docker -- run
4147
```
4248

43-
In the `docker-compose.yml` file, `latest` is the latest Plotly Image-Server docker container version
44-
as listed on [hub.docker.com](https://hub.docker.com/r/plotly/testbed/tags/) and
45-
`imagetest` is the name of the docker container. The `-d` flag tells docker to start the containers in the background and leave them running.
49+
which calls [`docker-run`][docker-run] or [`docker-start`][docker-start] with
50+
the correct arguments.
51+
4652

4753
### Step 2: Run the image tests
4854

49-
The image testing docker container allows plotly.js developers to ([A](#a-run-image-comparison-tests)) run image
50-
comparison tests, ([B](#b-run-image-export-tests)) run image export tests and ([C](#c-generate-or-update-existing-baseline-image)) generate baseline
51-
images.
55+
The image testing docker container allows plotly.js developers to
56+
([A](#a-run-image-comparison-tests)) run image comparison tests,
57+
([B](#b-run-image-export-tests)) run image export tests and
58+
([C](#c-generate-or-update-existing-baseline-image)) generate baseline images.
5259

5360
**IMPORTANT:** the image tests scripts do **not** bundle the source files before
5461
running the image tests. We recommend running `npm run watch` or `npm start` in
@@ -60,8 +67,7 @@ Image comparison tests take in plotly.js mock json files (found in
6067
[`test/image/mocks`][mocks]), generate test png images (saved in
6168
`build/test_images/` - which is git-ignored) and compare them pixel-by-pixel to
6269
their corresponding baseline images (found in
63-
[`test/image/baselines`][baselines]) using
64-
[`GraphicsMagick`](https://github.com/aheckmann/gm).
70+
[`test/image/baselines`][baselines]) using [`GraphicsMagick`][gm].
6571

6672
To run the image comparison tests, in your `plotly.js` directory:
6773

@@ -73,7 +79,7 @@ which runs all image comparison tests in batch. If some tests fail, compare thei
7379
by booting up the test image viewer using `npm run start-image_viewer`.
7480

7581
As an alternative to running all image comparison tests at once, you can provide
76-
a [glob](https://github.com/isaacs/node-glob) as argument to target one or multiple test mocks found in
82+
a [glob][glob] as argument to target one or multiple test mocks found in
7783
[`test/image/mocks`][mocks].
7884
For example,
7985

@@ -132,9 +138,11 @@ npm run baseline -- <glob-of-mocks-to-update>
132138
Once done testing, inside your `plotly.js` directory, run
133139

134140
```bash
135-
docker-compose stop
141+
npm run docker -- stop
136142
```
137143

144+
which calls [`docker-stop`][docker-stop] with the correct arguments.
145+
138146
Mac and Windows user should also kill their docker-machine (named `default`) once done testing:
139147

140148
```bash
@@ -174,9 +182,11 @@ whereas `docker ps` lists only the started containers.
174182
Inside your `plotly.js` directory, run
175183

176184
```bash
177-
docker-compose rm -f
185+
npm run docker -- remove
178186
```
179187

188+
which calls [`docker-rm`][docker-rm] with the correct arguments.
189+
180190
##### Remove your docker machine
181191

182192
If named `default`:
@@ -189,3 +199,13 @@ For more comprehensive information about docker, please refer to the [docker doc
189199

190200
[mocks]: https://github.com/plotly/plotly.js/tree/master/test/image/mocks
191201
[baselines]: https://github.com/plotly/plotly.js/tree/master/test/image/baselines
202+
[docker-install]: http://docs.docker.com/engine/installation/
203+
[docker-machine-install]: https://docs.docker.com/machine/install-machine/
204+
[docker-hub]: https://hub.docker.com/r/plotly/testbed/tags/
205+
[docker-pull]: https://docs.docker.com/engine/reference/commandline/pull/
206+
[docker-run]: https://docs.docker.com/engine/reference/commandline/run/
207+
[docker-start]: https://docs.docker.com/engine/reference/commandline/start/
208+
[docker-stop]: https://docs.docker.com/engine/reference/commandline/stop/
209+
[docker-rm]: https://docs.docker.com/engine/reference/commandline/rm/
210+
[gm]: https://github.com/aheckmann/gm
211+
[glob]: https://github.com/isaacs/node-glob

0 commit comments

Comments
 (0)