github.com/openshift/moby-moby@v1.13.2-0.20170601211448-f5ec1e2936dc/daemon/image_push.go (about)

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