From f1a9f913233551549ea51a7eef92e321e4f56200 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 25 May 2022 12:10:07 +0100 Subject: [PATCH] imagetools: support cross-repo mounting Signed-off-by: Justin Chadwell --- util/imagetools/create.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 22462041..2480ebb1 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "encoding/json" + "net/url" + "strings" "github.com/containerd/containerd/content" "github.com/containerd/containerd/errdefs" @@ -183,6 +185,17 @@ func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named) return err } + refspec := reference.TrimNamed(src.Ref).String() + u, err := url.Parse("dummy://" + refspec) + if err != nil { + return err + } + source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/") + if src.Desc.Annotations == nil { + src.Desc.Annotations = make(map[string]string) + } + src.Desc.Annotations["containerd.io/distribution.source."+source] = repo + err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), src.Desc) if err != nil { return err