GoogleContainerTools / kaniko

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

Cannot build multi-stage Dockerfile with nested COPY paths #1909

Open jokajak opened 2 years ago

jokajak commented 2 years ago

Actual behavior Using a multi-stage dockerfile where a nested path of one copied directory is copied between stages causes the build to fail.

# /kaniko/executor --dockerfile Dockerfile --context . --no-push
INFO[0000] Resolved base name alpine:3.11 to base
INFO[0000] Resolved base name alpine:3.11 to toplevel_copy
INFO[0000] Resolved base name alpine:3.11 to nested_copy
INFO[0000] Retrieving image manifest alpine:3.11
INFO[0000] Retrieving image alpine:3.11 from registry index.docker.io
INFO[0000] Retrieving image manifest alpine:3.11
INFO[0000] Returning cached image manifest
INFO[0000] Retrieving image manifest alpine:3.11
INFO[0000] Returning cached image manifest
INFO[0000] Built cross stage deps: map[0:[/top_level/ /top_level/nested]]
INFO[0000] Retrieving image manifest alpine:3.11
INFO[0000] Returning cached image manifest
INFO[0000] Executing 0 build triggers
INFO[0000] Unpacking rootfs as cmd RUN mkdir -p /top_level/nested requires it.
INFO[0000] RUN mkdir -p /top_level/nested
INFO[0000] Taking snapshot of full filesystem...
INFO[0000] cmd: /bin/sh
INFO[0000] args: [-c mkdir -p /top_level/nested]
INFO[0000] Running: [/bin/sh -c mkdir -p /top_level/nested]
INFO[0000] Taking snapshot of full filesystem...
INFO[0000] RUN echo my_dest /top_level/nested/target
INFO[0000] cmd: /bin/sh
INFO[0000] args: [-c echo my_dest /top_level/nested/target]
INFO[0000] Running: [/bin/sh -c echo my_dest /top_level/nested/target]
my_dest /top_level/nested/target
INFO[0000] Taking snapshot of full filesystem...
INFO[0000] No files were changed, appending empty layer to config. No layer added to image.
INFO[0000] RUN ln -s /top_level/nested/target /top_level/nested/my_link
INFO[0000] cmd: /bin/sh
INFO[0000] args: [-c ln -s /top_level/nested/target /top_level/nested/my_link]
INFO[0000] Running: [/bin/sh -c ln -s /top_level/nested/target /top_level/nested/my_link]
INFO[0000] Taking snapshot of full filesystem...
INFO[0000] Saving file top_level for later use
INFO[0000] Saving file top_level/nested for later use
error building image: could not save file: symlink /top_level/nested/target /kaniko/0/top_level/nested/my_link: file exists

Expected behavior Both paths should be copy-able between stages

To Reproduce Steps to reproduce the behavior:

  1. Try to build the included Dockerfile

Additional Information

RUN mkdir -p /top_level/nested
RUN echo my_dest /top_level/nested/target
RUN ln -s /top_level/nested/target /top_level/nested/my_link
FROM alpine:3.11 AS toplevel_copy
COPY --from=base /top_level/ /top_level/
FROM alpine:3.11 AS nested_copy
COPY --from=base /top_level/nested /top_level/nested
Tien-Jellyfish commented 1 year ago

I got the same issue with the nested COPY path.

Mistic92 commented 1 year ago

In 1.9.1 still the same issue

matutter commented 1 year ago

I just ran into this on 1.11.0