GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.88k stars 1.44k forks source link

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

Open phongvq opened 2 years ago

phongvq commented 2 years ago

Actual behavior

Expected behavior

To Reproduce

  1. put RUN echo helloworld in Dockerfile
    
    FROM node:14.18.2

RUN npm i -g npm@8.2.0

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

2. Run following command:
```bash
/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

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
  • - [x]
Please check if the build works in docker but not in kaniko
  • - [x]
Please check if this error is seen when you use --cache flag
  • - [x]
Please check if your dockerfile is a multistage dockerfile
  • - [ ]
phongvq commented 2 years ago

Based on the logs, I guess the cause is:

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