imagetools: push support for create

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2019-04-18 20:07:00 -07:00
parent 80ad78e372
commit 96b1892b63
3 changed files with 30 additions and 2 deletions

View File

@ -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

View File

@ -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 {

2
vendor/modules.txt vendored
View File

@ -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