Skip to content
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

Cache will be invalidated if there is an instruction in Dockerfile that doesn't cause any changes in file system #2179

Open
phongvq opened this issue Jul 23, 2022 · 1 comment
Labels
area/caching For all bugs related to cache issues kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy

Comments

@phongvq
Copy link

phongvq commented Jul 23, 2022

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

  1. put RUN echo helloworld in 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
  1. 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}
  1. Re-execute the command to observe caching behaviour

Additional Information

  • kaniko version: latest
  • flag --cache-copy-layers set to true
  • switch --snapshotMode flag from redo to full does 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
@phongvq phongvq changed the title Cache was invalidated if there is an docker instruction that doesn't cause change in file system Cache will be invalidated if there is an docker instruction that doesn't cause change in file system Jul 23, 2022
@phongvq
Copy link
Author

phongvq commented Jul 23, 2022

Based on the logs, I guess the cause is:

  • first build, RUN echo abc doesn't cause file system change -> no snapshot was done
  • next build, cache of RUN echo abc was not found -> cache of all layer after echo layer will not be valid -> and all instruction will be executed.

Please correct me if I am wrong.
Thanks very much.

@phongvq phongvq changed the title Cache will be invalidated if there is an docker instruction that doesn't cause change in file system Cache will be invalidated if there is an instruction in Dockerfile that doesn't cause any changes in file system Jul 23, 2022
@aaron-prindle aaron-prindle added area/caching For all bugs related to cache issues kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy labels Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/caching For all bugs related to cache issues kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy
Projects
None yet
Development

No branches or pull requests

2 participants