diff --git a/daemon/containerd/image_inspect.go b/daemon/containerd/image_inspect.go index e5e71ab37f..04de7b0ca9 100644 --- a/daemon/containerd/image_inspect.go +++ b/daemon/containerd/image_inspect.go @@ -11,6 +11,7 @@ import ( "time" c8dimages "github.com/containerd/containerd/v2/core/images" + "github.com/containerd/containerd/v2/pkg/labels" cerrdefs "github.com/containerd/errdefs" "github.com/containerd/log" "github.com/containerd/platforms" @@ -152,6 +153,8 @@ func (i *ImageService) imageIdentity(ctx context.Context, dgst digest.Digest) (* } identity := &imagetypes.Identity{} + seenRepos := make(map[string]struct{}) + for k, v := range info.Labels { if ref, ok := strings.CutPrefix(k, exporter.BuildRefLabel); ok { var val exporter.BuildRefLabelValue @@ -166,6 +169,23 @@ func (i *ImageService) imageIdentity(ctx context.Context, dgst digest.Digest) (* }) } } + if registry, ok := strings.CutPrefix(k, labels.LabelDistributionSource+"."); ok { + for repo := range strings.SplitSeq(v, ",") { + ref, err := reference.ParseNormalizedNamed(registry + "/" + repo) + if err != nil { + log.G(ctx).WithError(err).Error("failed to parse image name as reference") + continue + } + name := ref.Name() + if _, ok := seenRepos[name]; ok { + continue + } + seenRepos[name] = struct{}{} + identity.Pull = append(identity.Pull, imagetypes.PullIdentity{ + Repository: name, + }) + } + } } // return nil if there is no identity information