uber-archive / makisu

Fast and flexible Docker image building tool, works in unprivileged containerized environments like Mesos and Kubernetes.
Apache License 2.0
2.41k stars 156 forks source link

Copy of symlinks fails when multistaging build #301

Open remibooo opened 4 years ago

remibooo commented 4 years ago

Describe the bug Makisu fails to build when copying symlinks from a stage to another (multistaging build)

To Reproduce

I used the following simple Dockerfile:

FROM ubuntu AS builder
RUN mkdir -p /test/
RUN echo blabla >> /test/file
RUN ln -s /test/file /test/symlink
WORKDIR /home/

FROM ubuntu
COPY --from=builder /test/symlink /test/symlink

and ran it with the master version of makisu and the following command: docker run -v "$PWD":/job remibooo03/makisu:v0.1.13 sh -c "/makisu/bin/makisu/makisu build --commit=explicit --modifyfs=true -t test_v0.1.13_minimal --dest /job/image_minimal.tar -f /job/Dockerfile_minimal /job 2> /job/log_minimal"

It gave the same error whether the flag commit was explicit or implicit.

Expected behavior A successful built

Additional context This is the error message I got (the final lines):

{"level":"info","ts":1580291383.9579847,"msg":"* Step 2/2 (commit) : COPY --from=builder /test/symlink /test/symlink  (bdc8ce21)"}
{"level":"info","ts":1580291383.9580278,"msg":"* Executed COPY --from=builder /test/symlink /test/symlink  (bdc8ce21)","duration":0.000017284}
{"level":"error","ts":1580291384.9725418,"msg":"failed to execute build plan: execute stage: build stage 1: build node: do commit: commit: failed to generate diff layer: write diffs: create layer by copy ops: stat src /makisu-storage/sandbox/sandbox055961992/stages/YnVpbGRlcg==/test/symlink: stat /makisu-storage/sandbox/sandbox055961992/stages/YnVpbGRlcg==/test/symlink: no such file or directory"}

This was solved by addind these two lines before the second stage (FROM ) of the dockerfile, in order to turn the symlinks into hardlinks, but obviously quite dirty...


WORKDIR /
RUN find -type l -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;