Skip to content

Drop docker-compose #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ test
dist/extras

circle.yml
docker-compose.yml
bower.json

.ackrc
Expand Down
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ machine:

dependencies:
pre:
- docker pull plotly/testbed:latest
- eval $(node tasks/docker.js pull)
post:
- eval $(node tasks/run_docker.js)
- eval $(node tasks/docker.js run)
- npm run cibuild
- npm run pretest
- eval $(node tasks/setup_docker.js)
- eval $(node tasks/docker.js setup)

test:
override:
Expand Down
20 changes: 0 additions & 20 deletions docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"watch": "node tasks/watch.js",
"lint": "eslint . || true",
"lint-fix": "eslint . --fix",
"docker": "node tasks/docker.js",
"pretest": "node tasks/pretest.js",
"test-jasmine": "karma start test/jasmine/karma.conf.js",
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
Expand Down
57 changes: 57 additions & 0 deletions tasks/docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var constants = require('./util/constants');
var common = require('./util/common');
var containerCommands = require('./util/container_commands');

var isCI = process.env.CIRCLECI;
var arg = process.argv[2];

var msg, cmd, cb, errorCb;

switch(arg) {

case 'pull':
msg = 'Pulling latest docker image';
cmd = 'docker pull ' + constants.testContainerImage;
break;

case 'run':
msg = 'Booting up ' + constants.testContainerName + ' docker container';
cmd = containerCommands.dockerRun;

// if docker-run fails, try docker-start.
errorCb = function(err) {
if(err) common.execCmd('docker start ' + constants.testContainerName);
};

break;

case 'setup':
msg = 'Setting up ' + constants.testContainerName + ' docker container for testing';
cmd = containerCommands.getRunCmd(isCI, containerCommands.setup);
break;

case 'stop':
msg = 'Stopping ' + constants.testContainerName + ' docker container';
cmd = 'docker stop ' + constants.testContainerName;
break;

case 'remove':
msg = 'Removing ' + constants.testContainerName + ' docker container';
cmd = 'docker rm ' + constants.testContainerName;
break;

default:
console.log('Usage: pull, run, setup, stop, remove');
process.exit(0);
break;
}

// Log command string on CircleCI, to then `eval` them,
// which appears to be more reliable then calling `child_process.exec()`
if(isCI) {
console.log(cmd);
}
else {
console.log(msg);
common.execCmd(cmd, cb, errorCb);
}
18 changes: 0 additions & 18 deletions tasks/run_docker.js

This file was deleted.

20 changes: 0 additions & 20 deletions tasks/setup_docker.js

This file was deleted.

9 changes: 6 additions & 3 deletions tasks/util/common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
var fs = require('fs');
var exec = require('child_process').exec;

exports.execCmd = function(cmd, cb) {
exports.execCmd = function(cmd, cb, errorCb) {
cb = cb ? cb : function() {};
errorCb = errorCb ? errorCb : function(err) { if(err) throw err; };

exec(cmd, function(err) {
if(err) throw err;
if(cb) cb();
errorCb(err);
cb();
})
.stdout.pipe(process.stdout);
};
Expand Down
1 change: 1 addition & 0 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module.exports = {
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
pathToSetPlotConfig: path.join(pathToBuild, 'set_plot_config.js'),

testContainerImage: 'plotly/testbed:latest',
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'imagetest',
testContainerPort: '9010',
testContainerUrl: 'http://localhost:9010/',
Expand Down
58 changes: 39 additions & 19 deletions test/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
Test plotly.js with Plotly's image testing docker container.

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

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

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

Set up the docker environment for `docker-compose`:
Set up the docker environment:

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


### Step 1: Run the testing container
### Step 1: Setup the testing container

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

Inside your `plotly.js` directory, run
```bash
npm run docker -- pull
```

which calls [`docker-pull`][docker-pull] with the correct arguments grabbing the
latest docker image as listed on [hub.docker.com][docker-hub].

Run the container with

```bash
docker-compose up -d
npm run docker -- run
```

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


### Step 2: Run the image tests

The image testing docker container allows plotly.js developers to ([A](#a-run-image-comparison-tests)) run image
comparison tests, ([B](#b-run-image-export-tests)) run image export tests and ([C](#c-generate-or-update-existing-baseline-image)) generate baseline
images.
The image testing docker container allows plotly.js developers to
([A](#a-run-image-comparison-tests)) run image comparison tests,
([B](#b-run-image-export-tests)) run image export tests and
([C](#c-generate-or-update-existing-baseline-image)) generate baseline images.

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

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

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

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

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

```bash
docker-compose stop
npm run docker -- stop
```

which calls [`docker-stop`][docker-stop] with the correct arguments.

Mac and Windows user should also kill their docker-machine (named `default`) once done testing:

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

```bash
docker-compose rm -f
npm run docker -- remove
```

which calls [`docker-rm`][docker-rm] with the correct arguments.

##### Remove your docker machine

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

[mocks]: https://github.com/plotly/plotly.js/tree/master/test/image/mocks
[baselines]: https://github.com/plotly/plotly.js/tree/master/test/image/baselines
[docker-install]: http://docs.docker.com/engine/installation/
[docker-machine-install]: https://docs.docker.com/machine/install-machine/
[docker-hub]: https://hub.docker.com/r/plotly/testbed/tags/
[docker-pull]: https://docs.docker.com/engine/reference/commandline/pull/
[docker-run]: https://docs.docker.com/engine/reference/commandline/run/
[docker-start]: https://docs.docker.com/engine/reference/commandline/start/
[docker-stop]: https://docs.docker.com/engine/reference/commandline/stop/
[docker-rm]: https://docs.docker.com/engine/reference/commandline/rm/
[gm]: https://github.com/aheckmann/gm
[glob]: https://github.com/isaacs/node-glob