Skip to content

Commit ea1f10b

Browse files
authored
Merge pull request #5889 from thaJeztah/internalize_manifest
cli/command: deprecate Cli.ManifestStore, Cli.RegistryClient
2 parents 7bcbe08 + 8ad0721 commit ea1f10b

8 files changed

Lines changed: 89 additions & 35 deletions

File tree

cli/command/cli.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"io"
1010
"os"
11-
"path/filepath"
1211
"runtime"
1312
"strconv"
1413
"sync"
@@ -21,14 +20,11 @@ import (
2120
"github.com/docker/cli/cli/context/store"
2221
"github.com/docker/cli/cli/debug"
2322
cliflags "github.com/docker/cli/cli/flags"
24-
manifeststore "github.com/docker/cli/cli/manifest/store"
25-
registryclient "github.com/docker/cli/cli/registry/client"
2623
"github.com/docker/cli/cli/streams"
2724
"github.com/docker/cli/cli/version"
2825
dopts "github.com/docker/cli/opts"
2926
"github.com/docker/docker/api"
3027
"github.com/docker/docker/api/types"
31-
"github.com/docker/docker/api/types/registry"
3228
"github.com/docker/docker/api/types/swarm"
3329
"github.com/docker/docker/client"
3430
"github.com/pkg/errors"
@@ -54,15 +50,14 @@ type Cli interface {
5450
ServerInfo() ServerInfo
5551
DefaultVersion() string
5652
CurrentVersion() string
57-
ManifestStore() manifeststore.Store
58-
RegistryClient(bool) registryclient.RegistryClient
5953
ContentTrustEnabled() bool
6054
BuildKitEnabled() (bool, error)
6155
ContextStore() store.Store
6256
CurrentContext() string
6357
DockerEndpoint() docker.Endpoint
6458
TelemetryClient
6559
DeprecatedNotaryClient
60+
DeprecatedManifestClient
6661
}
6762

6863
// DockerCli is an instance the docker command line client.
@@ -227,21 +222,6 @@ func (cli *DockerCli) HooksEnabled() bool {
227222
return false
228223
}
229224

230-
// ManifestStore returns a store for local manifests
231-
func (*DockerCli) ManifestStore() manifeststore.Store {
232-
// TODO: support override default location from config file
233-
return manifeststore.NewStore(filepath.Join(config.Dir(), "manifests"))
234-
}
235-
236-
// RegistryClient returns a client for communicating with a Docker distribution
237-
// registry
238-
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient {
239-
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
240-
return ResolveAuthConfig(cli.ConfigFile(), index)
241-
}
242-
return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure)
243-
}
244-
245225
// WithInitializeClient is passed to DockerCli.Initialize by callers who wish to set a particular API Client for use by the CLI.
246226
func WithInitializeClient(makeClient func(dockerCli *DockerCli) (client.APIClient, error)) CLIOption {
247227
return func(dockerCli *DockerCli) error {

cli/command/cli_deprecated.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package command
22

33
import (
4+
"context"
5+
"path/filepath"
6+
7+
"github.com/docker/cli/cli/config"
8+
manifeststore "github.com/docker/cli/cli/manifest/store"
9+
registryclient "github.com/docker/cli/cli/registry/client"
410
"github.com/docker/cli/cli/trust"
11+
"github.com/docker/docker/api/types/registry"
512
notaryclient "github.com/theupdateframework/notary/client"
613
)
714

@@ -12,7 +19,38 @@ type DeprecatedNotaryClient interface {
1219
NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
1320
}
1421

22+
type DeprecatedManifestClient interface {
23+
// ManifestStore returns a store for local manifests
24+
//
25+
// Deprecated: use [manifeststore.NewStore] instead. This method is no longer used and will be removed in the next release.
26+
ManifestStore() manifeststore.Store
27+
28+
// RegistryClient returns a client for communicating with a Docker distribution
29+
// registry.
30+
//
31+
// Deprecated: use [registryclient.NewRegistryClient]. This method is no longer used and will be removed in the next release.
32+
RegistryClient(bool) registryclient.RegistryClient
33+
}
34+
1535
// NotaryClient provides a Notary Repository to interact with signed metadata for an image
1636
func (cli *DockerCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error) {
1737
return trust.GetNotaryRepository(cli.In(), cli.Out(), UserAgent(), imgRefAndAuth.RepoInfo(), imgRefAndAuth.AuthConfig(), actions...)
1838
}
39+
40+
// ManifestStore returns a store for local manifests
41+
//
42+
// Deprecated: use [manifeststore.NewStore] instead. This method is no longer used and will be removed in the next release.
43+
func (*DockerCli) ManifestStore() manifeststore.Store {
44+
return manifeststore.NewStore(filepath.Join(config.Dir(), "manifests"))
45+
}
46+
47+
// RegistryClient returns a client for communicating with a Docker distribution
48+
// registry
49+
//
50+
// Deprecated: use [registryclient.NewRegistryClient]. This method is no longer used and will be removed in the next release.
51+
func (cli *DockerCli) RegistryClient(allowInsecure bool) registryclient.RegistryClient {
52+
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
53+
return ResolveAuthConfig(cli.ConfigFile(), index)
54+
}
55+
return registryclient.NewRegistryClient(resolver, UserAgent(), allowInsecure)
56+
}

cli/command/manifest/annotate.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package manifest
22

33
import (
4+
"context"
45
"fmt"
6+
"path/filepath"
57

68
"github.com/docker/cli/cli"
79
"github.com/docker/cli/cli/command"
10+
"github.com/docker/cli/cli/config"
811
"github.com/docker/cli/cli/manifest/store"
12+
registryclient "github.com/docker/cli/cli/registry/client"
13+
"github.com/docker/docker/api/types/registry"
914
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1015
"github.com/pkg/errors"
1116
"github.com/spf13/cobra"
@@ -21,6 +26,37 @@ type annotateOptions struct {
2126
osVersion string
2227
}
2328

29+
// manifestStoreProvider is used in tests to provide a dummy store.
30+
type manifestStoreProvider interface {
31+
// ManifestStore returns a store for local manifests
32+
ManifestStore() store.Store
33+
RegistryClient(bool) registryclient.RegistryClient
34+
}
35+
36+
// newManifestStore returns a store for local manifests
37+
func newManifestStore(dockerCLI command.Cli) store.Store {
38+
if msp, ok := dockerCLI.(manifestStoreProvider); ok {
39+
// manifestStoreProvider is used in tests to provide a dummy store.
40+
return msp.ManifestStore()
41+
}
42+
43+
// TODO: support override default location from config file
44+
return store.NewStore(filepath.Join(config.Dir(), "manifests"))
45+
}
46+
47+
// newRegistryClient returns a client for communicating with a Docker distribution
48+
// registry
49+
func newRegistryClient(dockerCLI command.Cli, allowInsecure bool) registryclient.RegistryClient {
50+
if msp, ok := dockerCLI.(manifestStoreProvider); ok {
51+
// manifestStoreProvider is used in tests to provide a dummy store.
52+
return msp.RegistryClient(allowInsecure)
53+
}
54+
resolver := func(ctx context.Context, index *registry.IndexInfo) registry.AuthConfig {
55+
return command.ResolveAuthConfig(dockerCLI.ConfigFile(), index)
56+
}
57+
return registryclient.NewRegistryClient(resolver, command.UserAgent(), allowInsecure)
58+
}
59+
2460
// NewAnnotateCommand creates a new `docker manifest annotate` command
2561
func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
2662
var opts annotateOptions
@@ -47,7 +83,7 @@ func newAnnotateCommand(dockerCli command.Cli) *cobra.Command {
4783
return cmd
4884
}
4985

50-
func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error {
86+
func runManifestAnnotate(dockerCLI command.Cli, opts annotateOptions) error {
5187
targetRef, err := normalizeReference(opts.target)
5288
if err != nil {
5389
return errors.Wrapf(err, "annotate: error parsing name for manifest list %s", opts.target)
@@ -57,7 +93,7 @@ func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error {
5793
return errors.Wrapf(err, "annotate: error parsing name for manifest %s", opts.image)
5894
}
5995

60-
manifestStore := dockerCli.ManifestStore()
96+
manifestStore := newManifestStore(dockerCLI)
6197
imageManifest, err := manifestStore.Get(targetRef, imgRef)
6298
switch {
6399
case store.IsNotFound(err):

cli/command/manifest/create_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func createManifestList(ctx context.Context, dockerCLI command.Cli, args []strin
4141
return errors.Wrapf(err, "error parsing name for manifest list %s", newRef)
4242
}
4343

44-
manifestStore := dockerCLI.ManifestStore()
44+
manifestStore := newManifestStore(dockerCLI)
4545
_, err = manifestStore.GetList(targetRef)
4646
switch {
4747
case store.IsNotFound(err):

cli/command/manifest/inspect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
6161
return err
6262
}
6363

64-
imageManifest, err := dockerCli.ManifestStore().Get(listRef, namedRef)
64+
imageManifest, err := newManifestStore(dockerCli).Get(listRef, namedRef)
6565
if err != nil {
6666
return err
6767
}
6868
return printManifest(dockerCli, imageManifest, opts)
6969
}
7070

7171
// Try a local manifest list first
72-
localManifestList, err := dockerCli.ManifestStore().GetList(namedRef)
72+
localManifestList, err := newManifestStore(dockerCli).GetList(namedRef)
7373
if err == nil {
7474
return printManifestList(dockerCli, namedRef, localManifestList, opts)
7575
}
7676

7777
// Next try a remote manifest
78-
registryClient := dockerCli.RegistryClient(opts.insecure)
78+
registryClient := newRegistryClient(dockerCli, opts.insecure)
7979
imageManifest, err := registryClient.GetManifest(ctx, namedRef)
8080
if err == nil {
8181
return printManifest(dockerCli, imageManifest, opts)

cli/command/manifest/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOpts) error {
6868
return err
6969
}
7070

71-
manifests, err := dockerCli.ManifestStore().GetList(targetRef)
71+
manifests, err := newManifestStore(dockerCli).GetList(targetRef)
7272
if err != nil {
7373
return err
7474
}
@@ -85,7 +85,7 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOpts) error {
8585
return err
8686
}
8787
if opts.purge {
88-
return dockerCli.ManifestStore().Remove(targetRef)
88+
return newManifestStore(dockerCli).Remove(targetRef)
8989
}
9090
return nil
9191
}
@@ -248,7 +248,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere
248248
}
249249

250250
func pushList(ctx context.Context, dockerCLI command.Cli, req pushRequest) error {
251-
rclient := dockerCLI.RegistryClient(req.insecure)
251+
rclient := newRegistryClient(dockerCLI, req.insecure)
252252

253253
if err := mountBlobs(ctx, rclient, req.targetRef, req.manifestBlobs); err != nil {
254254
return err

cli/command/manifest/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func newRmManifestListCommand(dockerCLI command.Cli) *cobra.Command {
1616
Short: "Delete one or more manifest lists from local storage",
1717
Args: cli.RequiresMinArgs(1),
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
return runRemove(cmd.Context(), dockerCLI.ManifestStore(), args)
19+
return runRemove(cmd.Context(), newManifestStore(dockerCLI), args)
2020
},
2121
}
2222

cli/command/manifest/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ func normalizeReference(ref string) (reference.Named, error) {
6969

7070
// getManifest from the local store, and fallback to the remote registry if it
7171
// doesn't exist locally
72-
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
73-
data, err := dockerCli.ManifestStore().Get(listRef, namedRef)
72+
func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
73+
data, err := newManifestStore(dockerCLI).Get(listRef, namedRef)
7474
switch {
7575
case store.IsNotFound(err):
76-
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
76+
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
7777
case err != nil:
7878
return types.ImageManifest{}, err
7979
case len(data.Raw) == 0:
80-
return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef)
80+
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
8181
default:
8282
return data, nil
8383
}

0 commit comments

Comments
 (0)