cli/command: internalize constructing RegistryClient
The CLI.RegistryClient method is a shallow wrapper around registryclient.NewRegistryClient but due to its signature resulted in various dependencies becoming a dependency of the "command" package. Consequence of this was that cli-plugins, which need the cli/command package, would also get those dependencies. This patch inlines the code where needed, skipping the wrapper Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
3b5dff2783
commit
985b58e7e1
@ -1,6 +1,7 @@
|
|||||||
package manifest
|
package manifest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -8,6 +9,8 @@ import (
|
|||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/cli/config"
|
"github.com/docker/cli/cli/config"
|
||||||
"github.com/docker/cli/cli/manifest/store"
|
"github.com/docker/cli/cli/manifest/store"
|
||||||
|
registryclient "github.com/docker/cli/cli/registry/client"
|
||||||
|
"github.com/docker/docker/api/types/registry"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -27,6 +30,7 @@ type annotateOptions struct {
|
|||||||
type manifestStoreProvider interface {
|
type manifestStoreProvider interface {
|
||||||
// ManifestStore returns a store for local manifests
|
// ManifestStore returns a store for local manifests
|
||||||
ManifestStore() store.Store
|
ManifestStore() store.Store
|
||||||
|
RegistryClient(bool) registryclient.RegistryClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// newManifestStore returns a store for local manifests
|
// newManifestStore returns a store for local manifests
|
||||||
@ -40,6 +44,19 @@ func newManifestStore(dockerCLI command.Cli) store.Store {
|
|||||||
return store.NewStore(filepath.Join(config.Dir(), "manifests"))
|
return store.NewStore(filepath.Join(config.Dir(), "manifests"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newRegistryClient returns a client for communicating with a Docker distribution
|
||||||
|
// registry
|
||||||
|
func newRegistryClient(dockerCLI command.Cli, allowInsecure bool) registryclient.RegistryClient {
|
||||||
|
if msp, ok := dockerCLI.(manifestStoreProvider); ok {
|
||||||
|
// manifestStoreProvider is used in tests to provide a dummy store.
|
||||||
|
return msp.RegistryClient(allowInsecure)
|
||||||
|
}
|
||||||
|
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
|
||||||
|
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
|
||||||
|
}
|
||||||
|
return registryclient.NewRegistryClient(resolver, command.UserAgent(), allowInsecure)
|
||||||
|
}
|
||||||
|
|
||||||
// NewAnnotateCommand creates a new `docker manifest annotate` command
|
// NewAnnotateCommand creates a new `docker manifest annotate` command
|
||||||
func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
|
func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
var opts annotateOptions
|
var opts annotateOptions
|
||||||
|
@ -75,7 +75,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Next try a remote manifest
|
// Next try a remote manifest
|
||||||
registryClient := dockerCli.RegistryClient(opts.insecure)
|
registryClient := newRegistryClient(dockerCli, opts.insecure)
|
||||||
imageManifest, err := registryClient.GetManifest(ctx, namedRef)
|
imageManifest, err := registryClient.GetManifest(ctx, namedRef)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return printManifest(dockerCli, imageManifest, opts)
|
return printManifest(dockerCli, imageManifest, opts)
|
||||||
|
@ -248,7 +248,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pushList(ctx context.Context, dockerCLI command.Cli, req pushRequest) error {
|
func pushList(ctx context.Context, dockerCLI command.Cli, req pushRequest) error {
|
||||||
rclient := dockerCLI.RegistryClient(req.insecure)
|
rclient := newRegistryClient(dockerCLI, req.insecure)
|
||||||
|
|
||||||
if err := mountBlobs(ctx, rclient, req.targetRef, req.manifestBlobs); err != nil {
|
if err := mountBlobs(ctx, rclient, req.targetRef, req.manifestBlobs); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -69,15 +69,15 @@ func normalizeReference(ref string) (reference.Named, error) {
|
|||||||
|
|
||||||
// getManifest from the local store, and fallback to the remote registry if it
|
// getManifest from the local store, and fallback to the remote registry if it
|
||||||
// doesn't exist locally
|
// doesn't exist locally
|
||||||
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
|
func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
|
||||||
data, err := newManifestStore(dockerCli).Get(listRef, namedRef)
|
data, err := newManifestStore(dockerCLI).Get(listRef, namedRef)
|
||||||
switch {
|
switch {
|
||||||
case store.IsNotFound(err):
|
case store.IsNotFound(err):
|
||||||
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
|
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return types.ImageManifest{}, err
|
return types.ImageManifest{}, err
|
||||||
case len(data.Raw) == 0:
|
case len(data.Raw) == 0:
|
||||||
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
|
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
|
||||||
default:
|
default:
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user