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.
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.
- Instead of specifying
image: foo, let users specify
- Automatically build the specified Dockerfile and use the resulting image for the job
- Connect that with
docker build --from-cacheso it works in a distributed environment too.
image: dockerfile: Dockerfile.ci cache: - $CI_REGISTRY:latest
- 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.
docker build --from-cachesolve this problem?
- Since custom Docker images are really just improvement over
apt-geting 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.