Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Jul 9, 2018
1 parent 0740fa6 commit 96cad80
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
4 changes: 4 additions & 0 deletions pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/command_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
41 changes: 22 additions & 19 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 96cad80

Please sign in to comment.