Skip to content

feat: Build & cache intermediate images

This adds support for a new environment variable, AUTO_DEVOPS_CACHE_BUILD_STAGES, which takes a comma separated list of intermediate build stages. Each will trigger a docker build with that step being targeted, tagged and pushed into the image registry. Each following step uses all previous steps as cache from images.

The default behaviour is to save "sub images" as separate images in the CI_APPLICATION_REPOSITORY path, however this can be overridden to just setting them as tags with the second new environment variable: AUTO_DEVOPS_CACHE_BUILD_STAGES_AS_TAGS to any non-empty string.

Example Usage

For the project gitlab.com/example/project with the following Dockerfile:

FROM some-heavy-image as builder
RUN some-heavy-task

FROM another-heavy-image as builder2
COPY --from=builder /source/code /source/code
RUN some-heavy-task

FROM some-slim-image
COPY --from=builder2 /some-file /some-file

We could enable caching by setting AUTO_DEVOPS_CACHE_BUILD_STAGES to 'builder,builder2', which would produce:

  • registry.gitlab.com/example/project:latest
  • registry.gitlab.com/example/project:commit-sha
  • registry.gitlab.com/example/project/builder:latest
  • registry.gitlab.com/example/project/builder:commit-sha
  • registry.gitlab.com/example/project/builder2:latest
  • registry.gitlab.com/example/project/builder2:commit-sha

If you don't want these to be saved as seperate images, you can also set AUTO_DEVOPS_CACHE_BUILD_STAGES_AS_TAGS to true, which would then instead produce:

  • registry.gitlab.com/example/project:latest
  • registry.gitlab.com/example/project:commit-sha
  • registry.gitlab.com/example/project:builder-latest
  • registry.gitlab.com/example/project:builder-commit-sha
  • registry.gitlab.com/example/project:builder2-latest
  • registry.gitlab.com/example/project:builder2-commit-sha

Resolves: #10 (closed)

Edited by Emily Shepherd

Merge request reports