mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
def549c8f6
Co-authored-by: Paweł Gronowski <pawel.gronowski@docker.com> Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
34 lines
919 B
Go
34 lines
919 B
Go
package images // import "github.com/docker/docker/daemon/images"
|
|
|
|
import (
|
|
"context"
|
|
|
|
imagetypes "github.com/docker/docker/api/types/image"
|
|
"github.com/docker/docker/builder"
|
|
"github.com/docker/docker/image/cache"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// MakeImageCache creates a stateful image cache.
|
|
func (i *ImageService) MakeImageCache(ctx context.Context, sourceRefs []string) (builder.ImageCache, error) {
|
|
if len(sourceRefs) == 0 {
|
|
return cache.NewLocal(i.imageStore), nil
|
|
}
|
|
|
|
cache := cache.New(i.imageStore)
|
|
|
|
for _, ref := range sourceRefs {
|
|
img, err := i.GetImage(ctx, ref, imagetypes.GetImageOpts{})
|
|
if err != nil {
|
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
|
return nil, err
|
|
}
|
|
logrus.Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err)
|
|
continue
|
|
}
|
|
cache.Populate(img)
|
|
}
|
|
|
|
return cache, nil
|
|
}
|