Avoid the cachedImage/remoteImage call loop (#483)
* Avoid the cachedImage/remoteImage call loop * missed one function * fix unit tests * proper bool comparison
This commit is contained in:
parent
7611ea7a1d
commit
7f9ea39bf7
|
|
@ -417,7 +417,7 @@ func fetchExtraStages(stages []config.KanikoStage, opts *config.KanikoOptions) e
|
||||||
}
|
}
|
||||||
// This must be an image name, fetch it.
|
// This must be an image name, fetch it.
|
||||||
logrus.Debugf("Found extra base image stage %s", c.From)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -448,7 +448,7 @@ func saveStageAsTarball(path string, image v1.Image) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tarPath := filepath.Join(constants.KanikoIntermediateStagesDir, path)
|
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 {
|
if err := os.MkdirAll(filepath.Dir(tarPath), 0750); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ func RetrieveSourceImage(stage config.KanikoStage, opts *config.KanikoOptions) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, initialize image as usual
|
// Otherwise, initialize image as usual
|
||||||
return RetrieveRemoteImage(currentBaseName, opts)
|
return RetrieveRemoteImage(currentBaseName, opts, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetrieveConfigFile returns the config file for an image
|
// RetrieveConfigFile returns the config file for an image
|
||||||
|
|
@ -89,11 +89,11 @@ func tarballImage(index int) (v1.Image, error) {
|
||||||
return tarball.ImageFromPath(tarPath, nil)
|
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)
|
logrus.Infof("Downloading base image %s", image)
|
||||||
// First, check if local caching is enabled
|
// First, check if local caching is enabled
|
||||||
// If so, look in the local cache before trying the remote registry
|
// 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)
|
cachedImage, err := cachedImage(opts, image)
|
||||||
if cachedImage != nil {
|
if cachedImage != nil {
|
||||||
return 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 {
|
if d, ok := ref.(name.Digest); ok {
|
||||||
cacheKey = d.DigestStr()
|
cacheKey = d.DigestStr()
|
||||||
} else {
|
} else {
|
||||||
img, err := remoteImage(image, opts)
|
img, err := remoteImage(image, opts, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func Test_StandardImage(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
RetrieveRemoteImage = original
|
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
|
return nil, nil
|
||||||
}
|
}
|
||||||
RetrieveRemoteImage = mock
|
RetrieveRemoteImage = mock
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue