moby/daemon/images/cache.go
Sebastiaan van Stijn a3a42c459e
api/types/image: move GetImageOpts to api/types/backend
The `GetImageOpts` struct is used for options to be passed to the backend,
and are not used in client code. This struct currently is intended for internal
use only.

This patch moves the `GetImageOpts` struct to the backend package to prevent
it being imported in the client, and to make it more clear that this is part
of internal APIs, and not public-facing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-01-22 20:45:21 +01:00

34 lines
910 B
Go

package images // import "github.com/docker/docker/daemon/images"
import (
"context"
"github.com/containerd/log"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/builder"
"github.com/docker/docker/image/cache"
"github.com/pkg/errors"
)
// 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, backend.GetImageOpts{})
if err != nil {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return nil, err
}
log.G(ctx).Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err)
continue
}
cache.Populate(img)
}
return cache, nil
}