CircleCI Ideas

Support caching by docker image tag


Add a .Docker cache-key similar to the following:

  - save_cache:
          key: v1-build-cache-{{ .Docker }}
          paths: "_build

This would cause the cache to be invalidated whenever the docker SHA-256 of an image changes.


The common use case is when you have a docker image that's something like:

      - image: circleci/elixir:1.5


Then, when circleci updates the docker image to have a newer version of elixir, or otp, then compiled files have a mismatch. They were built (and cached) for one version of elixir, but are now running on an incompatible



Adding the docker version as a key allows authors to make sure that environment-specific-files are only cached while the dockerfile remains the same.


Thank you!

  • Avatar32.5fb70cce7410889e661286fd7f1897de Guest
  • Jul 12 2018
  • Taking votes
  • Attach files
  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    July 14, 2018 07:59

    What if, instead, you could parameterize the tag you want to use and also build your cache key from that? Then your executor declaration might look like:

    - image: circleci/elixir:<< parameters.dockertag >>

    and then your cache key might look like:

      - save_cache:
              key: v1-build-cache-<< parameters.dockertag >>
              paths: "_build


    The above (or something a lot like it) will soon be possible in config, so curious if that would suffice?

  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    July 14, 2018 08:09

    Hi @Nathan Dintenfass
    Unfortunately that won't solve the issue.

    The problem additionally happens when same docker tag to be overwritten.

    E.g. this is the actual scenario I have today:
    day 1: Building with circleci/elixir:1.6 works
    day N: Elixir 1.6.7 is released. circleci updates their docker images, and circleci/elixir:1.6 picks up the 1.6.7 binary

  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    July 14, 2018 08:10

    ^^ the old _build cache doesn't work across elixir versions and builds start failing. This doesn't happen with every transition, but _has_ happened across OTP versions

  • Avatar40.8f183f721a2c86cd98fddbbe6dc46ec9
    Guest commented
    April 11, 2019 07:39

    We needed something like this with a node.js project. There was an update of the node.js version in the base image we use, and some modules needed to be recompiled for the new version. 


    Rather than using the docker tag, it would be good to use the digest of the image being used. This would handle cases where the tag didn't change but a new image was used.