From 2b0da893660089b72d9a99c8f72f6f80cc7d6e09 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 27 Feb 2022 23:45:22 +0100 Subject: [PATCH] distribution: move newPusher() and newPuller() together with definition Also moving writeStatus() to the puller, which is where it's used, and makes it slightly easier to consume. Signed-off-by: Sebastiaan van Stijn --- distribution/pull.go | 28 ---------------------------- distribution/pull_v2.go | 27 ++++++++++++++++++++++++++- distribution/push.go | 15 --------------- distribution/push_v2.go | 13 +++++++++++++ 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/distribution/pull.go b/distribution/pull.go index cb60f62b6f..7780ea4c43 100644 --- a/distribution/pull.go +++ b/distribution/pull.go @@ -6,28 +6,12 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api" - "github.com/docker/docker/distribution/metadata" - "github.com/docker/docker/pkg/progress" refstore "github.com/docker/docker/reference" - "github.com/docker/docker/registry" "github.com/opencontainers/go-digest" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) -// newPuller returns a puller to pull from a v2 registry. -func newPuller(endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, config *ImagePullConfig, local ContentStore) *puller { - return &puller{ - metadataService: metadata.NewV2MetadataService(config.MetadataStore), - endpoint: endpoint, - config: config, - repoInfo: repoInfo, - manifestStore: &manifestStore{ - local: local, - }, - } -} - // Pull initiates a pull operation. image is the repository name to pull, and // tag may be either empty, or indicate a specific tag to pull. func Pull(ctx context.Context, ref reference.Named, config *ImagePullConfig, local ContentStore) error { @@ -100,18 +84,6 @@ func Pull(ctx context.Context, ref reference.Named, config *ImagePullConfig, loc return translatePullError(lastErr, ref) } -// writeStatus writes a status message to out. If layersDownloaded is true, the -// status message indicates that a newer image was downloaded. Otherwise, it -// indicates that the image is up to date. requestedTag is the tag the message -// will refer to. -func writeStatus(requestedTag string, out progress.Output, layersDownloaded bool) { - if layersDownloaded { - progress.Message(out, "", "Status: Downloaded newer image for "+requestedTag) - } else { - progress.Message(out, "", "Status: Image is up to date for "+requestedTag) - } -} - // validateRepoName validates the name of a repository. func validateRepoName(name reference.Named) error { if reference.FamiliarName(name) == api.NoBaseImageSpecifier { diff --git a/distribution/pull_v2.go b/distribution/pull_v2.go index 37ced60d43..f4a55f83e7 100644 --- a/distribution/pull_v2.go +++ b/distribution/pull_v2.go @@ -52,6 +52,19 @@ func (e imageConfigPullError) Error() string { return "error pulling image configuration: " + e.Err.Error() } +// newPuller returns a puller to pull from a v2 registry. +func newPuller(endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, config *ImagePullConfig, local ContentStore) *puller { + return &puller{ + metadataService: metadata.NewV2MetadataService(config.MetadataStore), + endpoint: endpoint, + config: config, + repoInfo: repoInfo, + manifestStore: &manifestStore{ + local: local, + }, + } +} + type puller struct { metadataService metadata.V2MetadataService endpoint registry.APIEndpoint @@ -122,11 +135,23 @@ func (p *puller) pullRepository(ctx context.Context, ref reference.Named) (err e } } - writeStatus(reference.FamiliarString(ref), p.config.ProgressOutput, layersDownloaded) + p.writeStatus(reference.FamiliarString(ref), layersDownloaded) return nil } +// writeStatus writes a status message to out. If layersDownloaded is true, the +// status message indicates that a newer image was downloaded. Otherwise, it +// indicates that the image is up to date. requestedTag is the tag the message +// will refer to. +func (p *puller) writeStatus(requestedTag string, layersDownloaded bool) { + if layersDownloaded { + progress.Message(p.config.ProgressOutput, "", "Status: Downloaded newer image for "+requestedTag) + } else { + progress.Message(p.config.ProgressOutput, "", "Status: Image is up to date for "+requestedTag) + } +} + type layerDescriptor struct { digest digest.Digest diffID layer.DiffID diff --git a/distribution/push.go b/distribution/push.go index 026c29f726..808c5ec316 100644 --- a/distribution/push.go +++ b/distribution/push.go @@ -8,27 +8,12 @@ import ( "io" "github.com/docker/distribution/reference" - "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/pkg/progress" - "github.com/docker/docker/registry" "github.com/sirupsen/logrus" ) const compressionBufSize = 32768 -// newPusher creates a new pusher for pushing to a v2 registry. -// The parameters are passed through to the underlying pusher implementation for -// use during the actual push operation. -func newPusher(ref reference.Named, endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, config *ImagePushConfig) *pusher { - return &pusher{ - metadataService: metadata.NewV2MetadataService(config.MetadataStore), - ref: ref, - endpoint: endpoint, - repoInfo: repoInfo, - config: config, - } -} - // Push initiates a push operation on ref. ref is the specific variant of the // image to push. If no tag is provided, all tags are pushed. func Push(ctx context.Context, ref reference.Named, config *ImagePushConfig) error { diff --git a/distribution/push_v2.go b/distribution/push_v2.go index f5168f836b..910123250c 100644 --- a/distribution/push_v2.go +++ b/distribution/push_v2.go @@ -34,6 +34,19 @@ const ( middleLayerMaximumSize = 10 * (1 << 20) // 10MB ) +// newPusher creates a new pusher for pushing to a v2 registry. +// The parameters are passed through to the underlying pusher implementation for +// use during the actual push operation. +func newPusher(ref reference.Named, endpoint registry.APIEndpoint, repoInfo *registry.RepositoryInfo, config *ImagePushConfig) *pusher { + return &pusher{ + metadataService: metadata.NewV2MetadataService(config.MetadataStore), + ref: ref, + endpoint: endpoint, + repoInfo: repoInfo, + config: config, + } +} + type pusher struct { metadataService metadata.V2MetadataService ref reference.Named