2018-02-07 20:52:47 +00:00
|
|
|
package images // import "github.com/docker/docker/daemon/images"
|
2016-04-07 21:29:18 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-04-07 21:29:18 +00:00
|
|
|
"io"
|
2018-06-07 22:26:07 +00:00
|
|
|
"time"
|
2016-04-07 21:29:18 +00:00
|
|
|
|
2023-08-30 16:31:46 +00:00
|
|
|
"github.com/distribution/reference"
|
2016-12-16 19:19:05 +00:00
|
|
|
"github.com/docker/distribution/manifest/schema2"
|
2022-03-03 09:28:39 +00:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2016-04-07 21:29:18 +00:00
|
|
|
"github.com/docker/docker/distribution"
|
2016-12-12 23:05:53 +00:00
|
|
|
progressutils "github.com/docker/docker/distribution/utils"
|
2016-04-07 21:29:18 +00:00
|
|
|
"github.com/docker/docker/pkg/progress"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PushImage initiates a push operation on the repository named localName.
|
2023-02-07 13:02:20 +00:00
|
|
|
func (i *ImageService) PushImage(ctx context.Context, ref reference.Named, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error {
|
2018-06-07 22:26:07 +00:00
|
|
|
start := time.Now()
|
2016-04-07 21:29:18 +00:00
|
|
|
// 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 23:05:53 +00:00
|
|
|
progressutils.WriteDistributionProgress(cancelFunc, outStream, progressChan)
|
2016-04-07 21:29:18 +00:00
|
|
|
close(writesDone)
|
|
|
|
}()
|
|
|
|
|
|
|
|
imagePushConfig := &distribution.ImagePushConfig{
|
2016-12-16 19:19:05 +00:00
|
|
|
Config: distribution.Config{
|
|
|
|
MetaHeaders: metaHeaders,
|
|
|
|
AuthConfig: authConfig,
|
|
|
|
ProgressOutput: progress.ChanOutput(progressChan),
|
2018-02-02 22:18:46 +00:00
|
|
|
RegistryService: i.registryService,
|
|
|
|
ImageEventLogger: i.LogImageEvent,
|
|
|
|
MetadataStore: i.distributionMetadataStore,
|
|
|
|
ImageStore: distribution.NewImageConfigStoreFromStore(i.imageStore),
|
|
|
|
ReferenceStore: i.referenceStore,
|
2016-12-16 19:19:05 +00:00
|
|
|
},
|
|
|
|
ConfigMediaType: schema2.MediaTypeImageConfig,
|
2021-03-19 14:34:08 +00:00
|
|
|
LayerStores: distribution.NewLayerProvidersFromStore(i.layerStore),
|
2018-02-02 22:18:46 +00:00
|
|
|
UploadManager: i.uploadManager,
|
2016-04-07 21:29:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 13:02:20 +00:00
|
|
|
err := distribution.Push(ctx, ref, imagePushConfig)
|
2016-04-07 21:29:18 +00:00
|
|
|
close(progressChan)
|
|
|
|
<-writesDone
|
2024-03-12 14:46:12 +00:00
|
|
|
ImageActions.WithValues("push").UpdateSince(start)
|
2016-04-07 21:29:18 +00:00
|
|
|
return err
|
|
|
|
}
|