github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/images/cache.go (about)

     1  package images // import "github.com/docker/docker/daemon/images"
     2  
     3  import (
     4  	"context"
     5  
     6  	imagetypes "github.com/docker/docker/api/types/image"
     7  	"github.com/docker/docker/builder"
     8  	"github.com/docker/docker/image/cache"
     9  	"github.com/pkg/errors"
    10  	"github.com/sirupsen/logrus"
    11  )
    12  
    13  // MakeImageCache creates a stateful image cache.
    14  func (i *ImageService) MakeImageCache(ctx context.Context, sourceRefs []string) (builder.ImageCache, error) {
    15  	if len(sourceRefs) == 0 {
    16  		return cache.NewLocal(i.imageStore), nil
    17  	}
    18  
    19  	cache := cache.New(i.imageStore)
    20  
    21  	for _, ref := range sourceRefs {
    22  		img, err := i.GetImage(ctx, ref, imagetypes.GetImageOpts{})
    23  		if err != nil {
    24  			if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
    25  				return nil, err
    26  			}
    27  			logrus.Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err)
    28  			continue
    29  		}
    30  		cache.Populate(img)
    31  	}
    32  
    33  	return cache, nil
    34  }