diff --git a/pkg/executor/executor.go b/pkg/executor/executor.go index dccfffa05c..8cefce17af 100644 --- a/pkg/executor/executor.go +++ b/pkg/executor/executor.go @@ -228,8 +228,12 @@ func saveStageDependencies(index int, stages []instructions.Stage, buildArgs *do dependencies, err := dockerfile.Dependencies(index, stages, buildArgs) logrus.Infof("saving dependencies %s", dependencies) if err != nil { + logrus.Info("returning err from getting dependencies") return err } + if len(dependencies) == 0 { + return nil + } // Then, create the directory they will exist in i := strconv.Itoa(index) dependencyDir := filepath.Join(constants.KanikoDir, i) diff --git a/pkg/snapshot/snapshot.go b/pkg/snapshot/snapshot.go index 478095afc5..d6e80dc171 100644 --- a/pkg/snapshot/snapshot.go +++ b/pkg/snapshot/snapshot.go @@ -93,7 +93,7 @@ func (s *Snapshotter) snapshotFiles(f io.Writer, files []string) (bool, error) { if val, ok := snapshottedFiles[file]; ok && val { continue } - if util.PathInWhitelist(file, s.directory) { + if util.CheckWhitelist(file) { logrus.Debugf("Not adding %s to layer, as it's whitelisted", file) continue } @@ -151,7 +151,7 @@ func (s *Snapshotter) snapShotFS(f io.Writer) (bool, error) { // Now create the tar. for path, info := range memFs { - if util.PathInWhitelist(path, s.directory) { + if util.CheckWhitelist(path) { logrus.Debugf("Not adding %s to layer, as it's whitelisted", path) continue } diff --git a/pkg/util/command_util.go b/pkg/util/command_util.go index 8d4bb37155..7b3a57e330 100644 --- a/pkg/util/command_util.go +++ b/pkg/util/command_util.go @@ -89,20 +89,25 @@ func ContainsWildcards(paths []string) bool { // It returns a list of resolved sources func ResolveSources(srcsAndDest instructions.SourcesAndDest, root string) ([]string, error) { srcs := srcsAndDest[:len(srcsAndDest)-1] + logrus.Infof("looking at srcs %s", srcs) // If sources contain wildcards, we first need to resolve them to actual paths if ContainsWildcards(srcs) { logrus.Debugf("Resolving srcs %v...", srcs) files, err := RelativeFiles("", root) if err != nil { + logrus.Info("error getting relative files") return nil, err } srcs, err = matchSources(srcs, files) + logrus.Infof("srcs after matching: %s", srcs) if err != nil { + logrus.Info("error matching sources") return nil, err } logrus.Debugf("Resolved sources to %v", srcs) } // Check to make sure the sources are valid + logrus.Infof("sources %s are not valid", srcs) return srcs, IsSrcsValid(srcsAndDest, srcs, root) } diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 1ac72780cd..e37ade0bcd 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -91,12 +91,12 @@ func GetFSFromImage(img v1.Image) error { continue } - if checkWhitelist(path, whitelist) { + if CheckWhitelist(path) { logrus.Infof("Not adding %s because it is whitelisted", path) continue } if hdr.Typeflag == tar.TypeSymlink { - if checkWhitelist(hdr.Linkname, whitelist) { + if CheckWhitelist(hdr.Linkname) { logrus.Debugf("skipping symlink from %s to %s because %s is whitelisted", hdr.Linkname, path, hdr.Linkname) continue } @@ -115,7 +115,7 @@ func GetFSFromImage(img v1.Image) error { func DeleteFilesystem() error { logrus.Info("Deleting filesystem...") err := filepath.Walk(constants.RootDir, func(path string, info os.FileInfo, err error) error { - if PathInWhitelist(path, constants.RootDir) || ChildDirInWhitelist(path, constants.RootDir) { + if CheckWhitelist(path) || ChildDirInWhitelist(path, constants.RootDir) { logrus.Debugf("Not deleting %s, as it's whitelisted", path) return nil } @@ -233,20 +233,20 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { return nil } -func PathInWhitelist(path, directory string) bool { - for _, c := range constants.KanikoBuildFiles { - if path == c { - return false - } - } - for _, d := range whitelist { - dirPath := filepath.Join(directory, d) - if HasFilepathPrefix(path, dirPath) { - return true - } - } - return false -} +// func PathInWhitelist(path, directory string) bool { +// for _, c := range constants.KanikoBuildFiles { +// if path == c { +// return false +// } +// } +// for _, d := range whitelist { +// dirPath := filepath.Join(directory, d) +// if HasFilepathPrefix(path, dirPath) { +// return true +// } +// } +// return false +// } func checkWhiteouts(path string, whiteouts map[string]struct{}) bool { // Don't add the file if it or it's directory are whited out. @@ -262,7 +262,7 @@ func checkWhiteouts(path string, whiteouts map[string]struct{}) bool { return false } -func checkWhitelist(path string, whitelist []string) bool { +func CheckWhitelist(path string) bool { for _, wl := range whitelist { if HasFilepathPrefix(path, wl) { return true @@ -316,6 +316,9 @@ func RelativeFiles(fp string, root string) ([]string, error) { fullPath := filepath.Join(root, fp) logrus.Debugf("Getting files and contents at root %s", fullPath) err := filepath.Walk(fullPath, func(path string, info os.FileInfo, err error) error { + if CheckWhitelist(path) && !HasFilepathPrefix(path, root) { + return nil + } if err != nil { return err } @@ -334,7 +337,7 @@ func Files(root string) ([]string, error) { var files []string logrus.Debugf("Getting files and contents at root %s", root) err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { - if PathInWhitelist(path, root) { + if CheckWhitelist(path) { return nil } files = append(files, path)