From b497587f216e96ba75efe8e353143455ef4f374e Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Wed, 27 Oct 2021 17:14:49 -0700 Subject: [PATCH] imagetools: fix pushing same image with multiple names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit containerd pusher can’t handle this case atm so we need to make sure we always create a new resolver for each name. Signed-off-by: Tonis Tiigi --- util/imagetools/create.go | 2 +- util/imagetools/inspect.go | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 2913813c..bd7191f2 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -150,7 +150,7 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispec.Descriptor, dt []byte) error { ref = reference.TagNameOnly(ref) - p, err := r.r.Pusher(ctx, ref.String()) + p, err := r.resolver().Pusher(ctx, ref.String()) if err != nil { return err } diff --git a/util/imagetools/inspect.go b/util/imagetools/inspect.go index b7e2f74e..55da1184 100644 --- a/util/imagetools/inspect.go +++ b/util/imagetools/inspect.go @@ -24,26 +24,29 @@ type Opt struct { } type Resolver struct { - r remotes.Resolver + auth docker.Authorizer } func New(opt Opt) *Resolver { - resolver := docker.NewResolver(docker.ResolverOptions{ - Client: http.DefaultClient, - Credentials: toCredentialsFunc(opt.Auth), - }) return &Resolver{ - r: resolver, + auth: docker.NewDockerAuthorizer(docker.WithAuthCreds(toCredentialsFunc(opt.Auth)), docker.WithAuthClient(http.DefaultClient)), } } +func (r *Resolver) resolver() remotes.Resolver { + return docker.NewResolver(docker.ResolverOptions{ + Authorizer: r.auth, + Client: http.DefaultClient, + }) +} + func (r *Resolver) Resolve(ctx context.Context, in string) (string, ocispec.Descriptor, error) { ref, err := parseRef(in) if err != nil { return "", ocispec.Descriptor{}, err } - in, desc, err := r.r.Resolve(ctx, ref.String()) + in, desc, err := r.resolver().Resolve(ctx, ref.String()) if err != nil { return "", ocispec.Descriptor{}, err } @@ -65,7 +68,7 @@ func (r *Resolver) Get(ctx context.Context, in string) ([]byte, ocispec.Descript } func (r *Resolver) GetDescriptor(ctx context.Context, in string, desc ocispec.Descriptor) ([]byte, error) { - fetcher, err := r.r.Fetcher(ctx, in) + fetcher, err := r.resolver().Fetcher(ctx, in) if err != nil { return nil, err }