daemon/image_push.go
47afe6bd
 package daemon
 
 import (
 	"io"
 
3c7676a0
 	"github.com/docker/distribution/manifest/schema2"
3a127939
 	"github.com/docker/distribution/reference"
91e197d6
 	"github.com/docker/docker/api/types"
47afe6bd
 	"github.com/docker/docker/distribution"
3d86b0c7
 	progressutils "github.com/docker/docker/distribution/utils"
47afe6bd
 	"github.com/docker/docker/pkg/progress"
 	"golang.org/x/net/context"
 )
 
 // PushImage initiates a push operation on the repository named localName.
 func (daemon *Daemon) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
3a127939
 	ref, err := reference.ParseNormalizedNamed(image)
47afe6bd
 	if err != nil {
 		return err
 	}
 	if tag != "" {
 		// Push by digest is not supported, so only tags are supported.
 		ref, err = reference.WithTag(ref, tag)
 		if err != nil {
 			return err
 		}
 	}
 
 	// Include a buffer so that slow client connections don't affect
 	// transfer performance.
 	progressChan := make(chan progress.Progress, 100)
 
 	writesDone := make(chan struct{})
 
 	ctx, cancelFunc := context.WithCancel(ctx)
 
 	go func() {
3d86b0c7
 		progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan)
47afe6bd
 		close(writesDone)
 	}()
 
 	imagePushConfig := &distribution.ImagePushConfig{
3c7676a0
 		Config: distribution.Config{
 			MetaHeaders:      metaHeaders,
 			AuthConfig:       authConfig,
 			ProgressOutput:   progress.ChanOutput(progressChan),
 			RegistryService:  daemon.RegistryService,
 			ImageEventLogger: daemon.LogImageEvent,
ce8e529e
 			MetadataStore:    daemon.distributionMetadataStore,
 			ImageStore:       distribution.NewImageConfigStoreFromStore(daemon.imageStore),
7b9a8f46
 			ReferenceStore:   daemon.referenceStore,
3c7676a0
 		},
 		ConfigMediaType: schema2.MediaTypeImageConfig,
afd305c4
 		LayerStores:     distribution.NewLayerProvidersFromStores(daemon.layerStores),
3c7676a0
 		TrustKey:        daemon.trustKey,
 		UploadManager:   daemon.uploadManager,
47afe6bd
 	}
 
 	err = distribution.Push(ctx, ref, imagePushConfig)
 	close(progressChan)
 	<-writesDone
 	return err
 }