Snapshot only specific files for COPY
Before #289 was merged, when copying over directories for COPY kaniko would get a list of all files at the destination specified and add them to the list of files to be snapshotted. If the destination was root it would add all files. This worked because the snapshotter made sure the file had been changed before adding it to the layer. After #289, we changed the logic to add all files snapshotted to a layer without checking if the files had been changed. This created the bug in got all the files at root and added them to the layer without checking if they had been changed. This change should fix this bug. Now, the CopyDir function returns a list of files it copied over and only those files are added to the list of files to be snapshotted. Should fix #314
This commit is contained in:
parent
216b14f79f
commit
9a93f5bad9
|
|
@ -79,10 +79,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
|
|||
// we need to add '/' to the end to indicate the destination is a directory
|
||||
dest = filepath.Join(cwd, dest) + "/"
|
||||
}
|
||||
if err := util.CopyDir(fullPath, dest); err != nil {
|
||||
return err
|
||||
}
|
||||
copiedFiles, err := util.Files(dest)
|
||||
copiedFiles, err := util.CopyDir(fullPath, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -459,16 +459,18 @@ func DownloadFileToDest(rawurl, dest string) error {
|
|||
}
|
||||
|
||||
// CopyDir copies the file or directory at src to dest
|
||||
func CopyDir(src, dest string) error {
|
||||
// It returns a list of files it copied over
|
||||
func CopyDir(src, dest string) ([]string, error) {
|
||||
files, err := RelativeFiles("", src)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
var copiedFiles []string
|
||||
for _, file := range files {
|
||||
fullPath := filepath.Join(src, file)
|
||||
fi, err := os.Lstat(fullPath)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
destPath := filepath.Join(dest, file)
|
||||
if fi.IsDir() {
|
||||
|
|
@ -478,24 +480,25 @@ func CopyDir(src, dest string) error {
|
|||
gid := int(fi.Sys().(*syscall.Stat_t).Gid)
|
||||
|
||||
if err := os.MkdirAll(destPath, fi.Mode()); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if err := os.Chown(destPath, uid, gid); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
} else if fi.Mode()&os.ModeSymlink != 0 {
|
||||
// If file is a symlink, we want to create the same relative symlink
|
||||
if err := CopySymlink(fullPath, destPath); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
// ... Else, we want to copy over a file
|
||||
if err := CopyFile(fullPath, destPath); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
copiedFiles = append(copiedFiles, destPath)
|
||||
}
|
||||
return nil
|
||||
return copiedFiles, nil
|
||||
}
|
||||
|
||||
// CopySymlink copies the symlink at src to dest
|
||||
|
|
|
|||
Loading…
Reference in New Issue