let's return errors when warming a cache (#553)

* let's return errors when warming a cache

* Fix lint error in warm.go
This commit is contained in:
James Rawlings 2019-02-08 21:14:53 +00:00 committed by dlorenc
parent 9047ccf7cc
commit af50bcec69
1 changed files with 5 additions and 7 deletions

12
pkg/cache/warm.go vendored
View File

@ -37,25 +37,23 @@ func WarmCache(opts *config.WarmerOptions) error {
for _, image := range images {
cacheRef, err := name.NewTag(image, name.WeakValidation)
if err != nil {
errors.Wrap(err, fmt.Sprintf("Failed to verify image name: %s", image))
return errors.Wrap(err, fmt.Sprintf("Failed to verify image name: %s", image))
}
img, err := remote.Image(cacheRef)
if err != nil {
errors.Wrap(err, fmt.Sprintf("Failed to retrieve image: %s", image))
return errors.Wrap(err, fmt.Sprintf("Failed to retrieve image: %s", image))
}
digest, err := img.Digest()
if err != nil {
errors.Wrap(err, fmt.Sprintf("Failed to retrieve digest: %s", image))
return errors.Wrap(err, fmt.Sprintf("Failed to retrieve digest: %s", image))
}
cachePath := path.Join(cacheDir, digest.String())
err = tarball.WriteToFile(cachePath, cacheRef, img)
if err != nil {
errors.Wrap(err, fmt.Sprintf("Failed to write %s to cache", image))
} else {
logrus.Debugf("Wrote %s to cache", image)
return errors.Wrap(err, fmt.Sprintf("Failed to write %s to cache", image))
}
logrus.Debugf("Wrote %s to cache", image)
}
return nil
}