GoogleContainerTools / kaniko

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

dockfile uses WORKDIR /workspace. An error must occur if cache is enabled. Why? #3176

Open manong-detective opened 6 months ago

manong-detective commented 6 months ago

The same dockfile, as long as I change WORKDIR to something else such as /temp there will be no problem, has cleared the cache and tried again many times, this problem is inevitable, do not know if there is a good person who has encountered this problem to tell me what is going on

dockfile definition

FROM maven:3.6.1-jdk-8-alpine as builder WORKDIR /workspace COPY smart-mvc/ smart-mvc/ COPY smart-sso-client/ smart-sso-client/ COPY smart-sso-server/ smart-sso-server/ COPY pom.xml pom.xml RUN mvn clean package -Dmaven.test.skip -Dlz.env=online -U

FROM openjdk:8 RUN groupadd --gid 555 dc && adduser --uid 555 --gid 555 dc RUN mkdir -p /usr/local/lizhi/smart-sso-server && chmod 777 /usr/local/lizhi/smart-sso-server WORKDIR /usr/local/lizhi/smart-sso-server COPY --from=builder /workspace/smart-sso-server/target/smart-sso-server-1.0.14-deploy.tar.gz . RUN tar -zxf smart-sso-server-1.0.14-deploy.tar.gz && rm -rf smart-sso-server-1.0.14-deploy.tar.gz RUN chmod 755 /usr/local/lizhi/smart-sso-server/startup.sh USER dc:dc CMD [ "/usr/local/lizhi/smart-sso-server/startup.sh"]

kaniko parameter

args:

Build log

INFO[0000] Resolved base name maven:3.6.1-jdk-8-alpine to builder INFO[0000] Retrieving image manifest maven:3.6.1-jdk-8-alpine INFO[0000] Retrieving image maven:3.6.1-jdk-8-alpine from registry index.docker.io INFO[0000] Retrieving image manifest maven:3.6.1-jdk-8-alpine INFO[0000] Returning cached image manifest
INFO[0000] Retrieving image manifest openjdk:8
INFO[0000] Retrieving image openjdk:8 from registry index.docker.io INFO[0001] Retrieving image manifest openjdk:8
INFO[0001] Returning cached image manifest
INFO[0001] Built cross stage deps: map[0:[/workspace/smart-sso-server/target/smart-sso-server-1.0.14-deploy.tar.gz]] INFO[0001] Retrieving image manifest maven:3.6.1-jdk-8-alpine INFO[0001] Returning cached image manifest
INFO[0001] Retrieving image manifest maven:3.6.1-jdk-8-alpine INFO[0001] Returning cached image manifest
INFO[0001] Executing 0 build triggers
INFO[0001] Building stage 'maven:3.6.1-jdk-8-alpine' [idx: '0', base-idx: '-1'] INFO[0005] Checking for cached layer us-central1-docker.pkg.dev/infrastructure-410808/nebula/cache:9312513252923a31da560df13a6f054b1ebca25aae0c5aaa80c9ed402ade1c0c... INFO[0005] Using caching version of cmd: RUN mvn clean package -Dmaven.test.skip -Dlz.env=online -U INFO[0005] Unpacking rootfs as cmd COPY smart-mvc/ smart-mvc/ requires it. INFO[0008] WORKDIR /workspace
INFO[0008] Cmd: workdir
INFO[0008] Changed working directory to /workspace
INFO[0008] No files changed in this command, skipping snapshotting. INFO[0008] COPY smart-mvc/ smart-mvc/
INFO[0008] Taking snapshot of files...
INFO[0008] COPY smart-sso-client/ smart-sso-client/
INFO[0009] Taking snapshot of files...
INFO[0011] COPY smart-sso-server/ smart-sso-server/
INFO[0013] Taking snapshot of files...
INFO[0014] COPY pom.xml pom.xml
INFO[0014] Taking snapshot of files...
INFO[0014] RUN mvn clean package -Dmaven.test.skip -Dlz.env=online -U INFO[0014] Found cached layer, extracting to filesystem INFO[0017] Deleting filesystem...
INFO[0017] Retrieving image manifest openjdk:8
INFO[0017] Returning cached image manifest
INFO[0017] Retrieving image manifest openjdk:8
INFO[0017] Returning cached image manifest
INFO[0017] Executing 0 build triggers
INFO[0017] Building stage 'openjdk:8' [idx: '1', base-idx: '-1'] INFO[0017] Checking for cached layer us-central1-docker.pkg.dev/infrastructure-410808/nebula/cache:046e46fbd3159b8f0f4aa689568ec96c429097d0935f559d77703608567fc642... INFO[0017] Using caching version of cmd: RUN groupadd --gid 555 dc && adduser --uid 555 --gid 555 dc INFO[0017] Checking for cached layer us-central1-docker.pkg.dev/infrastructure-410808/nebula/cache:0cab411acdb8320c56b7cee90d732270b6b472ff1e983be4f0899ea19c7fa3b6... INFO[0018] Using caching version of cmd: RUN mkdir -p /usr/local/lizhi/smart-sso-server && chmod 777 /usr/local/lizhi/smart-sso-server error building image: error building stage: failed to optimize instructions: failed to get files used from context: failed to get fileinfo for /kaniko/0/workspace/smart-sso-server/target/smart-sso-server-1.0.14-deploy.tar.gz: lstat /kaniko/0/workspace/smart-sso-server/target/smart-sso-server-1.0.14-deploy.tar.gz: no such file or directory

KacperMalachowski commented 5 months ago

Exactly same behaviour observed at our team. It's even more interesting that locally everything seems working fine (the file is stored to be reused), but running on Azure DevOps is failing due to missing file. That happened only when cache layer is found, when cache hasn't found - everything is working.