Update pusher to use content writer

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-06-05 17:30:17 -07:00
parent 621760f10a
commit 5615b68f06
7 changed files with 190 additions and 87 deletions

33
cmd/dist/push.go vendored
View File

@@ -92,7 +92,6 @@ var pushCommand = cli.Command{
return client.Push(ctx, ref, desc,
containerd.WithResolver(resolver),
containerd.WithImageHandler(jobHandler),
containerd.WithPushWrapper(ongoing.wrapPusher),
)
})
@@ -156,16 +155,16 @@ func (pt *pushTracker) Close() error {
return nil
}
type pushWrapper struct {
jobs *pushjobs
pusher remotes.Pusher
}
func (pw pushWrapper) Push(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error {
tr := pw.jobs.track(remotes.MakeRefKey(ctx, desc), desc.Size)
defer tr.Close()
return pw.pusher.Push(ctx, desc, io.TeeReader(r, tr))
}
//type pushWrapper struct {
// jobs *pushjobs
// pusher remotes.Pusher
//}
//
//func (pw pushWrapper) Push(ctx context.Context, desc ocispec.Descriptor, r io.Reader) error {
// tr := pw.jobs.track(remotes.MakeRefKey(ctx, desc), desc.Size)
// defer tr.Close()
// return pw.pusher.Push(ctx, desc, io.TeeReader(r, tr))
//}
type pushStatus struct {
name string
@@ -184,12 +183,12 @@ func newPushJobs() *pushjobs {
return &pushjobs{jobs: make(map[string]*pushTracker)}
}
func (j *pushjobs) wrapPusher(p remotes.Pusher) remotes.Pusher {
return pushWrapper{
jobs: j,
pusher: p,
}
}
//func (j *pushjobs) wrapPusher(p remotes.Pusher) remotes.Pusher {
// return pushWrapper{
// jobs: j,
// pusher: p,
// }
//}
func (j *pushjobs) add(ref string) {
j.mu.Lock()

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/log"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -63,8 +64,13 @@ var pushObjectCommand = cli.Command{
}
defer rc.Close()
cw, err := pusher.Push(ctx, desc)
if err != nil {
return err
}
// TODO: Progress reader
if err = pusher.Push(ctx, desc, rc); err != nil {
if err := content.Copy(cw, rc, desc.Size, desc.Digest); err != nil {
return err
}