image_push.go 1.9 KB

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