Try to warm all images and warn about errors (#1653)
When providing multiple images to warm, the warmer stops at the first error. There are use cases however where an image is provided to the warmer which does not yet exist on purpose (e.g. CI/CD latest image only created at first release). Thus we want to try all given images and only error if none of them work.
This commit is contained in:
parent
f21639daac
commit
1ee4140024
|
|
@ -39,6 +39,7 @@ func WarmCache(opts *config.WarmerOptions) error {
|
|||
logrus.Debugf("%s\n", cacheDir)
|
||||
logrus.Debugf("%s\n", images)
|
||||
|
||||
errs := 0
|
||||
for _, img := range images {
|
||||
tarBuf := new(bytes.Buffer)
|
||||
manifestBuf := new(bytes.Buffer)
|
||||
|
|
@ -53,7 +54,8 @@ func WarmCache(opts *config.WarmerOptions) error {
|
|||
digest, err := cw.Warm(img, opts)
|
||||
if err != nil {
|
||||
if !IsAlreadyCached(err) {
|
||||
return err
|
||||
logrus.Warnf("Error while trying to warm image: %v %v", img, err)
|
||||
errs++
|
||||
}
|
||||
|
||||
continue
|
||||
|
|
@ -62,11 +64,18 @@ func WarmCache(opts *config.WarmerOptions) error {
|
|||
cachePath := path.Join(cacheDir, digest.String())
|
||||
|
||||
if err := writeBufsToFile(cachePath, tarBuf, manifestBuf); err != nil {
|
||||
return err
|
||||
logrus.Warnf("Error while writing %v to cache: %v", img, err)
|
||||
errs++
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Debugf("Wrote %s to cache", img)
|
||||
}
|
||||
|
||||
if len(images) == errs {
|
||||
return errors.New("Failed to warm any of the given images")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue