I've setup container images builds in kubernetes using kaniko (version v1.6.0-debug
), but I ended up in the following problem when the cache is enabled (/kaniko/executor --cache --cache-repo $CI_REGISTRY_IMAGE/cache
).
This is a simplified Dockerfile that explains the issue (the real one has a PHP package.json
and package.lock
files where new requirements have been added).
FROM busybox:1.33.1 AS builder
WORKDIR /root
COPY testfile testfile
FROM busybox:1.33.1 AS release
WORKDIR /root
COPY --from=builder /root/testfile testfile
RUN cat /root/testfile
If testfile
is modified, and the docker image was previously built (and thus all its layers cached in the docker registry), kaniko does not see any modification and uses the cached layer for
COPY --from=builder /root/testfile testfile
The result is that the final docker image provides an old (cached) version of the file testfile
instead of the last one.
Any idea how to solve/mitigate this problem? Of course if I remove the cached layers from our docker repository, the image is build correctly, but disable the cache is not an option for me because the builds would be too slow.
Upgrading to Kaniko 1.7.0 might solve your problem: https://github.com/GoogleContainerTools/kaniko/pull/1735