See the accompanying blog post here for more information.
The run-containerized script uses the dockerfiles/ci/Dockerfile
in your project to build a container to run your tests in during the Jenkins job execution. Docker automatically caches containers so there's almost no overhead after the initial run of the job where the container is actually build.
The jobs workspace is mounted in the container under /workspace
. Each container get's a /cache
directory mounted that is dedicated to that job. Whatever is stored in this directory is persisted accross builds. This can be used for example to store Ruby Bundler gems, the local Maven repository etc.
For more information read the run-containerized script, it's well documented.
- Make sure your Jenkins slaves can run Docker containers.
- Make sure the user running your Jenkins jobs (usually
jenkins
) is allowed to run Docker containers. - Put the run-containerized script in your Jenkins
$PATH
. - Check in a Dockerfile into your project at
dockerfiles/ci/Dockerfile
. - Configure your jobs with an
Execute shell
step and prefix your CI command(s) withrun-containerized
, for examplerun-containerized 'bin/ci'
.
- Make sure that you configure your Dockerfile to store cachable artifacts in the
/cache
directory. For Ruby projects using Bundler this can be done by puttingRUN bundle config --global path /cache/
in the Dockerfile. - If you need any services running during the build (for example PostgreSQL, Redis etc) make sure to include them in the Dockerfile. The file
/usr/local/bin/init-container
is automatically invoked just before your CI command is run, this can be used to start your services.
See example-dockerfiles for some example Dockerfiles to use in your project. These files demonstrate the usage of the /cache
directory and the starting of services using /usr/local/bin/init-container
.
- Builds currently run as root inside the container. This is not as scary as it sounds but you should be aware of possible security risks when you allow untrusted people to run builds on your CI server (for example Pull Requests on a public project).