mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <github@gone.nl>
This commit is contained in:
parent
566c8db66d
commit
2b0da89366
4 changed files with 39 additions and 44 deletions
|
@ -6,28 +6,12 @@ import (
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/api"
|
"github.com/docker/docker/api"
|
||||||
"github.com/docker/docker/distribution/metadata"
|
|
||||||
"github.com/docker/docker/pkg/progress"
|
|
||||||
refstore "github.com/docker/docker/reference"
|
refstore "github.com/docker/docker/reference"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"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
|
// 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.
|
// 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 {
|
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)
|
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.
|
// validateRepoName validates the name of a repository.
|
||||||
func validateRepoName(name reference.Named) error {
|
func validateRepoName(name reference.Named) error {
|
||||||
if reference.FamiliarName(name) == api.NoBaseImageSpecifier {
|
if reference.FamiliarName(name) == api.NoBaseImageSpecifier {
|
||||||
|
|
|
@ -52,6 +52,19 @@ func (e imageConfigPullError) Error() string {
|
||||||
return "error pulling image configuration: " + e.Err.Error()
|
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 {
|
type puller struct {
|
||||||
metadataService metadata.V2MetadataService
|
metadataService metadata.V2MetadataService
|
||||||
endpoint registry.APIEndpoint
|
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
|
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 {
|
type layerDescriptor struct {
|
||||||
digest digest.Digest
|
digest digest.Digest
|
||||||
diffID layer.DiffID
|
diffID layer.DiffID
|
||||||
|
|
|
@ -8,27 +8,12 @@ import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/docker/docker/distribution/metadata"
|
|
||||||
"github.com/docker/docker/pkg/progress"
|
"github.com/docker/docker/pkg/progress"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const compressionBufSize = 32768
|
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
|
// 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.
|
// image to push. If no tag is provided, all tags are pushed.
|
||||||
func Push(ctx context.Context, ref reference.Named, config *ImagePushConfig) error {
|
func Push(ctx context.Context, ref reference.Named, config *ImagePushConfig) error {
|
||||||
|
|
|
@ -34,6 +34,19 @@ const (
|
||||||
middleLayerMaximumSize = 10 * (1 << 20) // 10MB
|
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 {
|
type pusher struct {
|
||||||
metadataService metadata.V2MetadataService
|
metadataService metadata.V2MetadataService
|
||||||
ref reference.Named
|
ref reference.Named
|
||||||
|
|
Loading…
Add table
Reference in a new issue