Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
github.com/moby/moby/api v1.54.1
github.com/moby/patternmatcher v0.6.1
github.com/moby/sys/signal v0.7.1
github.com/otiai10/copy v1.14.1
github.com/sirupsen/logrus v1.9.4
github.com/spf13/afero v1.15.0
github.com/spf13/cobra v1.10.2
Expand Down Expand Up @@ -124,7 +123,6 @@ require (
github.com/moby/sys/userns v0.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
}

if fi.IsDir() {
copiedFiles, err := util.CopyDir(fullPath, destPath, c.fileContext, uid, gid, chmod, useDefaultChmod)
copiedFiles, err := util.CopyDir(fullPath, destPath, c.fileContext, uid, gid, chmod, useDefaultChmod, false, false)
if err != nil {
return fmt.Errorf("copying dir: %w", err)
}
c.snapshotFiles = append(c.snapshotFiles, copiedFiles...)
} else if util.IsSymlink(fi) {
// If file is a symlink, we want to copy the target file to destPath
exclude, err := util.CopySymlink(fullPath, destPath, c.fileContext)
exclude, err := util.CopySymlink(fullPath, destPath, c.fileContext, false)
if err != nil {
return fmt.Errorf("copying symlink: %w", err)
}
Expand All @@ -128,7 +128,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
c.snapshotFiles = append(c.snapshotFiles, destPath)
} else {
// ... Else, we want to copy over a file
exclude, err := util.CopyFile(fullPath, destPath, c.fileContext, uid, gid, chmod, useDefaultChmod)
exclude, err := util.CopyFile(fullPath, destPath, c.fileContext, uid, gid, chmod, useDefaultChmod, false)
if err != nil {
return fmt.Errorf("copying file: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/copy_multistage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ COPY --from=first / output/`
if err != nil {
t.Fatal(err)
}
testutil.CheckDeepEqual(t, 3, len(filesUnderRoot))
testutil.CheckDeepEqual(t, 2, len(filesUnderRoot))

files, err := os.ReadDir(filepath.Join(testDir, "output/workspace/foo"))
if err != nil {
Expand Down
65 changes: 27 additions & 38 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/moby/patternmatcher/ignorefile"
"github.com/osscontainertools/kaniko/pkg/config"
"github.com/osscontainertools/kaniko/pkg/timing"
otiai10Cpy "github.com/otiai10/copy"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -681,7 +680,7 @@ type timestampUpdate struct {

// CopyDir copies the file or directory at src to dest
// It returns a list of files it copied over
func CopyDir(src, dest string, context FileContext, uid, gid int64, chmod fs.FileMode, useDefaultChmod bool) ([]string, error) {
func CopyDir(src, dest string, context FileContext, uid, gid int64, chmod fs.FileMode, useDefaultChmod bool, skipSrcIgnoreList, skipDstIgnoreList bool) ([]string, error) {
files, err := RelativeFiles("", src)
if err != nil {
return nil, fmt.Errorf("copying dir: %w", err)
Expand All @@ -698,9 +697,13 @@ func CopyDir(src, dest string, context FileContext, uid, gid int64, chmod fs.Fil
if err != nil {
return nil, fmt.Errorf("copying dir: %w", err)
}
if file != "." && !skipSrcIgnoreList && CheckIgnoreList(fullPath) {
logrus.Debugf("Skipping copy of ignored source: %s", fullPath)
continue
}
destPath := filepath.Join(dest, file)
if CheckIgnoreList(destPath) {
logrus.Debugf("Skipping copy for ignored path: %s", destPath)
if !skipDstIgnoreList && CheckIgnoreList(destPath) {
logrus.Debugf("Skipping copy for ignored dest: %s", destPath)
continue
}
if file == "." {
Expand Down Expand Up @@ -737,7 +740,7 @@ func CopyDir(src, dest string, context FileContext, uid, gid int64, chmod fs.Fil
}
} else if IsSymlink(fi) {
// If file is a symlink, we want to create the same relative symlink
if _, err := CopySymlink(fullPath, destPath, context); err != nil {
if _, err := CopySymlink(fullPath, destPath, context, skipDstIgnoreList); err != nil {
return nil, err
}
} else {
Expand All @@ -747,7 +750,7 @@ func CopyDir(src, dest string, context FileContext, uid, gid int64, chmod fs.Fil
mode = fs.FileMode(0o600)
}

if _, err := CopyFile(fullPath, destPath, context, uid, gid, mode, useDefaultChmod); err != nil {
if _, err := CopyFile(fullPath, destPath, context, uid, gid, mode, useDefaultChmod, skipDstIgnoreList); err != nil {
return nil, err
}
}
Expand All @@ -773,13 +776,7 @@ func MoveDir(src, dest string) error {

if errors.Is(err, syscall.EXDEV) {
// Cross-device move: copy + delete
opts := otiai10Cpy.Options{
PreserveTimes: true,
PreserveOwner: true,
PermissionControl: otiai10Cpy.PerservePermission,
FS: FSys,
}
err = otiai10Cpy.Copy(src, dest, opts)
_, err = CopyDir(src, dest, FileContext{}, DoNotChangeUID, DoNotChangeGID, 0, true, true, true)
if err != nil {
return err
}
Expand All @@ -796,12 +793,12 @@ func MoveDir(src, dest string) error {
}

// CopySymlink copies the symlink at src to dest.
func CopySymlink(src, dest string, context FileContext) (bool, error) {
func CopySymlink(src, dest string, context FileContext, skipIgnoreList bool) (bool, error) {
if context.ExcludesFile(src) {
logrus.Debugf("%s found in .dockerignore, ignoring", src)
return true, nil
}
if CheckIgnoreList(dest) {
if !skipIgnoreList && CheckIgnoreList(dest) {
logrus.Debugf("Skipping copy for ignored path: %s", dest)
return true, nil
}
Expand All @@ -821,12 +818,12 @@ func CopySymlink(src, dest string, context FileContext) (bool, error) {
}

// CopyFile copies the file at src to dest
func CopyFile(src, dest string, context FileContext, uid, gid int64, chmod fs.FileMode, useDefaultChmod bool) (bool, error) {
func CopyFile(src, dest string, context FileContext, uid, gid int64, chmod fs.FileMode, useDefaultChmod bool, skipIgnoreList bool) (bool, error) {
if context.ExcludesFile(src) {
logrus.Debugf("%s found in .dockerignore, ignoring", src)
return true, nil
}
if CheckIgnoreList(dest) {
if !skipIgnoreList && CheckIgnoreList(dest) {
logrus.Debugf("Skipping copy for ignored path: %s", dest)
return true, nil
}
Expand Down Expand Up @@ -1102,28 +1099,20 @@ func CopyFileOrSymlink(src string, destDir string, root string) error {
return err
}
return os.Symlink(link, destFile)
} else if fi.IsDir() {
err := os.MkdirAll(destFile, 0o755)
if err != nil {
return err
}
if _, err := CopyDir(src, destFile, FileContext{}, DoNotChangeUID, DoNotChangeGID, fs.FileMode(0o600), true, false, true); err != nil {
return fmt.Errorf("copying dir: %w", err)
}
} else {
if _, err := CopyFile(src, destFile, FileContext{}, DoNotChangeUID, DoNotChangeGID, fs.FileMode(0o600), true, true); err != nil {
return fmt.Errorf("copying file: %w", err)
}
}
opts := otiai10Cpy.Options{
PreserveTimes: true,
Skip: func(info os.FileInfo, src, dest string) (bool, error) {
return strings.HasSuffix(src, config.KanikoDir), nil
},
FS: FSys,
}
if err := otiai10Cpy.Copy(src, destFile, opts); err != nil {
return fmt.Errorf("copying file: %w", err)
}
if err := CopyOwnership(src, destDir, root); err != nil {
return fmt.Errorf("copying ownership: %w", err)
}
if err := os.Chmod(destFile, fi.Mode()); err != nil {
return fmt.Errorf("copying file mode: %w", err)
}
if err := CopyTimestamps(src, destFile); err != nil {
return fmt.Errorf("copying file timestamps: %w", err)
}

return CopyCapabilities(src, destFile)
return nil
}

// CopyOwnership copies the file or directory ownership recursively at src to dest
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/fs_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ func TestCopySymlink(t *testing.T) {
if err := os.Symlink(tc.linkTarget, link); err != nil {
t.Fatal(err)
}
if _, err := CopySymlink(link, dest, FileContext{}); err != nil {
if _, err := CopySymlink(link, dest, FileContext{}, false); err != nil {
t.Fatal(err)
}
if _, err := os.Lstat(dest); err != nil {
Expand Down Expand Up @@ -1167,7 +1167,7 @@ func Test_CopyFile_skips_self(t *testing.T) {
t.Fatal(err)
}

ignored, err := CopyFile(tempFile, tempFile, FileContext{}, DoNotChangeUID, DoNotChangeGID, fs.FileMode(0o600), true)
ignored, err := CopyFile(tempFile, tempFile, FileContext{}, DoNotChangeUID, DoNotChangeGID, fs.FileMode(0o600), true, false)
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 0 additions & 9 deletions vendor/github.com/otiai10/copy/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/otiai10/copy/LICENSE

This file was deleted.

127 changes: 0 additions & 127 deletions vendor/github.com/otiai10/copy/README.md

This file was deleted.

Loading
Loading