Specify Dockerfile to build image for use in CI/CD
Problem to solve
A common pattern in CI/CD pipelines is to have a custom Docker image that has all the tools needed to efficiently run a job or jobs in the pipeline. But maintaining that Docker image is kind of a pain as you usually have to have a separate project just to declare and build the image. This is fine if you're using the image in tons of other projects, but feels like overkill if it's a custom image for a single project.
Further details
I'd like to be able to specify how to build a Docker image directly in the .gitlab-ci.yml
file rather than having to maintain a separate project.
Proposal
- Instead of specifying
image: foo
, let users specifydockerfile: Dockerfile.ci
- Automatically build the specified Dockerfile and use the resulting image for the job
- Connect that with
docker build --from-cache
so it works in a distributed environment too.
Current Stage
image: foo:tag
Future State
image:
dockerfile: Dockerfile.ci
cache:
- $CI_REGISTRY:latest
Notes/Questions
- One challenge is caching and knowing when to rebuild the image. It should be easy to detect content changes in the Dockerfile, but if any changes are in the base layer, they'll probably be missed. That's probably OK, and we should encourage people to use explicit versions in Dockerfiles rather than pointing to
latest
. That's a general best practice anyway.
- Does
docker build --from-cache
solve this problem?
- Since custom Docker images are really just improvement over
apt-get
ing packages, which would usually be inline in the job, maybe we should let people put the Dockerfile contents inline as well?
What does success look like, and how can we measure that?
More people happily using CI/CD.
Links / references
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.