image_push.go 2.2 KB

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