github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/daemon/images/cache.go (about)

     1  package images // import "github.com/Prakhar-Agarwal-byte/moby/daemon/images"
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/containerd/log"
     7  	imagetypes "github.com/Prakhar-Agarwal-byte/moby/api/types/image"
     8  	"github.com/Prakhar-Agarwal-byte/moby/builder"
     9  	"github.com/Prakhar-Agarwal-byte/moby/image/cache"
    10  	"github.com/pkg/errors"
    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  			log.G(ctx).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  }