Even faster snapshotting with godirwalk. (#504)

This switches from filepath.Walk to godirwalk.Walk for even faster snapshotting.
A quick test shows a 40% improvement on the dockerfile_mv_add build.
This commit is contained in:
dlorenc
2019-01-03 13:10:18 -06:00
committed by GitHub
parent c3afcc0c7d
commit a044e2b6e4
13 changed files with 822 additions and 15 deletions
+16 -15
View File
@@ -19,10 +19,11 @@ package snapshot
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"syscall"
"github.com/karrick/godirwalk"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/util"
@@ -141,22 +142,22 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
defer t.Close()
// Save the fs state in a map to iterate over later.
memFs := map[string]os.FileInfo{}
filepath.Walk(s.directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if util.IsInWhitelist(path) {
if util.IsDestDir(path) {
logrus.Infof("Skipping paths under %s, as it is a whitelisted directory", path)
return filepath.SkipDir
memFs := map[string]*godirwalk.Dirent{}
godirwalk.Walk(s.directory, &godirwalk.Options{
Callback: func(path string, ent *godirwalk.Dirent) error {
if util.IsInWhitelist(path) {
if util.IsDestDir(path) {
logrus.Infof("Skipping paths under %s, as it is a whitelisted directory", path)
return filepath.SkipDir
}
return nil
}
memFs[path] = ent
return nil
}
memFs[path] = info
return nil
})
},
Unsorted: true,
},
)
// First handle whiteouts
for p := range memFs {