From 96b1892b63463781cffbd21fdf8beb01ab1e1a03 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 18 Apr 2019 20:07:00 -0700 Subject: [PATCH] imagetools: push support for create Signed-off-by: Tonis Tiigi --- commands/imagetools/create.go | 14 +++++++++++++- util/imagetools/create.go | 16 ++++++++++++++++ vendor/modules.txt | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/commands/imagetools/create.go b/commands/imagetools/create.go index d119192b..be651794 100644 --- a/commands/imagetools/create.go +++ b/commands/imagetools/create.go @@ -137,10 +137,22 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error { if err != nil { return err } - _ = desc if in.dryrun { fmt.Printf("%s\n", dt) + return nil + } + + // new resolver cause need new auth + r = imagetools.New(imagetools.Opt{ + Auth: dockerCli.ConfigFile(), + }) + + for _, t := range tags { + if err := r.Push(ctx, t, desc, dt); err != nil { + return err + } + fmt.Println(t.String()) } return nil diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 2827c58e..8ecf7d1b 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -1,10 +1,13 @@ package imagetools import ( + "bytes" "context" "encoding/json" + "github.com/containerd/containerd/content" "github.com/containerd/containerd/images" + "github.com/docker/distribution/reference" "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/specs-go" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -142,6 +145,19 @@ func (r *Resolver) Combine(ctx context.Context, in string, descs []ocispec.Descr }, nil } +func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispec.Descriptor, dt []byte) error { + p, err := r.r.Pusher(ctx, ref.String()) + if err != nil { + return err + } + cw, err := p.Push(ctx, desc) + if err != nil { + return err + } + + return content.Copy(ctx, cw, bytes.NewReader(dt), desc.Size, desc.Digest) +} + func (r *Resolver) loadConfig(ctx context.Context, in string, dt []byte) (*ocispec.Image, error) { var manifest ocispec.Manifest if err := json.Unmarshal(dt, &manifest); err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 1cbbb13c..da13f0a5 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -29,11 +29,11 @@ github.com/containerd/console # github.com/containerd/containerd v1.3.0-0.20190321141026-ceba56893a76 github.com/containerd/containerd/platforms github.com/containerd/containerd/images +github.com/containerd/containerd/content github.com/containerd/containerd/remotes github.com/containerd/containerd/remotes/docker github.com/containerd/containerd/errdefs github.com/containerd/containerd/log -github.com/containerd/containerd/content github.com/containerd/containerd/content/local github.com/containerd/containerd/labels github.com/containerd/containerd/reference