kaniko
kaniko copied to clipboard
Cache will be invalidated if there is an instruction in Dockerfile that doesn't cause any changes in file system
Actual behavior
- Docker cache will not work if there is an instruction in Dockerfile that doesn't produce any changes in the file system (e.g. instruction
RUN echo helloworld) (cache of any layers after that instruction will be invalidate in the next build)
Expected behavior
- Caching works in case there is an instruction Dockerfile that not produce changes in filesystem
To Reproduce
- put
RUN echo helloworldin Dockerfile
FROM node:14.18.2
RUN npm i -g [email protected]
WORKDIR /app
COPY package.json .
COPY package-lock.json .
# echo abc will not cause any change in filesystem
RUN echo abc
################## cache of layers after this line cannot be re-used in the next build.
COPY .npmrc .
RUN npm ci
COPY . .
RUN GENERATE_SOURCEMAP=false npm run build
- Run following command:
/kaniko/executor --context ${CI_PROJECT_DIR} \
--cache=true \
--snapshotMode=redo \
--use-new-run=true \
--cache-copy-layers=true \
--dockerfile ${CI_PROJECT_DIR}/${TOPCV_DOCKERFILE_PATH} \
${docker_destination} \
${docker_build_args}
- Re-execute the command to observe caching behaviour
Additional Information
- kaniko version: latest
- flag
--cache-copy-layersset totrue - switch
--snapshotModeflag fromredotofulldoes not show the issue - use Gitlab Regsitry as cache + container registry
- kaniko logs
build no. 1
INFO[0050] Running: [/bin/sh -c echo abc]
abc
INFO[0051] No files changed in this command, skipping snapshotting.
build no. 2
INFO[0007] No cached layer found for cmd RUN echo abc
Triage Notes for the Maintainers
| Description | Yes/No |
|---|---|
| Please check if this a new feature you are proposing |
|
| Please check if the build works in docker but not in kaniko |
|
Please check if this error is seen when you use --cache flag |
|
| Please check if your dockerfile is a multistage dockerfile |
|
Based on the logs, I guess the cause is:
- first build,
RUN echo abcdoesn't cause file system change -> no snapshot was done - next build, cache of
RUN echo abcwas not found -> cache of all layer afterecholayer will not be valid -> and all instruction will be executed.
Please correct me if I am wrong. Thanks very much.