Merge pull request #452 from sharifelgamal/cache-fix
Create cache directory if it doesn't already exist
This commit is contained in:
commit
56eeaf41e6
|
|
@ -52,6 +52,12 @@ var RootCmd = &cobra.Command{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if _, err := os.Stat(opts.CacheDir); os.IsNotExist(err) {
|
||||||
|
err = os.MkdirAll(opts.CacheDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
exit(errors.Wrap(err, "Failed to create cache directory"))
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := cache.WarmCache(opts); err != nil {
|
if err := cache.WarmCache(opts); err != nil {
|
||||||
exit(errors.Wrap(err, "Failed warming cache"))
|
exit(errors.Wrap(err, "Failed warming cache"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func (rc *RegistryCache) RetrieveLayer(ck string) (v1.Image, error) {
|
||||||
// Layer is stale, rebuild it.
|
// Layer is stale, rebuild it.
|
||||||
if expiry.Before(time.Now()) {
|
if expiry.Before(time.Now()) {
|
||||||
logrus.Infof("Cache entry expired: %s", cache)
|
logrus.Infof("Cache entry expired: %s", cache)
|
||||||
return nil, errors.New(fmt.Sprintf("Cache entry expired: %s", cache))
|
return nil, fmt.Errorf("Cache entry expired: %s", cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force the manifest to be populated
|
// Force the manifest to be populated
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WarmCache populates the cache
|
||||||
func WarmCache(opts *config.WarmerOptions) error {
|
func WarmCache(opts *config.WarmerOptions) error {
|
||||||
cacheDir := opts.CacheDir
|
cacheDir := opts.CacheDir
|
||||||
images := opts.Images
|
images := opts.Images
|
||||||
|
|
@ -41,7 +42,7 @@ func WarmCache(opts *config.WarmerOptions) error {
|
||||||
return 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)
|
img, err := remote.Image(cacheRef)
|
||||||
if err != nil {
|
if err != nil || img == nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("Failed to retrieve image: %s", image))
|
return errors.Wrap(err, fmt.Sprintf("Failed to retrieve image: %s", image))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue