Right now our Jenkins agents generate a docker-compose.yml for each of our Rails projects and then run docker-compose up. The docker-compose.yml has a main "web" container that has rbenv and all of our other Rails dependencies inside. It is linked to a DB container that contains the test Postgres DB.
The problem comes when we need to actually run the tests and generate exit codes. Our CI server will only deploy if the test script returns exit 0, but docker-compose always returns 0, even if one of the container commands fail.
The other issue is that the DB container runs indefinitely, even after the web container is done running the tests, so docker-compose up
never returns.
Is there a way we can use docker-compose for this process? We would need to be able to run the containers, but exit after the web container is complete and return it's exit code. Right now we are stuck manually using docker to spin up the DB container and run the web container with the --link option.
In case you might run more docker-compose services with same name on one docker engine, and you don't know the exact name:
echo %?
- returns exit code from test-chrome serviceBenefits:
Use
docker wait
to get the exit code:foo
is the "project name". In the example above, I specified it explicitly, but if you don't supply it, it's the directory name.bar
is the name you give to the system under test in your docker-compose.yml.Note that
docker logs -f
does the right thing, too, exiting when the container stops. So you can putbetween the
docker-compose up
and thedocker wait
so you can watch your tests run.--exit-code-from SERVICE
and--abort-on-container-exit
don't work in scenarios where you need to run all containers to completion, but fail if one of them exited early. An example might be if running 2 test suits in concurrently in different containers.With @spenthil's suggestion, you can wrap
docker-compose
in a script that will fail if any containers do.Then on your CI server simply change
docker-compose up
to./docker-compose.sh up
.