Support caching by docker image tag
A
Anil
Idea
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:
docker: - 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
version.
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!
CCI-I-500
F
Florian Loretan Loretan
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.
A
Anil
^^ 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
A
Anil
Hi @Nathan DintenfassUnfortunately 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 worksday N: Elixir 1.6.7 is released. circleci updates their docker images, and circleci/elixir:1.6 picks up the 1.6.7 binary
N
Nathan Dintenfass
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:
docker: - 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?