New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local and Registry cache not used or *invalidating* cache unnecessarily #4910
Comments
This is expected with your Dockerfile above that uses Cache mismatches are common if you use If you have a reproducible case/steps where you think cache is not matched properly you can post that and we can look at the specifics. |
I don't see how the I tested with pruning all my Docker cache, running it once, adding a test.txt file and running build again, and as shown here, the
I'll create a reproducible case early week, just wanted to get initial thoughts out quickly 😊 |
I haven't had the time to setup a reproducible case, as the setup has quite some configuration, so it would take a while to give an exact replica. We did come up with something that seems to work for local cache, each image being built now stores it's cache in a separate subdirectory, meaning that no builds will ever write to the same cache directory unless it's the same image. This seems to work, and we have had much better success with the cache not being broken. Here is a code snippet added to the cache_subpath="${UNIQUE_IMAGE_ID}"
buildkit_cache="${CACHE_PATH}/buildkit/${cache_subpath}"
mkdir -p $buildkit_cache
cache="--export-cache type=local,dest=$buildkit_cache,mode=max --import-cache type=local,src=$buildkit_cache" $BUILDCTL --addr=$(cat $tmp/addr) build ${BUILD_ARGS} --frontend dockerfile.v0 --local context=. --local dockerfile=. --opt filename=./${DOCKERFILE} \
--output type=local,dest=output $cache |
Been having some issues when exporting and importing cache from both a registry and locally, we use the buildctl-daemonless example.
Our full use case is being able to spawn
N
amount of pods in our kubernetes cluster, that each build various applications, and we obviously want cache enabled to make this as fast as possible.The problem we've ran into with locally storing the cache on a volume that is mounted to the pod, is that the cache will very rarely actually be used, even though the source code is exactly the same, and the Dockerfile is very simple, causing the builds to take much longer than necessary.
Command:
Dockerfile:
We tried to switch over to use a registry instead, as we got the vibe from the README it was more the intention to use when you had multiple instances of buildctl using the same cache.
This also seemed to do a lot better, the new pods consistently uses the cache now, but upon further testing, we noticed that if the source code were to change (like a simple test.txt file being added, or an index.js file being manipulated), our
RUN yarn install
would no longer be cached.This didn't seem correct, and we therefore tested locally with just plain docker, did the exact same code change we had tested with in the pod using buildctl, and Docker did use the cache for the
RUN yarn install
as expected.We are essentially running
master-rootless
version of buildkit, but I'll include the full Dockerfile that we use on our pods.Dockerfile
The ENTRYPOINT can be ignored for now, we shell into the spawned pod instead and run it manually, it is just the daemonless script
For our specific use case, using local cache in a mounted volume would be the best, as we can ensure the fastest performant cache possible, but if registries are the inteded resolution for this, that's fine too.
The text was updated successfully, but these errors were encountered: