From a73d07ff7a5835c7b357c18e4512ff710a2cd6c7 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Fri, 10 Feb 2023 11:09:02 +0000 Subject: [PATCH] imagetools: process com.docker.reference.* annotations To give us the option later down the road of producing recommended OCI names in BuildKit (using com instead of vnd, woops), we need to update Buildx to be able to process both. Ideally, if a Buildx/BuildKit release hadn't been made we could just switch over, but since we have, we'd need to support both (at least for a while, eventually we could consider deprecating+removing the vnd variant). Signed-off-by: Justin Chadwell (cherry picked from commit 642f28f439e9da9bbd528f8a46506ca3bdc95028) --- util/imagetools/loader.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/util/imagetools/loader.go b/util/imagetools/loader.go index 9bba4e21..a1651566 100644 --- a/util/imagetools/loader.go +++ b/util/imagetools/loader.go @@ -21,8 +21,11 @@ import ( "golang.org/x/sync/errgroup" ) -const ( - annotationReference = "vnd.docker.reference.digest" +var ( + annotationReferences = []string{ + "com.docker.reference.digest", + "vnd.docker.reference.digest", // TODO: deprecate/remove after migration to new annotation + } ) type contentCache interface { @@ -167,8 +170,13 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe } r.mu.Unlock() - ref, ok := desc.Annotations[annotationReference] - if ok { + found := false + for _, annotationReference := range annotationReferences { + ref, ok := desc.Annotations[annotationReference] + if !ok { + continue + } + refdgst, err := digest.Parse(ref) if err != nil { return err @@ -176,7 +184,10 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe r.mu.Lock() r.refs[refdgst] = append(r.refs[refdgst], desc.Digest) r.mu.Unlock() - } else { + found = true + break + } + if !found { p := desc.Platform if p == nil { p, err = l.readPlatformFromConfig(ctx, fetcher, mfst.Config)