github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/images/image_push.go (about) 1 package images // import "github.com/docker/docker/daemon/images" 2 3 import ( 4 "context" 5 "io" 6 "time" 7 8 "github.com/docker/distribution/manifest/schema2" 9 "github.com/docker/distribution/reference" 10 "github.com/docker/docker/api/types/registry" 11 "github.com/docker/docker/distribution" 12 progressutils "github.com/docker/docker/distribution/utils" 13 "github.com/docker/docker/pkg/progress" 14 ) 15 16 // PushImage initiates a push operation on the repository named localName. 17 func (i *ImageService) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error { 18 start := time.Now() 19 ref, err := reference.ParseNormalizedNamed(image) 20 if err != nil { 21 return err 22 } 23 if tag != "" { 24 // Push by digest is not supported, so only tags are supported. 25 ref, err = reference.WithTag(ref, tag) 26 if err != nil { 27 return err 28 } 29 } 30 31 // Include a buffer so that slow client connections don't affect 32 // transfer performance. 33 progressChan := make(chan progress.Progress, 100) 34 35 writesDone := make(chan struct{}) 36 37 ctx, cancelFunc := context.WithCancel(ctx) 38 39 go func() { 40 progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan) 41 close(writesDone) 42 }() 43 44 imagePushConfig := &distribution.ImagePushConfig{ 45 Config: distribution.Config{ 46 MetaHeaders: metaHeaders, 47 AuthConfig: authConfig, 48 ProgressOutput: progress.ChanOutput(progressChan), 49 RegistryService: i.registryService, 50 ImageEventLogger: i.LogImageEvent, 51 MetadataStore: i.distributionMetadataStore, 52 ImageStore: distribution.NewImageConfigStoreFromStore(i.imageStore), 53 ReferenceStore: i.referenceStore, 54 }, 55 ConfigMediaType: schema2.MediaTypeImageConfig, 56 LayerStores: distribution.NewLayerProvidersFromStore(i.layerStore), 57 TrustKey: i.trustKey, 58 UploadManager: i.uploadManager, 59 } 60 61 err = distribution.Push(ctx, ref, imagePushConfig) 62 close(progressChan) 63 <-writesDone 64 imageActions.WithValues("push").UpdateSince(start) 65 return err 66 }