diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 17cc2dd0f..bd151d2b1 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -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 } @@ -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 } diff --git a/pkg/util/image_util.go b/pkg/util/image_util.go index cb167c9de..03dd1a442 100644 --- a/pkg/util/image_util.go +++ b/pkg/util/image_util.go @@ -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 @@ -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 @@ -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 } diff --git a/pkg/util/image_util_test.go b/pkg/util/image_util_test.go index c44fe8a58..e53ff4250 100644 --- a/pkg/util/image_util_test.go +++ b/pkg/util/image_util_test.go @@ -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