Skip to content

Commit

Permalink
Fix bug in extracting hardlinks
Browse files Browse the repository at this point in the history
When we execute multistage builds, we store the fs of each intermediate
stage at /kaniko/<stage number> if it's used later in the build. This
created a bug when extracting hardlinks, because we weren't appending
the new directory to the link path.

So, if `/tmp/file1` and `/tmp/file2` were hardlinked, kaniko was trying
to link `/kaniko/0/tmp/file1` to `/tmp/file2` instead of
`/kaniko/0/tmp/file2`. This change will append the correct directory to
the link, and fixes GoogleContainerTools#437 GoogleContainerTools#362 GoogleContainerTools#352 GoogleContainerTools#342.
  • Loading branch information
Priya Wadhwa committed Nov 17, 2018
1 parent 0c29413 commit 98a9dad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion integration/dockerfiles/Dockerfile_test_hardlink
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
FROM composer@sha256:5c4bd89217b50125f28e08d9f16414ecb75f90ce9b773605472b35cd55f3e5c0 AS composer
FROM php@sha256:9fe20c8003a12f5907ffdc1d7ec435b4ca4226fa4342b94cec4d66189a439f17
COPY --from=composer /usr/bin/composer /usr/bin/composer

COPY ./ /app
WORKDIR /app

RUN ls -l

FROM jboss/base-jdk@sha256:138591422fdab93a5844c13f6cbcc685631b37a16503675e9f340d2503617a41

FROM gcr.io/kaniko-test/hardlink-base:latest
RUN ls -al /usr/libexec/git-core/git /usr/bin/git /usr/libexec/git-core/git-diff
RUN stat /usr/bin/git
RUN stat /usr/libexec/git-core/git
RUN git --version > /git-version
RUN git --version > /git-version
4 changes: 2 additions & 2 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error {
return errors.Wrapf(err, "error removing %s to make way for new link", hdr.Name)
}
}

if err := os.Link(filepath.Clean(filepath.Join("/", hdr.Linkname)), path); err != nil {
link := filepath.Join(dest, hdr.Linkname)
if err := os.Link(filepath.Clean(filepath.Join("/", link)), path); err != nil {
return err
}

Expand Down

0 comments on commit 98a9dad

Please sign in to comment.