2018-02-07 15:52:47 -05:00
|
|
|
package images // import "github.com/docker/docker/daemon/images"
|
2016-04-07 17:29:18 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2016-12-16 14:19:05 -05:00
|
|
|
"github.com/docker/distribution/manifest/schema2"
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-04-07 17:29:18 -04:00
|
|
|
"github.com/docker/docker/distribution"
|
2016-12-12 18:05:53 -05:00
|
|
|
progressutils "github.com/docker/docker/distribution/utils"
|
2016-04-07 17:29:18 -04:00
|
|
|
"github.com/docker/docker/pkg/progress"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PushImage initiates a push operation on the repository named localName.
|
2018-02-07 15:52:47 -05:00
|
|
|
func (i *ImageService) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
|
2017-01-25 19:54:18 -05:00
|
|
|
ref, err := reference.ParseNormalizedNamed(image)
|
2016-04-07 17:29:18 -04:00
|
|
|
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() {
|
2016-12-12 18:05:53 -05:00
|
|
|
progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan)
|
2016-04-07 17:29:18 -04:00
|
|
|
close(writesDone)
|
|
|
|
}()
|
|
|
|
|
|
|
|
imagePushConfig := &distribution.ImagePushConfig{
|
2016-12-16 14:19:05 -05:00
|
|
|
Config: distribution.Config{
|
|
|
|
MetaHeaders: metaHeaders,
|
|
|
|
AuthConfig: authConfig,
|
|
|
|
ProgressOutput: progress.ChanOutput(progressChan),
|
2018-02-02 17:18:46 -05:00
|
|
|
RegistryService: i.registryService,
|
|
|
|
ImageEventLogger: i.LogImageEvent,
|
|
|
|
MetadataStore: i.distributionMetadataStore,
|
|
|
|
ImageStore: distribution.NewImageConfigStoreFromStore(i.imageStore),
|
|
|
|
ReferenceStore: i.referenceStore,
|
2016-12-16 14:19:05 -05:00
|
|
|
},
|
|
|
|
ConfigMediaType: schema2.MediaTypeImageConfig,
|
2018-02-02 17:18:46 -05:00
|
|
|
LayerStores: distribution.NewLayerProvidersFromStores(i.layerStores),
|
|
|
|
TrustKey: i.trustKey,
|
|
|
|
UploadManager: i.uploadManager,
|
2016-04-07 17:29:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = distribution.Push(ctx, ref, imagePushConfig)
|
|
|
|
close(progressChan)
|
|
|
|
<-writesDone
|
|
|
|
return err
|
|
|
|
}
|