We want to give it a try to setup CI/CD with Jenkins for our project. The project itself has Elasticsearch and PostgreSQL as runtime dependencies and Webdriver for acceptance testing.
In dev environment, everything is set up within one docker-compose.yml
file and we have acceptance.sh
script to run acceptance tests.
After digging documentation I found that it's potentially possible to build CI with following steps:
docker-compose.yml
and project Dockerfile
- either:
docker-compose up
ONBUILT
section to run tests. Unit tests are run through mix tests
and acceptance through scripts/acceptance.sh
. It'll be cool to run them in parallel. docker-compose
, clean up containersBecause this is my first experience with Jenkins a series of questions arise:
Thanks
To run a Docker image, you must have Docker installed. Docker provides detailed instructions for installation on Linux, macOS, and Windows. Note that while recent versions of Windows gained native support for running Docker images, Jenkins only provides Linux based Docker images.
To run docker inside docker, all you have to do it just run docker with the default Unix socket docker. sock as a volume. Just a word of caution: If your container gets access to docker. sock , it means it has more privileges over your docker daemon.
Is this a viable strategy?
Yes it is. I think it would be better to include the docker-compose.yml
and Dockerfile
in the project repo. That way any changes are tied to the version of code that uses the changes. If it's in an external repo it becomes a lot harder to change (unless you pin the git sha somehow , like using a submodule).
project's Dockerfile will have
ONBUILD
section to run tests
I would avoid this. Just set a different command to run the tests in a container, not at build time.
How to connect tests output with Jenkins?
Jenkins just uses the exit status from the build steps, so as long as the test script exits with a non-zero code on failure and a zero code on success that's all you need. Test output that is printed to stdout/stderr will be visible from jenkins console.
How to run and shut down docker-compose?
I would recommend this to run Compose:
docker-compose pull # if you use images from the hub, pull the latest version
docker-compose up --build -d
In a post-build step to shutdown:
docker-compose down --volumes
Do we need/want to write a pipeline for that?
No, I think just a single job is fine. Get it working with a simple setup first, and then you can figure out what you need to split into different jobs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With