Make it easy to build a docker image, to be used in subsequent stages if the same project
Description
When writing CI/CD scripts, you often start from a base image, and then add custom software (e.g. using apt-get
). This is fine, but slow. A better way is to do this once, bundle it up into an image, and then use that custom image as the base for your CI/CD scripts. Unfortunately, this is kind of painful. You usually end up creating a separate project to house a Dockerfile that builds and publishes that image. Then in your main repo, you refer to the registry image. Aside from being annoying managing multiple projects, it also breaks immutability and reproducibility by decoupling the dependent docker image from the main project.
We now allow projects to have multiple image names, so it's conceivable to create a docker image in one stage to be consumed in a subsequent stage. The problem is, you don't want to generate this image every time; it's a slowly changing artifact.
We could make a manual action to build the image, but that doesn't really work.
We could use cross-project triggers to re-run pipelines whenever the base docker image changes, but then you're still stuck with separate projects.
Some things that could make this much better:
- Restrict jobs to only trigger if certain files are changed (e.g. Dockerfile)
Actually, that might be all we need.
Barring the above, it could also be helpful if building unchanged Docker images was faster. e.g. Docker caching, persistent Docker daemon, etc. That way we could always run the rebuild, but it would just be really fast if nothing changed.
Proposal
Links / references
Documentation blurb
(Write the start of the documentation of this feature here, include:
- Why should someone use it; what's the underlying problem.
- What is the solution.
- How does someone use this
During implementation, this can then be copied and used as a starter for the documentation.)