diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go index 0534d2cf8d..dcb190fb2b 100644 --- a/api/server/router/image/backend.go +++ b/api/server/router/image/backend.go @@ -24,7 +24,7 @@ type imageBackend interface { ImageDelete(ctx context.Context, imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) ImageHistory(imageName string) ([]*image.HistoryResponseItem, error) Images(ctx context.Context, opts types.ImageListOptions) ([]*types.ImageSummary, error) - GetImage(refOrID string, platform *specs.Platform) (retImg *dockerimage.Image, retErr error) + GetImage(refOrID string, options image.GetImageOpts) (*dockerimage.Image, error) TagImage(imageName, repository, tag string) (string, error) ImagesPrune(ctx context.Context, pruneFilters filters.Args) (*types.ImagesPruneReport, error) } diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index 8fdee3b773..e2654cb279 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + opts "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" @@ -192,7 +193,7 @@ func (ir *imageRouter) deleteImages(ctx context.Context, w http.ResponseWriter, } func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - img, err := ir.backend.GetImage(vars["name"], nil) + img, err := ir.backend.GetImage(vars["name"], opts.GetImageOpts{}) if err != nil { return err } diff --git a/api/types/image/opts.go b/api/types/image/opts.go new file mode 100644 index 0000000000..2a99696228 --- /dev/null +++ b/api/types/image/opts.go @@ -0,0 +1,8 @@ +package image + +import specs "github.com/opencontainers/image-spec/specs-go/v1" + +// GetImageOpts holds parameters to inspect an image. +type GetImageOpts struct { + Platform *specs.Platform +} diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 280c030106..8aab1b13e0 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" + opts "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" @@ -76,5 +77,5 @@ type VolumeBackend interface { type ImageBackend interface { PullImage(ctx context.Context, image, tag string, platform *specs.Platform, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error GetRepository(context.Context, reference.Named, *registry.AuthConfig) (distribution.Repository, error) - GetImage(refOrID string, platform *specs.Platform) (retImg *image.Image, retErr error) + GetImage(refOrID string, options opts.GetImageOpts) (*image.Image, error) } diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index 979e788fe4..8e9aa108ac 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -16,6 +16,7 @@ import ( "github.com/docker/docker/api/types/backend" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" containerpkg "github.com/docker/docker/container" "github.com/docker/docker/daemon" @@ -75,7 +76,7 @@ func (c *containerAdapter) pullImage(ctx context.Context) error { named, err := reference.ParseNormalizedNamed(spec.Image) if err == nil { if _, ok := named.(reference.Canonical); ok { - _, err := c.imageBackend.GetImage(spec.Image, nil) + _, err := c.imageBackend.GetImage(spec.Image, imagetypes.GetImageOpts{}) if err == nil { return nil } diff --git a/daemon/containerd/image.go b/daemon/containerd/image.go index e4022b204e..6405ec63a7 100644 --- a/daemon/containerd/image.go +++ b/daemon/containerd/image.go @@ -1,11 +1,11 @@ package containerd import ( + imagetype "github.com/docker/docker/api/types/image" "github.com/docker/docker/image" - specs "github.com/opencontainers/image-spec/specs-go/v1" ) // GetImage returns an image corresponding to the image referred to by refOrID. -func (i *ImageService) GetImage(refOrID string, platform *specs.Platform) (retImg *image.Image, retErr error) { +func (i *ImageService) GetImage(refOrID string, options imagetype.GetImageOpts) (retImg *image.Image, retErr error) { panic("not implemented") } diff --git a/daemon/create.go b/daemon/create.go index 4d44d01ca6..c843381ce0 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -10,6 +10,7 @@ import ( "github.com/containerd/containerd/platforms" "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" + imagetypes "github.com/docker/docker/api/types/image" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/container" "github.com/docker/docker/daemon/images" @@ -68,7 +69,7 @@ func (daemon *Daemon) containerCreate(opts createOpts) (containertypes.CreateRes } if opts.params.Platform == nil && opts.params.Config.Image != "" { - if img, _ := daemon.imageService.GetImage(opts.params.Config.Image, opts.params.Platform); img != nil { + if img, _ := daemon.imageService.GetImage(opts.params.Config.Image, imagetypes.GetImageOpts{Platform: opts.params.Platform}); img != nil { p := maximumSpec() imgPlat := v1.Platform{ OS: img.OS, @@ -119,7 +120,7 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr ) if opts.params.Config.Image != "" { - img, err = daemon.imageService.GetImage(opts.params.Config.Image, opts.params.Platform) + img, err = daemon.imageService.GetImage(opts.params.Config.Image, imagetypes.GetImageOpts{Platform: opts.params.Platform}) if err != nil { return nil, err } diff --git a/daemon/image_service.go b/daemon/image_service.go index cb0bb8dc5e..e6be1c763f 100644 --- a/daemon/image_service.go +++ b/daemon/image_service.go @@ -40,7 +40,7 @@ type ImageService interface { ImportImage(src string, repository string, platform *v1.Platform, tag string, msg string, inConfig io.ReadCloser, outStream io.Writer, changes []string) error TagImage(imageName, repository, tag string) (string, error) TagImageWithReference(imageID image.ID, newTag reference.Named) error - GetImage(refOrID string, platform *v1.Platform) (retImg *image.Image, retErr error) + GetImage(refOrID string, options imagetype.GetImageOpts) (*image.Image, error) ImageHistory(name string) ([]*imagetype.HistoryResponseItem, error) CommitImage(c backend.CommitConfig) (image.ID, error) SquashImage(id, parent string) (string, error) diff --git a/daemon/images/cache.go b/daemon/images/cache.go index 445b1b9261..d81136b8a3 100644 --- a/daemon/images/cache.go +++ b/daemon/images/cache.go @@ -1,6 +1,7 @@ package images // import "github.com/docker/docker/daemon/images" import ( + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/builder" "github.com/docker/docker/image/cache" "github.com/sirupsen/logrus" @@ -15,7 +16,7 @@ func (i *ImageService) MakeImageCache(sourceRefs []string) builder.ImageCache { cache := cache.New(i.imageStore) for _, ref := range sourceRefs { - img, err := i.GetImage(ref, nil) + img, err := i.GetImage(ref, imagetypes.GetImageOpts{}) if err != nil { logrus.Warnf("Could not look up %s for cache resolution, skipping: %+v", ref, err) continue diff --git a/daemon/images/image.go b/daemon/images/image.go index b6a994cb9d..ddd7e19ae3 100644 --- a/daemon/images/image.go +++ b/daemon/images/image.go @@ -12,6 +12,7 @@ import ( "github.com/containerd/containerd/leases" "github.com/containerd/containerd/platforms" "github.com/docker/distribution/reference" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/errdefs" "github.com/docker/docker/image" "github.com/opencontainers/go-digest" @@ -148,9 +149,9 @@ func (i *ImageService) manifestMatchesPlatform(img *image.Image, platform specs. } // GetImage returns an image corresponding to the image referred to by refOrID. -func (i *ImageService) GetImage(refOrID string, platform *specs.Platform) (retImg *image.Image, retErr error) { +func (i *ImageService) GetImage(refOrID string, options imagetypes.GetImageOpts) (retImg *image.Image, retErr error) { defer func() { - if retErr != nil || retImg == nil || platform == nil { + if retErr != nil || retImg == nil || options.Platform == nil { return } @@ -159,7 +160,7 @@ func (i *ImageService) GetImage(refOrID string, platform *specs.Platform) (retIm Architecture: retImg.Architecture, Variant: retImg.Variant, } - p := *platform + p := *options.Platform // Note that `platforms.Only` will fuzzy match this for us // For example: an armv6 image will run just fine an an armv7 CPU, without emulation or anything. if OnlyPlatformWithFallback(p).Match(imgPlat) { diff --git a/daemon/images/image_builder.go b/daemon/images/image_builder.go index a5fa0aa46d..5ec5442eb2 100644 --- a/daemon/images/image_builder.go +++ b/daemon/images/image_builder.go @@ -8,6 +8,7 @@ import ( "github.com/containerd/containerd/platforms" "github.com/docker/distribution/reference" "github.com/docker/docker/api/types/backend" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/builder" "github.com/docker/docker/errdefs" @@ -167,7 +168,7 @@ func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConf return nil, err } - img, err := i.GetImage(name, platform) + img, err := i.GetImage(name, imagetypes.GetImageOpts{Platform: platform}) if errdefs.IsNotFound(err) && img != nil && platform != nil { imgPlat := specs.Platform{ OS: img.OS, @@ -211,7 +212,7 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s } if opts.PullOption != backend.PullOptionForcePull { - img, err := i.GetImage(refOrID, opts.Platform) + img, err := i.GetImage(refOrID, imagetypes.GetImageOpts{Platform: opts.Platform}) if err != nil && opts.PullOption == backend.PullOptionNoPull { return nil, nil, err } diff --git a/daemon/images/image_delete.go b/daemon/images/image_delete.go index a928b90bca..89dab288a0 100644 --- a/daemon/images/image_delete.go +++ b/daemon/images/image_delete.go @@ -8,6 +8,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" "github.com/docker/docker/image" @@ -63,7 +64,7 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force, start := time.Now() records := []types.ImageDeleteResponseItem{} - img, err := i.GetImage(imageRef, nil) + img, err := i.GetImage(imageRef, imagetypes.GetImageOpts{}) if err != nil { return nil, err } diff --git a/daemon/images/image_events.go b/daemon/images/image_events.go index 1d8cfcd914..e3e5952587 100644 --- a/daemon/images/image_events.go +++ b/daemon/images/image_events.go @@ -2,6 +2,7 @@ package images // import "github.com/docker/docker/daemon/images" import ( "github.com/docker/docker/api/types/events" + imagetypes "github.com/docker/docker/api/types/image" ) // LogImageEvent generates an event related to an image with only the default attributes. @@ -11,7 +12,7 @@ func (i *ImageService) LogImageEvent(imageID, refName, action string) { // LogImageEventWithAttributes generates an event related to an image with specific given attributes. func (i *ImageService) LogImageEventWithAttributes(imageID, refName, action string, attributes map[string]string) { - img, err := i.GetImage(imageID, nil) + img, err := i.GetImage(imageID, imagetypes.GetImageOpts{}) if err == nil && img.Config != nil { // image has not been removed yet. // it could be missing if the event is `delete`. diff --git a/daemon/images/image_history.go b/daemon/images/image_history.go index c1f4882952..135eb7d13f 100644 --- a/daemon/images/image_history.go +++ b/daemon/images/image_history.go @@ -13,7 +13,7 @@ import ( // name by walking the image lineage. func (i *ImageService) ImageHistory(name string) ([]*image.HistoryResponseItem, error) { start := time.Now() - img, err := i.GetImage(name, nil) + img, err := i.GetImage(name, image.GetImageOpts{}) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func (i *ImageService) ImageHistory(name string) ([]*image.HistoryResponseItem, if id == "" { break } - histImg, err = i.GetImage(id.String(), nil) + histImg, err = i.GetImage(id.String(), image.GetImageOpts{}) if err != nil { break } diff --git a/daemon/images/image_list.go b/daemon/images/image_list.go index e00e6ec5b8..32bb366d2c 100644 --- a/daemon/images/image_list.go +++ b/daemon/images/image_list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/container" "github.com/docker/docker/image" "github.com/docker/docker/layer" @@ -49,7 +50,7 @@ func (i *ImageService) Images(_ context.Context, opts types.ImageListOptions) ([ err error ) err = opts.Filters.WalkValues("before", func(value string) error { - beforeFilter, err = i.GetImage(value, nil) + beforeFilter, err = i.GetImage(value, imagetypes.GetImageOpts{}) return err }) if err != nil { @@ -57,7 +58,7 @@ func (i *ImageService) Images(_ context.Context, opts types.ImageListOptions) ([ } err = opts.Filters.WalkValues("since", func(value string) error { - sinceFilter, err = i.GetImage(value, nil) + sinceFilter, err = i.GetImage(value, imagetypes.GetImageOpts{}) return err }) if err != nil { diff --git a/daemon/images/image_pull.go b/daemon/images/image_pull.go index e6efd90fbf..0ad3eec99a 100644 --- a/daemon/images/image_pull.go +++ b/daemon/images/image_pull.go @@ -10,6 +10,7 @@ import ( "github.com/containerd/containerd/namespaces" dist "github.com/docker/distribution" "github.com/docker/distribution/reference" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/distribution" progressutils "github.com/docker/docker/distribution/utils" @@ -63,7 +64,7 @@ func (i *ImageService) PullImage(ctx context.Context, image, tag string, platfor // we allow the image to have a non-matching architecture. The code // below checks for this situation, and returns a warning to the client, // as well as logging it to the daemon logs. - img, err := i.GetImage(image, platform) + img, err := i.GetImage(image, imagetypes.GetImageOpts{Platform: platform}) // Note that this is a special case where GetImage returns both an image // and an error: https://github.com/docker/docker/blob/v20.10.7/daemon/images/image.go#L175-L183 diff --git a/daemon/images/image_tag.go b/daemon/images/image_tag.go index becd2e2df3..16a7aaea2c 100644 --- a/daemon/images/image_tag.go +++ b/daemon/images/image_tag.go @@ -2,13 +2,14 @@ package images // import "github.com/docker/docker/daemon/images" import ( "github.com/docker/distribution/reference" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/image" ) // TagImage creates the tag specified by newTag, pointing to the image named // imageName (alternatively, imageName can also be an image ID). func (i *ImageService) TagImage(imageName, repository, tag string) (string, error) { - img, err := i.GetImage(imageName, nil) + img, err := i.GetImage(imageName, imagetypes.GetImageOpts{}) if err != nil { return "", err } diff --git a/daemon/list.go b/daemon/list.go index f246066163..f1083d4f62 100644 --- a/daemon/list.go +++ b/daemon/list.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/container" "github.com/docker/docker/daemon/images" "github.com/docker/docker/errdefs" @@ -317,7 +318,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis if psFilters.Contains("ancestor") { ancestorFilter = true psFilters.WalkValues("ancestor", func(ancestor string) error { - img, err := daemon.imageService.GetImage(ancestor, nil) + img, err := daemon.imageService.GetImage(ancestor, imagetypes.GetImageOpts{}) if err != nil { logrus.Warnf("Error while looking up for image %v", ancestor) return nil @@ -581,7 +582,7 @@ func (daemon *Daemon) refreshImage(s *container.Snapshot, filter *listContext) ( c := s.Container tmpImage := s.Image // keep the original ref if still valid (hasn't changed) if tmpImage != s.ImageID { - img, err := daemon.imageService.GetImage(tmpImage, nil) + img, err := daemon.imageService.GetImage(tmpImage, imagetypes.GetImageOpts{}) if _, isDNE := err.(images.ErrImageDoesNotExist); err != nil && !isDNE { return nil, err } diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 886be9ae25..839daa2d98 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -8,6 +8,7 @@ import ( "strings" containertypes "github.com/docker/docker/api/types/container" + imagetypes "github.com/docker/docker/api/types/image" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" "github.com/docker/docker/oci" @@ -26,7 +27,7 @@ const ( func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) { - img, err := daemon.imageService.GetImage(string(c.ImageID), nil) + img, err := daemon.imageService.GetImage(string(c.ImageID), imagetypes.GetImageOpts{}) if err != nil { return nil, err }