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

ONBUILD COPY fails using multi-stage build #533

Closed
mbfisher opened this issue Jan 17, 2019 · 3 comments · Fixed by #1190
Closed

ONBUILD COPY fails using multi-stage build #533

mbfisher opened this issue Jan 17, 2019 · 3 comments · Fixed by #1190
Assignees
Labels
area/multi-stage builds issues related to kaniko multi-stage builds cmd/onbuild good first issue Good for newcomers help wanted Looking for a volunteer! kind/bug Something isn't working priority/p1 Basic need feature compatibility with docker build. we should be working on this next.

Comments

@mbfisher
Copy link

Hi everyone, thanks for your work on Kaniko!

Actual behavior

When using ONBUILD instructions with a multi-stage build, Kaniko fails to copy files between stages:

+ docker run --rm -it --volume /Volumes/Users/mbfisher/git-projects/kaniko-multi-stage-bug:/build gcr.io/kaniko-project/executor:debug --context=/build --destination=my-kaniko-bug
INFO[0000] Downloading base image mbfisher/kaniko-multi-stage-bug:builder
2019/01/17 10:05:39 No matching credentials were found, falling back on anonymous
INFO[0001] Executing 1 build triggers
INFO[0001] Unpacking rootfs as cmd RUN mkdir /app && echo "Hello, World!" > /app/index requires it.
INFO[0001] Taking snapshot of full filesystem...
INFO[0001] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0001] Skipping paths under /build, as it is a whitelisted directory
INFO[0001] Skipping paths under /proc, as it is a whitelisted directory
INFO[0001] Skipping paths under /dev, as it is a whitelisted directory
INFO[0001] Skipping paths under /sys, as it is a whitelisted directory
INFO[0001] Skipping paths under /busybox, as it is a whitelisted directory
INFO[0001] RUN mkdir /app && echo "Hello, World!" > /app/index
INFO[0001] cmd: /bin/sh
INFO[0001] args: [-c mkdir /app && echo "Hello, World!" > /app/index]
INFO[0001] Taking snapshot of full filesystem...
INFO[0001] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0001] Skipping paths under /build, as it is a whitelisted directory
INFO[0001] Skipping paths under /proc, as it is a whitelisted directory
INFO[0001] Skipping paths under /dev, as it is a whitelisted directory
INFO[0001] Skipping paths under /sys, as it is a whitelisted directory
INFO[0001] Skipping paths under /busybox, as it is a whitelisted directory
INFO[0001] Deleting filesystem...
INFO[0002] Downloading base image mbfisher/kaniko-multi-stage-bug:runtime
2019/01/17 10:05:41 No matching credentials were found, falling back on anonymous
INFO[0002] Executing 1 build triggers
INFO[0002] Taking snapshot of full filesystem...
INFO[0002] Skipping paths under /kaniko, as it is a whitelisted directory
INFO[0002] Skipping paths under /build, as it is a whitelisted directory
INFO[0002] Skipping paths under /proc, as it is a whitelisted directory
INFO[0002] Skipping paths under /dev, as it is a whitelisted directory
INFO[0002] Skipping paths under /sys, as it is a whitelisted directory
INFO[0002] Skipping paths under /busybox, as it is a whitelisted directory
INFO[0002] COPY --from=builder /app/* /app/
error building image: error building stage: lstat /kaniko/builder: no such file or directory

Expected behavior
The build should succeed, as it does when using the Docker Engine:

+ docker build --no-cache -t my-multi-stage-build .
Sending build context to Docker daemon  50.69kB
Step 1/2 : FROM mbfisher/kaniko-multi-stage-bug:builder AS builder
# Executing 1 build trigger
 ---> Running in c6bbc064f397
Removing intermediate container c6bbc064f397
 ---> c3d2e2f359f7
Step 2/2 : FROM mbfisher/kaniko-multi-stage-bug:runtime
# Executing 1 build trigger
 ---> 2b4f93925947
Successfully built 2b4f93925947
Successfully tagged my-multi-stage-build:latest
+ docker run --rm my-multi-stage-build
Hello, World!

To Reproduce

See https://github.com/mbfisher/kaniko-multi-stage-bug

Additional Information

@grampelberg
Copy link

I believe I'm running into the same issue. With this dockerfile - https://github.com/linkerd/linkerd2/blob/master/Dockerfile-proxy, I get errors on this line:

COPY --from=fetch /build/target/proxy/LICENSE ./LICENSE

Adding this line fixes it:

RUN cp /build/target/proxy/LICENSE /build/LICENSE

@laoshancun
Copy link

Same issue.

INFO[0093] Executing 2 build triggers                   
INFO[0093] Skipping unpacking as no commands require it. 
INFO[0093] Taking snapshot of full filesystem...        
INFO[0094] Using files from context: [/builds/my-service/data] 
INFO[0094] ADD data /data                               
INFO[0094] Taking snapshot of files...                  
INFO[0094] COPY --from=builder /build/dist/* .          
error building image: error building stage: lstat /kaniko/builder: no such file or directory
INFO[0094] Resolving srcs [/build/dist/*]...      

@priyawadhwa priyawadhwa added cmd/copy kind/bug Something isn't working area/multi-stage builds issues related to kaniko multi-stage builds labels Aug 8, 2019
@tejal29 tejal29 added the priority/p1 Basic need feature compatibility with docker build. we should be working on this next. label Sep 27, 2019
@tejal29 tejal29 added this to the GA Release v1.0.0 milestone Jan 10, 2020
@tejal29
Copy link
Contributor

tejal29 commented Feb 28, 2020

I have identified the issue. The resolveStages happens before resolveOnBuild for a stage is called.
resolveStages replaces all the stage names to an index 0, 1 instead of their name in the order in dockerfile. Copy command expects the stage names to be resolved to an index.

The OnBuild command is processed after resolveStages which adds COPY -from=builder .. without resolving the stage name to an index.

The fix here is to resolve stage idx in resolveOnBuild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/multi-stage builds issues related to kaniko multi-stage builds cmd/onbuild good first issue Good for newcomers help wanted Looking for a volunteer! kind/bug Something isn't working priority/p1 Basic need feature compatibility with docker build. we should be working on this next.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants