Merge pull request #5877 from thaJeztah/remove_redundant_ParseRepositoryInfo
cli/command/manifest: remove redundant uses of ParseRepositoryInfo
This commit is contained in:
commit
3f154adf70
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/manifest/store"
|
"github.com/docker/cli/cli/manifest/store"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -42,11 +41,6 @@ func createManifestList(ctx context.Context, dockerCLI command.Cli, args []strin
|
|||||||
return errors.Wrapf(err, "error parsing name for manifest list %s", newRef)
|
return errors.Wrapf(err, "error parsing name for manifest list %s", newRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = registry.ParseRepositoryInfo(targetRef)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "error parsing repository name for manifest list %s", newRef)
|
|
||||||
}
|
|
||||||
|
|
||||||
manifestStore := dockerCLI.ManifestStore()
|
manifestStore := dockerCLI.ManifestStore()
|
||||||
_, err = manifestStore.GetList(targetRef)
|
_, err = manifestStore.GetList(targetRef)
|
||||||
switch {
|
switch {
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/manifest/types"
|
"github.com/docker/cli/cli/manifest/types"
|
||||||
"github.com/docker/distribution/manifest/manifestlist"
|
"github.com/docker/distribution/manifest/manifestlist"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -113,10 +112,7 @@ func printManifest(dockerCli command.Cli, manifest types.ImageManifest, opts ins
|
|||||||
|
|
||||||
func printManifestList(dockerCli command.Cli, namedRef reference.Named, list []types.ImageManifest, opts inspectOptions) error {
|
func printManifestList(dockerCli command.Cli, namedRef reference.Named, list []types.ImageManifest, opts inspectOptions) error {
|
||||||
if !opts.verbose {
|
if !opts.verbose {
|
||||||
targetRepo, err := registry.ParseRepositoryInfo(namedRef)
|
targetRepo := reference.TrimNamed(namedRef)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
manifests := []manifestlist.ManifestDescriptor{}
|
manifests := []manifestlist.ManifestDescriptor{}
|
||||||
// More than one response. This is a manifest list.
|
// More than one response. This is a manifest list.
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/docker/distribution/manifest/manifestlist"
|
"github.com/docker/distribution/manifest/manifestlist"
|
||||||
"github.com/docker/distribution/manifest/ocischema"
|
"github.com/docker/distribution/manifest/ocischema"
|
||||||
"github.com/docker/distribution/manifest/schema2"
|
"github.com/docker/distribution/manifest/schema2"
|
||||||
"github.com/docker/docker/registry"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -100,11 +99,7 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named
|
|||||||
return req, err
|
return req, err
|
||||||
}
|
}
|
||||||
|
|
||||||
targetRepo, err := registry.ParseRepositoryInfo(targetRef)
|
targetRepoName, err := registryclient.RepoNameForReference(targetRef)
|
||||||
if err != nil {
|
|
||||||
return req, err
|
|
||||||
}
|
|
||||||
targetRepoName, err := registryclient.RepoNameForReference(targetRepo.Name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return req, err
|
return req, err
|
||||||
}
|
}
|
||||||
@ -134,11 +129,7 @@ func buildPushRequest(manifests []types.ImageManifest, targetRef reference.Named
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildManifestList(manifests []types.ImageManifest, targetRef reference.Named) (*manifestlist.DeserializedManifestList, error) {
|
func buildManifestList(manifests []types.ImageManifest, targetRef reference.Named) (*manifestlist.DeserializedManifestList, error) {
|
||||||
targetRepoInfo, err := registry.ParseRepositoryInfo(targetRef)
|
targetRepo := reference.TrimNamed(targetRef)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
descriptors := []manifestlist.ManifestDescriptor{}
|
descriptors := []manifestlist.ManifestDescriptor{}
|
||||||
for _, imageManifest := range manifests {
|
for _, imageManifest := range manifests {
|
||||||
if imageManifest.Descriptor.Platform == nil ||
|
if imageManifest.Descriptor.Platform == nil ||
|
||||||
@ -147,7 +138,7 @@ func buildManifestList(manifests []types.ImageManifest, targetRef reference.Name
|
|||||||
return nil, errors.Errorf(
|
return nil, errors.Errorf(
|
||||||
"manifest %s must have an OS and Architecture to be pushed to a registry", imageManifest.Ref)
|
"manifest %s must have an OS and Architecture to be pushed to a registry", imageManifest.Ref)
|
||||||
}
|
}
|
||||||
descriptor, err := buildManifestDescriptor(targetRepoInfo, imageManifest)
|
descriptor, err := buildManifestDescriptor(targetRepo, imageManifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -157,14 +148,9 @@ func buildManifestList(manifests []types.ImageManifest, targetRef reference.Name
|
|||||||
return manifestlist.FromDescriptors(descriptors)
|
return manifestlist.FromDescriptors(descriptors)
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildManifestDescriptor(targetRepo *registry.RepositoryInfo, imageManifest types.ImageManifest) (manifestlist.ManifestDescriptor, error) {
|
func buildManifestDescriptor(targetRepo reference.Named, imageManifest types.ImageManifest) (manifestlist.ManifestDescriptor, error) {
|
||||||
repoInfo, err := registry.ParseRepositoryInfo(imageManifest.Ref)
|
manifestRepoHostname := reference.Domain(reference.TrimNamed(imageManifest.Ref))
|
||||||
if err != nil {
|
targetRepoHostname := reference.Domain(reference.TrimNamed(targetRepo))
|
||||||
return manifestlist.ManifestDescriptor{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
manifestRepoHostname := reference.Domain(repoInfo.Name)
|
|
||||||
targetRepoHostname := reference.Domain(targetRepo.Name)
|
|
||||||
if manifestRepoHostname != targetRepoHostname {
|
if manifestRepoHostname != targetRepoHostname {
|
||||||
return manifestlist.ManifestDescriptor{}, errors.Errorf("cannot use source images from a different registry than the target image: %s != %s", manifestRepoHostname, targetRepoHostname)
|
return manifestlist.ManifestDescriptor{}, errors.Errorf("cannot use source images from a different registry than the target image: %s != %s", manifestRepoHostname, targetRepoHostname)
|
||||||
}
|
}
|
||||||
@ -182,7 +168,7 @@ func buildManifestDescriptor(targetRepo *registry.RepositoryInfo, imageManifest
|
|||||||
manifest.Platform = *platform
|
manifest.Platform = *platform
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = manifest.Descriptor.Digest.Validate(); err != nil {
|
if err := manifest.Descriptor.Digest.Validate(); err != nil {
|
||||||
return manifestlist.ManifestDescriptor{}, errors.Wrapf(err,
|
return manifestlist.ManifestDescriptor{}, errors.Wrapf(err,
|
||||||
"digest parse of image %q failed", imageManifest.Ref)
|
"digest parse of image %q failed", imageManifest.Ref)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user