github.com/skanehira/moby@v17.12.1-ce-rc2+incompatible/daemon/image_push.go (about)

     1  package daemon
     2  
     3  import (
     4  	"io"
     5  	"runtime"
     6  
     7  	"github.com/docker/distribution/manifest/schema2"
     8  	"github.com/docker/distribution/reference"
     9  	"github.com/docker/docker/api/types"
    10  	"github.com/docker/docker/distribution"
    11  	progressutils "github.com/docker/docker/distribution/utils"
    12  	"github.com/docker/docker/pkg/progress"
    13  	"github.com/docker/docker/pkg/system"
    14  	"golang.org/x/net/context"
    15  )
    16  
    17  // PushImage initiates a push operation on the repository named localName.
    18  func (daemon *Daemon) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
    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  	// TODO @jhowardmsft LCOW Support. This will require revisiting. For now, hard-code.
    45  	platform := runtime.GOOS
    46  	if system.LCOWSupported() {
    47  		platform = "linux"
    48  	}
    49  
    50  	imagePushConfig := &distribution.ImagePushConfig{
    51  		Config: distribution.Config{
    52  			MetaHeaders:      metaHeaders,
    53  			AuthConfig:       authConfig,
    54  			ProgressOutput:   progress.ChanOutput(progressChan),
    55  			RegistryService:  daemon.RegistryService,
    56  			ImageEventLogger: daemon.LogImageEvent,
    57  			MetadataStore:    daemon.stores[platform].distributionMetadataStore,
    58  			ImageStore:       distribution.NewImageConfigStoreFromStore(daemon.stores[platform].imageStore),
    59  			ReferenceStore:   daemon.referenceStore,
    60  		},
    61  		ConfigMediaType: schema2.MediaTypeImageConfig,
    62  		LayerStore:      distribution.NewLayerProviderFromStore(daemon.stores[platform].layerStore),
    63  		TrustKey:        daemon.trustKey,
    64  		UploadManager:   daemon.uploadManager,
    65  	}
    66  
    67  	err = distribution.Push(ctx, ref, imagePushConfig)
    68  	close(progressChan)
    69  	<-writesDone
    70  	return err
    71  }