github.com/kobeld/docker@v1.12.0-rc1/daemon/image_push.go (about) 1 package daemon 2 3 import ( 4 "io" 5 6 "github.com/docker/docker/distribution" 7 "github.com/docker/docker/pkg/progress" 8 "github.com/docker/docker/reference" 9 "github.com/docker/engine-api/types" 10 "golang.org/x/net/context" 11 ) 12 13 // PushImage initiates a push operation on the repository named localName. 14 func (daemon *Daemon) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error { 15 ref, err := reference.ParseNamed(image) 16 if err != nil { 17 return err 18 } 19 if tag != "" { 20 // Push by digest is not supported, so only tags are supported. 21 ref, err = reference.WithTag(ref, tag) 22 if err != nil { 23 return err 24 } 25 } 26 27 // Include a buffer so that slow client connections don't affect 28 // transfer performance. 29 progressChan := make(chan progress.Progress, 100) 30 31 writesDone := make(chan struct{}) 32 33 ctx, cancelFunc := context.WithCancel(ctx) 34 35 go func() { 36 writeDistributionProgress(cancelFunc, outStream, progressChan) 37 close(writesDone) 38 }() 39 40 imagePushConfig := &distribution.ImagePushConfig{ 41 MetaHeaders: metaHeaders, 42 AuthConfig: authConfig, 43 ProgressOutput: progress.ChanOutput(progressChan), 44 RegistryService: daemon.RegistryService, 45 ImageEventLogger: daemon.LogImageEvent, 46 MetadataStore: daemon.distributionMetadataStore, 47 LayerStore: daemon.layerStore, 48 ImageStore: daemon.imageStore, 49 ReferenceStore: daemon.referenceStore, 50 TrustKey: daemon.trustKey, 51 UploadManager: daemon.uploadManager, 52 } 53 54 err = distribution.Push(ctx, ref, imagePushConfig) 55 close(progressChan) 56 <-writesDone 57 return err 58 }