Integration Testing With CircleCI 2.0 and Docker Compose

Greg Orzell
Chaotic Snippets
Published in
2 min readMay 4, 2017

Running integration tests in Circle 2.0 against a Docker Compose stack turned out to be much more complicated than I had hoped and certainly much more complex than it used to be. Some of these issues are probably easily resolved by switching which of their execution environments[1] you are using, but there are pros and cons to that as they mention in the documentation.

These are the steps that I ended up with:

  1. Add docker remote support.
- setup_remote_docker

2. Start the compose containers.

compose-it: #: Compose dependencies for integration tests.
docker-compose -f docker-compose.yaml up -d
# Give the services a chance to start up.
sleep 45

3. Start create an additional build container.

4. Attach it to the compose network.

5. Copy the build working directory into the container.[2]

6. Build and run the integration tests in the additional container.

7. Copy test result files back into the parent build container.[3]

it-ci: #: Setup up and run integration tests in ci.
docker create \
# Run on the compose network.
--network dependencies_default \
# Link to the containers you depend on.
--link api1 \
--link api2 \
# Pass required environment variables.
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY \
# Change working directory
-w /build \
--name it \
# Use the same build image we are using for the parent.
keen/build-scala:master \
# Run the integration tests.
make it
# Copy the entire build context into the container.
docker cp . it:/build
# Copy the caches from the parent since we already did a compile and unit tests.
docker cp ~/.sbt it:/root
docker cp ~/.ivy2 it:/root
# Now that everything is configured and copied, execute the container.
docker start -a it
# Copy out the test results.
docker cp it:/build/target/test-reports target/it/

[1] If you have a very simple set of integration test dependencies, then you might not need to use compose at all and could instead use the multiple container feature of the docker execution environment.

[2] Their suggested method of adding files is overly complex, you don’t really need a helper container, you just need to use create instead of run.

[3] Unfortunately I haven’t yet figured out how to do this when the tests fail, so you only get test results when they pass, with isn’t super helpful. :-(

Full Code Snippets

Related Documents

--

--