mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 05:35:49 +02:00
Fix caching to respect .dockerignore
Previously kaniko would compute the cache key for any copy command by computing the combined hash of all files in a directory, even if they were listed as ignored. With this change, the cache key creation was updated to be aware of ignored files. Related issues: * https://github.com/GoogleContainerTools/kaniko/issues/594
This commit is contained in:
committed by
Tejal Desai
parent
a2aae6274d
commit
123dcaf83e
@@ -54,14 +54,18 @@ func (s *CompositeCache) Hash() (string, error) {
|
||||
return util.SHA256(strings.NewReader(s.Key()))
|
||||
}
|
||||
|
||||
func (s *CompositeCache) AddPath(p string) error {
|
||||
func (s *CompositeCache) AddPath(p, context string) error {
|
||||
sha := sha256.New()
|
||||
fi, err := os.Lstat(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if util.ExcludeFile(p, context) {
|
||||
return os.ErrNotExist
|
||||
}
|
||||
|
||||
if fi.Mode().IsDir() {
|
||||
k, err := HashDir(p)
|
||||
k, err := HashDir(p, context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -81,12 +85,20 @@ func (s *CompositeCache) AddPath(p string) error {
|
||||
}
|
||||
|
||||
// HashDir returns a hash of the directory.
|
||||
func HashDir(p string) (string, error) {
|
||||
func HashDir(p, context string) (string, error) {
|
||||
sha := sha256.New()
|
||||
if err := filepath.Walk(p, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exclude := util.ExcludeFile(path, context)
|
||||
if fi.IsDir() && exclude {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if exclude {
|
||||
return nil
|
||||
}
|
||||
|
||||
fileHash, err := util.CacheHasher()(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user