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

Fix Symlinks not being copied across stages #971

Merged
merged 7 commits into from
Jan 27, 2020

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Jan 16, 2020

Fixes #915

Description
In case of symlink files across multi-stage files, kaniko would only detect change in the symlink.
Logs suggested, it only saved the symlink and not the target. Due to which user saw a build failure.

INFO[0000] Resolved base name alpine:3.11 to alpine:3.11
INFO[0000] Resolved base name scratch to scratch
INFO[0000] Resolved base name alpine:3.11 to alpine:3.11
....
INFO[0015] Taking snapshot of full filesystem...
INFO[0017] Saving file /usr/lib/libstdc++.so.6 for later use.
....
INFO[0018] COPY --from=0 /usr/lib/libstdc++.so.6 /usr/lib/
error building image: error building stage: failed to execute command: symlink libstdc++.so.6.0.27 /usr/lib/libstdc++.so.6: no such file or directory

In this change,

  1. For symlinks, we identify the symlink as well as the target as files to saved
/ # /kaniko/executor -f dockerfiles/Dockerfile_test_copy_symlink --context=dir:///workspace --destination=gcr.io/tejal-test/test --tarPath=image.tar
....
INFO[0004] Taking snapshot of full filesystem...        
INFO[0004] Adding whiteout for /kaniko                  
INFO[0007] Saving file /usr/lib/libstdc++.so.6.0.27 for later use 
INFO[0007] Saving file /usr/lib/libstdc++.so.6 for later use 
INFO[0007] Deleting filesystem...                       
INFO[0007] No base image, nothing to extract            
INFO[0007] Unpacking rootfs as cmd COPY --from=t /usr/lib/libstdc++.so.6 /usr/lib/ requires it. 
INFO[0007] Taking snapshot of full filesystem...        
INFO[0008] COPY --from=t /usr/lib/libstdc++.so.6 /usr/lib/ 
INFO[0008] Taking snapshot of files... 
  1. When a symlink is copied across mutliple stages, the target file is also copies.
    Success log above.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
    will do.
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

Describe any changes here so maintainer can include it in the release notes, or delete this block.

Fix symlinks files copies across multi-stage dockerfiles.

@googlebot googlebot added the cla: yes CLA signed by all commit authors label Jan 16, 2020
pkg/executor/build.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
Copy link
Contributor

@samos123 samos123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits and questions

@tejal29 tejal29 changed the title Fix Symlinks not being copies across stages Fix Symlinks not being copied across stages Jan 17, 2020
pkg/executor/build.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshot.go Outdated Show resolved Hide resolved
pkg/util/fs_util.go Outdated Show resolved Hide resolved
@cvgw
Copy link
Contributor

cvgw commented Jan 17, 2020

@tejal29 how similar to #943 is this?

pkg/util/fs_util.go Outdated Show resolved Hide resolved
@tejal29
Copy link
Contributor Author

tejal29 commented Jan 17, 2020

@tejal29 how similar to #943 is this?

I looked at the PR and looks like for symlinks, it fixes copy by copying the target file when a symlink is copied. The code does not change what file is saved.
For cross stage references, for symlink is referenced, we should save both symlink as well as target.

WDYT?
i will check what docker does when copying a symlink and update this section.

@cvgw
Copy link
Contributor

cvgw commented Jan 17, 2020

@tejal29 how similar to #943 is this?

I looked at the PR and looks like for symlinks, it fixes copy by copying the target file when a symlink is copied. The code does not change what file is saved.
For cross stage references, for symlink is referenced, we should save both symlink as well as target.

WDYT?
i will check what docker does when copying a symlink and update this section.

Ya I agree, I think they are addressing two similar but different issues.
This PR: src is a symlink
That PR: dest is a symlink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate-release cla: yes CLA signed by all commit authors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior for symlink file COPY compared with docker build
5 participants