Skip to content

Commit

Permalink
Avoid the cachedImage/remoteImage call loop (#483)
Browse files Browse the repository at this point in the history
* Avoid the cachedImage/remoteImage call loop

* missed one function

* fix unit tests

* proper bool comparison
  • Loading branch information
sharifelgamal authored Dec 10, 2018
1 parent 7611ea7 commit 7f9ea39
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func fetchExtraStages(stages []config.KanikoStage, opts *config.KanikoOptions) e
}
// This must be an image name, fetch it.
logrus.Debugf("Found extra base image stage %s", c.From)
sourceImage, err := util.RetrieveRemoteImage(c.From, opts)
sourceImage, err := util.RetrieveRemoteImage(c.From, opts, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -448,7 +448,7 @@ func saveStageAsTarball(path string, image v1.Image) error {
return err
}
tarPath := filepath.Join(constants.KanikoIntermediateStagesDir, path)
logrus.Infof("Storing source image from stage %d at path %s", path, tarPath)
logrus.Infof("Storing source image from stage %s at path %s", path, tarPath)
if err := os.MkdirAll(filepath.Dir(tarPath), 0750); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func RetrieveSourceImage(stage config.KanikoStage, opts *config.KanikoOptions) (
}

// Otherwise, initialize image as usual
return RetrieveRemoteImage(currentBaseName, opts)
return RetrieveRemoteImage(currentBaseName, opts, false)
}

// RetrieveConfigFile returns the config file for an image
Expand All @@ -89,11 +89,11 @@ func tarballImage(index int) (v1.Image, error) {
return tarball.ImageFromPath(tarPath, nil)
}

func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
func remoteImage(image string, opts *config.KanikoOptions, forceNoCache bool) (v1.Image, error) {
logrus.Infof("Downloading base image %s", image)
// First, check if local caching is enabled
// If so, look in the local cache before trying the remote registry
if opts.Cache && opts.CacheDir != "" {
if opts.Cache && opts.CacheDir != "" && !forceNoCache {
cachedImage, err := cachedImage(opts, image)
if cachedImage != nil {
return cachedImage, nil
Expand Down Expand Up @@ -148,7 +148,7 @@ func cachedImage(opts *config.KanikoOptions, image string) (v1.Image, error) {
if d, ok := ref.(name.Digest); ok {
cacheKey = d.DigestStr()
} else {
img, err := remoteImage(image, opts)
img, err := remoteImage(image, opts, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/image_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_StandardImage(t *testing.T) {
defer func() {
RetrieveRemoteImage = original
}()
mock := func(image string, opts *config.KanikoOptions) (v1.Image, error) {
mock := func(image string, opts *config.KanikoOptions, forceNoCache bool) (v1.Image, error) {
return nil, nil
}
RetrieveRemoteImage = mock
Expand Down

0 comments on commit 7f9ea39

Please sign in to comment.