Skip to content

Commit

Permalink
Even faster snapshotting with godirwalk. (#504)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlorenc committed Jan 3, 2019
1 parent c3afcc0 commit a044e2b
Show file tree
Hide file tree
Showing 13 changed files with 822 additions and 15 deletions.
13 changes: 13 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions pkg/snapshot/snapshot.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions vendor/github.com/karrick/godirwalk/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions vendor/github.com/karrick/godirwalk/dirent.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions vendor/github.com/karrick/godirwalk/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions vendor/github.com/karrick/godirwalk/readdir.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions vendor/github.com/karrick/godirwalk/readdir_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a044e2b

Please sign in to comment.