I'm checking the newly available feature in the pipeline for the docker buildkit. Trying to utilize the build cache feature to improve the build speed. But after some tests, I noticed the cache layer can't be reused consistently.
The build command I used is
docker build orch-tool --tag image-name --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from image-name-at-registry
docker tag image-name image-name-at-registry
docker push image-name-at-registry
I tested the above commands locally without issue, and the caching works perfectly. But when tested in the pipeline, it doesn't work.
The dockerfile contains `apt update` in early layers, not sure if this is the problem.
Hi @Thor Zhong,
(1) Does caching not work at all in Pipelines?
Or does it not work in some builds?
Or does it work only for some layers?
I am trying to understand the scope of the issue you are reporting.
(2) Have you added the following command in the script of your bitbucket-pipelines.yml file (before the docker build command)?
- export DOCKER_BUILDKIT=1
This is necessary in order to be able to use Docker BuildKit in Bitbucket Pipelines.
(3) Are you using this in Pipelines builds that run in our own infrastructure, or have you set up runners that run in your own infrastructure?
Kind regards,
Theodora
1. The cache works in some builds. But failed more often I can feel
2. Yes, I did this export
3. I'm using runners from bitbucket infrastructure.
For example, I ran three builds one after another. They all have the same sha256 (not sure if you can see it clearly) at the same layer, but build 12 used the cache layer while build 15 did apt installation again. I think build 12 ran 1 day after build 11 finished, build 15 ran 4 days after
#11
#12
#15
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thor Zhong,
Thank you for the info.
My guess is that there may be a change between the different Pipelines builds either in the base image you are using in your Dockerfile or in one of the tools you are installing with the apt install command, which makes the dependencies get downloaded again.
Are you using a public Docker image as a base image in the Dockerfile? If so, would you mind sharing which image it is and also the full list of tools you are installing with apt install, so I can try to reproduce and investigate?
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.