-
Notifications
You must be signed in to change notification settings - Fork 18.7k
/
cache.go
34 lines (28 loc) · 919 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
}