From b194274bebb91eb52ac0fe2ece16c5eef3c922f4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 3 Jul 2024 15:35:44 +0200 Subject: [PATCH] replace uses of deprecated API types Signed-off-by: Sebastiaan van Stijn --- cli/command/completion/functions.go | 3 +- cli/command/container/attach.go | 5 +- cli/command/container/attach_test.go | 31 ++++---- cli/command/container/client_test.go | 12 +-- cli/command/container/exec.go | 3 +- cli/command/container/exec_test.go | 10 +-- cli/command/container/list_test.go | 33 ++++---- cli/command/container/logs_test.go | 7 +- cli/command/container/pause.go | 4 +- cli/command/container/port_test.go | 6 +- cli/command/container/start.go | 3 +- cli/command/container/unpause.go | 4 +- cli/command/formatter/container.go | 10 +-- cli/command/formatter/container_test.go | 96 ++++++++++++------------ cli/command/formatter/disk_usage.go | 15 ++-- cli/command/image/client_test.go | 6 +- cli/command/image/inspect_test.go | 16 ++-- cli/command/network/disconnect.go | 10 +-- cli/command/trust/inspect_pretty_test.go | 5 +- internal/test/builders/container.go | 34 ++++----- 20 files changed, 153 insertions(+), 160 deletions(-) diff --git a/cli/command/completion/functions.go b/cli/command/completion/functions.go index 6026ef7692..ac2335d9ac 100644 --- a/cli/command/completion/functions.go +++ b/cli/command/completion/functions.go @@ -4,7 +4,6 @@ import ( "os" "github.com/docker/cli/cli/command/formatter" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/network" @@ -44,7 +43,7 @@ func ImageNames(dockerCLI APIClientProvider) ValidArgsFn { // ContainerNames offers completion for container names and IDs // By default, only names are returned. // Set DOCKER_COMPLETION_SHOW_CONTAINER_IDS=yes to also complete IDs. -func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(types.Container) bool) ValidArgsFn { +func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(container.Summary) bool) ValidArgsFn { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { list, err := dockerCLI.Client().ContainerList(cmd.Context(), container.ListOptions{ All: all, diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index a2d9838683..a54e8fb530 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -7,7 +7,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/moby/sys/signal" @@ -23,7 +22,7 @@ type AttachOptions struct { DetachKeys string } -func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*types.ContainerJSON, error) { +func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*container.InspectResponse, error) { c, err := apiClient.ContainerInspect(ctx, args) if err != nil { return nil, err @@ -56,7 +55,7 @@ func NewAttachCommand(dockerCLI command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container attach, docker attach", }, - ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr types.Container) bool { + ValidArgsFunction: completion.ContainerNames(dockerCLI, false, func(ctr container.Summary) bool { return ctr.State != "paused" }), } diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index 69332fc6bc..33aa4f93e3 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -6,7 +6,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -17,24 +16,24 @@ func TestNewAttachCommandErrors(t *testing.T) { name string args []string expectedError string - containerInspectFunc func(img string) (types.ContainerJSON, error) + containerInspectFunc func(img string) (container.InspectResponse, error) }{ { name: "client-error", args: []string{"5cb5bb5e4a3b"}, expectedError: "something went wrong", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{}, errors.Errorf("something went wrong") + containerInspectFunc: func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{}, errors.Errorf("something went wrong") }, }, { name: "client-stopped", args: []string{"5cb5bb5e4a3b"}, expectedError: "You cannot attach to a stopped container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - State: &types.ContainerState{ + containerInspectFunc: func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{ + ContainerJSONBase: &container.ContainerJSONBase{ + State: &container.State{ Running: false, }, }, @@ -45,10 +44,10 @@ func TestNewAttachCommandErrors(t *testing.T) { name: "client-paused", args: []string{"5cb5bb5e4a3b"}, expectedError: "You cannot attach to a paused container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - State: &types.ContainerState{ + containerInspectFunc: func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{ + ContainerJSONBase: &container.ContainerJSONBase{ + State: &container.State{ Running: true, Paused: true, }, @@ -60,10 +59,10 @@ func TestNewAttachCommandErrors(t *testing.T) { name: "client-restarting", args: []string{"5cb5bb5e4a3b"}, expectedError: "You cannot attach to a restarting container", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{ - ContainerJSONBase: &types.ContainerJSONBase{ - State: &types.ContainerState{ + containerInspectFunc: func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{ + ContainerJSONBase: &container.ContainerJSONBase{ + State: &container.State{ Running: true, Paused: false, Restarting: true, diff --git a/cli/command/container/client_test.go b/cli/command/container/client_test.go index 621acbcdd0..deae11a73b 100644 --- a/cli/command/container/client_test.go +++ b/cli/command/container/client_test.go @@ -16,7 +16,7 @@ import ( type fakeClient struct { client.Client - inspectFunc func(string) (types.ContainerJSON, error) + inspectFunc func(string) (container.InspectResponse, error) execInspectFunc func(execID string) (container.ExecInspect, error) execCreateFunc func(containerID string, options container.ExecOptions) (types.IDResponse, error) createContainerFunc func(config *container.Config, @@ -31,7 +31,7 @@ type fakeClient struct { containerCopyFromFunc func(containerID, srcPath string) (io.ReadCloser, container.PathStat, error) logFunc func(string, container.LogsOptions) (io.ReadCloser, error) waitFunc func(string) (<-chan container.WaitResponse, <-chan error) - containerListFunc func(container.ListOptions) ([]types.Container, error) + containerListFunc func(container.ListOptions) ([]container.Summary, error) containerExportFunc func(string) (io.ReadCloser, error) containerExecResizeFunc func(id string, options container.ResizeOptions) error containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error @@ -41,18 +41,18 @@ type fakeClient struct { Version string } -func (f *fakeClient) ContainerList(_ context.Context, options container.ListOptions) ([]types.Container, error) { +func (f *fakeClient) ContainerList(_ context.Context, options container.ListOptions) ([]container.Summary, error) { if f.containerListFunc != nil { return f.containerListFunc(options) } - return []types.Container{}, nil + return []container.Summary{}, nil } -func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (types.ContainerJSON, error) { +func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (container.InspectResponse, error) { if f.inspectFunc != nil { return f.inspectFunc(containerID) } - return types.ContainerJSON{}, nil + return container.InspectResponse{}, nil } func (f *fakeClient) ContainerExecCreate(_ context.Context, containerID string, config container.ExecOptions) (types.IDResponse, error) { diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index 1c0a741263..a459c01388 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -11,7 +11,6 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/opts" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/pkg/errors" @@ -54,7 +53,7 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command { options.Command = args[1:] return RunExec(cmd.Context(), dockerCli, containerIDorName, options) }, - ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { + ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool { return ctr.State != "paused" }), Annotations: map[string]string{ diff --git a/cli/command/container/exec_test.go b/cli/command/container/exec_test.go index ed34e4777f..89193b29f4 100644 --- a/cli/command/container/exec_test.go +++ b/cli/command/container/exec_test.go @@ -178,8 +178,8 @@ func TestRunExec(t *testing.T) { doc: "inspect error", options: NewExecOptions(), client: &fakeClient{ - inspectFunc: func(string) (types.ContainerJSON, error) { - return types.ContainerJSON{}, errors.New("failed inspect") + inspectFunc: func(string) (container.InspectResponse, error) { + return container.InspectResponse{}, errors.New("failed inspect") }, }, expectedError: "failed inspect", @@ -252,14 +252,14 @@ func TestNewExecCommandErrors(t *testing.T) { name string args []string expectedError string - containerInspectFunc func(img string) (types.ContainerJSON, error) + containerInspectFunc func(img string) (container.InspectResponse, error) }{ { name: "client-error", args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"}, expectedError: "something went wrong", - containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{}, errors.Errorf("something went wrong") + containerInspectFunc: func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{}, errors.Errorf("something went wrong") }, }, } diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index 6bc63b57a6..6d72fbcf7e 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/cli/opts" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -130,7 +129,7 @@ func TestContainerListErrors(t *testing.T) { testCases := []struct { args []string flags map[string]string - containerListFunc func(container.ListOptions) ([]types.Container, error) + containerListFunc func(container.ListOptions) ([]container.Summary, error) expectedError string }{ { @@ -146,7 +145,7 @@ func TestContainerListErrors(t *testing.T) { expectedError: `wrong number of args for join`, }, { - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { return nil, errors.New("error listing containers") }, expectedError: "error listing containers", @@ -170,8 +169,8 @@ func TestContainerListErrors(t *testing.T) { func TestContainerListWithoutFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1"), *builders.Container("c2", builders.WithName("foo")), *builders.Container("c3", builders.WithPort(80, 80, builders.TCP), builders.WithPort(81, 81, builders.TCP), builders.WithPort(82, 82, builders.TCP)), @@ -187,8 +186,8 @@ func TestContainerListWithoutFormat(t *testing.T) { func TestContainerListNoTrunc(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1"), *builders.Container("c2", builders.WithName("foo/bar")), }, nil @@ -203,8 +202,8 @@ func TestContainerListNoTrunc(t *testing.T) { // Test for GitHub issue docker/docker#21772 func TestContainerListNamesMultipleTime(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1"), *builders.Container("c2", builders.WithName("foo/bar")), }, nil @@ -219,8 +218,8 @@ func TestContainerListNamesMultipleTime(t *testing.T) { // Test for GitHub issue docker/docker#30291 func TestContainerListFormatTemplateWithArg(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1", builders.WithLabel("some.label", "value")), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), }, nil @@ -270,9 +269,9 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) { tc := tc t.Run(tc.doc, func(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(options container.ListOptions) ([]types.Container, error) { + containerListFunc: func(options container.ListOptions) ([]container.Summary, error) { assert.Check(t, is.Equal(options.Size, tc.sizeExpected)) - return []types.Container{}, nil + return []container.Summary{}, nil }, }) cmd := newListCommand(cli) @@ -287,8 +286,8 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) { func TestContainerListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1", builders.WithLabel("some.label", "value"), builders.WithSize(10700000)), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar"), builders.WithSize(3200000)), }, nil @@ -304,8 +303,8 @@ func TestContainerListWithConfigFormat(t *testing.T) { func TestContainerListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return []types.Container{ + containerListFunc: func(_ container.ListOptions) ([]container.Summary, error) { + return []container.Summary{ *builders.Container("c1", builders.WithLabel("some.label", "value")), *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), }, nil diff --git a/cli/command/container/logs_test.go b/cli/command/container/logs_test.go index 4a27cfaf5d..452f097b00 100644 --- a/cli/command/container/logs_test.go +++ b/cli/command/container/logs_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -20,10 +19,10 @@ var logFn = func(expectedOut string) func(string, container.LogsOptions) (io.Rea } func TestRunLogs(t *testing.T) { - inspectFn := func(containerID string) (types.ContainerJSON, error) { - return types.ContainerJSON{ + inspectFn := func(containerID string) (container.InspectResponse, error) { + return container.InspectResponse{ Config: &container.Config{Tty: true}, - ContainerJSONBase: &types.ContainerJSONBase{State: &types.ContainerState{Running: false}}, + ContainerJSONBase: &container.ContainerJSONBase{State: &container.State{Running: false}}, }, nil } diff --git a/cli/command/container/pause.go b/cli/command/container/pause.go index 495c1c9f9a..87fb0e10c5 100644 --- a/cli/command/container/pause.go +++ b/cli/command/container/pause.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -32,7 +32,7 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container pause, docker pause", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { + ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool { return ctr.State != "paused" }), } diff --git a/cli/command/container/port_test.go b/cli/command/container/port_test.go index 66e601c543..8502cf761d 100644 --- a/cli/command/container/port_test.go +++ b/cli/command/container/port_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/go-connections/nat" "gotest.tools/v3/assert" "gotest.tools/v3/golden" @@ -46,8 +46,8 @@ func TestNewPortCommandOutput(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - inspectFunc: func(string) (types.ContainerJSON, error) { - ci := types.ContainerJSON{NetworkSettings: &types.NetworkSettings{}} + inspectFunc: func(string) (container.InspectResponse, error) { + ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}} ci.NetworkSettings.Ports = nat.PortMap{ "80/tcp": make([]nat.PortBinding, len(tc.ips)), "443/tcp": make([]nat.PortBinding, len(tc.ips)), diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 7cd6d0e7ce..29aaa988d6 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/moby/sys/signal" "github.com/moby/term" @@ -43,7 +42,7 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container start, docker start", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool { + ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr container.Summary) bool { return ctr.State == "exited" || ctr.State == "created" }), } diff --git a/cli/command/container/unpause.go b/cli/command/container/unpause.go index 3190d75790..cffd94d4c2 100644 --- a/cli/command/container/unpause.go +++ b/cli/command/container/unpause.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -32,7 +32,7 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container unpause, docker unpause", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { + ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr container.Summary) bool { return ctr.State == "paused" }), } diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index 17afec1b4b..2407e9c81f 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -11,7 +11,7 @@ import ( "time" "github.com/distribution/reference" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/stringid" "github.com/docker/go-units" ) @@ -66,7 +66,7 @@ ports: {{- pad .Ports 1 0}} } // ContainerWrite renders the context for a list of containers -func ContainerWrite(ctx Context, containers []types.Container) error { +func ContainerWrite(ctx Context, containers []container.Summary) error { render := func(format func(subContext SubContext) error) error { for _, ctr := range containers { err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr}) @@ -83,7 +83,7 @@ func ContainerWrite(ctx Context, containers []types.Container) error { type ContainerContext struct { HeaderContext trunc bool - c types.Container + c container.Summary // FieldsUsed is used in the pre-processing step to detect which fields are // used in the template. It's currently only used to detect use of the .Size @@ -313,7 +313,7 @@ func (c *ContainerContext) Networks() string { // DisplayablePorts returns formatted string representing open ports of container // e.g. "0.0.0.0:80->9090/tcp, 9988/tcp" // it's used by command 'docker ps' -func DisplayablePorts(ports []types.Port) string { +func DisplayablePorts(ports []container.Port) string { type portGroup struct { first uint16 last uint16 @@ -378,7 +378,7 @@ func formGroup(key string, start, last uint16) string { return group + "/" + groupType } -func comparePorts(i, j types.Port) bool { +func comparePorts(i, j container.Port) bool { if i.PrivatePort != j.PrivatePort { return i.PrivatePort < j.PrivatePort } diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index 1185e07141..379927a36a 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/stringid" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -25,47 +25,47 @@ func TestContainerPsContext(t *testing.T) { var ctx ContainerContext cases := []struct { - container types.Container + container container.Summary trunc bool expValue string call func() string }{ { - container: types.Container{ID: containerID}, + container: container.Summary{ID: containerID}, trunc: true, expValue: stringid.TruncateID(containerID), call: ctx.ID, }, { - container: types.Container{ID: containerID}, + container: container.Summary{ID: containerID}, expValue: containerID, call: ctx.ID, }, { - container: types.Container{Names: []string{"/foobar_baz"}}, + container: container.Summary{Names: []string{"/foobar_baz"}}, trunc: true, expValue: "foobar_baz", call: ctx.Names, }, { - container: types.Container{Image: "ubuntu"}, + container: container.Summary{Image: "ubuntu"}, trunc: true, expValue: "ubuntu", call: ctx.Image, }, { - container: types.Container{Image: "verylongimagename"}, + container: container.Summary{Image: "verylongimagename"}, trunc: true, expValue: "verylongimagename", call: ctx.Image, }, { - container: types.Container{Image: "verylongimagename"}, + container: container.Summary{Image: "verylongimagename"}, expValue: "verylongimagename", call: ctx.Image, }, { - container: types.Container{ + container: container.Summary{ Image: "a5a665ff33eced1e0803148700880edab4", ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", }, @@ -74,7 +74,7 @@ func TestContainerPsContext(t *testing.T) { call: ctx.Image, }, { - container: types.Container{ + container: container.Summary{ Image: "a5a665ff33eced1e0803148700880edab4", ImageID: "a5a665ff33eced1e0803148700880edab4269067ed77e27737a708d0d293fbf5", }, @@ -82,67 +82,67 @@ func TestContainerPsContext(t *testing.T) { call: ctx.Image, }, { - container: types.Container{Image: ""}, + container: container.Summary{Image: ""}, trunc: true, expValue: "", call: ctx.Image, }, { - container: types.Container{Command: "sh -c 'ls -la'"}, + container: container.Summary{Command: "sh -c 'ls -la'"}, trunc: true, expValue: `"sh -c 'ls -la'"`, call: ctx.Command, }, { - container: types.Container{Created: unix}, + container: container.Summary{Created: unix}, trunc: true, expValue: time.Unix(unix, 0).String(), call: ctx.CreatedAt, }, { - container: types.Container{Ports: []types.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, + container: container.Summary{Ports: []container.Port{{PrivatePort: 8080, PublicPort: 8080, Type: "tcp"}}}, trunc: true, expValue: "8080/tcp", call: ctx.Ports, }, { - container: types.Container{Status: "RUNNING"}, + container: container.Summary{Status: "RUNNING"}, trunc: true, expValue: "RUNNING", call: ctx.Status, }, { - container: types.Container{SizeRw: 10}, + container: container.Summary{SizeRw: 10}, trunc: true, expValue: "10B", call: ctx.Size, }, { - container: types.Container{SizeRw: 10, SizeRootFs: 20}, + container: container.Summary{SizeRw: 10, SizeRootFs: 20}, trunc: true, expValue: "10B (virtual 20B)", call: ctx.Size, }, { - container: types.Container{}, + container: container.Summary{}, trunc: true, call: ctx.Labels, }, { - container: types.Container{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, + container: container.Summary{Labels: map[string]string{"cpu": "6", "storage": "ssd"}}, trunc: true, expValue: "cpu=6,storage=ssd", call: ctx.Labels, }, { - container: types.Container{Created: unix}, + container: container.Summary{Created: unix}, trunc: true, expValue: "About a minute ago", call: ctx.RunningFor, }, { - container: types.Container{ - Mounts: []types.MountPoint{ + container: container.Summary{ + Mounts: []container.MountPoint{ { Name: "this-is-a-long-volume-name-and-will-be-truncated-if-trunc-is-set", Driver: "local", @@ -155,8 +155,8 @@ func TestContainerPsContext(t *testing.T) { call: ctx.Mounts, }, { - container: types.Container{ - Mounts: []types.MountPoint{ + container: container.Summary{ + Mounts: []container.MountPoint{ { Driver: "local", Source: "/a/path", @@ -167,8 +167,8 @@ func TestContainerPsContext(t *testing.T) { call: ctx.Mounts, }, { - container: types.Container{ - Mounts: []types.MountPoint{ + container: container.Summary{ + Mounts: []container.MountPoint{ { Name: "733908409c91817de8e92b0096373245f329f19a88e2c849f02460e9b3d1c203", Driver: "local", @@ -191,7 +191,7 @@ func TestContainerPsContext(t *testing.T) { } } - c1 := types.Container{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}} + c1 := container.Summary{Labels: map[string]string{"com.docker.swarm.swarm-id": "33", "com.docker.swarm.node_name": "ubuntu"}} ctx = ContainerContext{c: c1, trunc: true} sid := ctx.Label("com.docker.swarm.swarm-id") @@ -204,7 +204,7 @@ func TestContainerPsContext(t *testing.T) { t.Fatalf("Expected ubuntu, was %s\n", node) } - c2 := types.Container{} + c2 := container.Summary{} ctx = ContainerContext{c: c2, trunc: true} label := ctx.Label("anything.really") @@ -340,7 +340,7 @@ size: 0B }, } - containers := []types.Container{ + containers := []container.Summary{ {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unixTime, State: "running"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unixTime, State: "running"}, } @@ -362,7 +362,7 @@ size: 0B func TestContainerContextWriteWithNoContainers(t *testing.T) { out := bytes.NewBufferString("") - containers := []types.Container{} + containers := []container.Summary{} cases := []struct { context Context @@ -424,7 +424,7 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) { func TestContainerContextWriteJSON(t *testing.T) { unix := time.Now().Add(-65 * time.Second).Unix() - containers := []types.Container{ + containers := []container.Summary{ {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix, State: "running"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix, State: "running"}, } @@ -478,7 +478,7 @@ func TestContainerContextWriteJSON(t *testing.T) { } func TestContainerContextWriteJSONField(t *testing.T) { - containers := []types.Container{ + containers := []container.Summary{ {ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu"}, {ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu"}, } @@ -497,7 +497,7 @@ func TestContainerContextWriteJSONField(t *testing.T) { } func TestContainerBackCompat(t *testing.T) { - containers := []types.Container{{ID: "brewhaha"}} + containers := []container.Summary{{ID: "brewhaha"}} cases := []string{ "ID", "Names", @@ -523,7 +523,7 @@ func TestContainerBackCompat(t *testing.T) { } type ports struct { - ports []types.Port + ports []container.Port expected string } @@ -531,7 +531,7 @@ type ports struct { func TestDisplayablePorts(t *testing.T) { cases := []ports{ { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9988, Type: "tcp", @@ -540,7 +540,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9988, Type: "udp", @@ -549,7 +549,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "0.0.0.0", PrivatePort: 9988, @@ -559,7 +559,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "0.0.0.0:0->9988/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9988, PublicPort: 8899, @@ -569,7 +569,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "4.3.2.1", PrivatePort: 9988, @@ -580,7 +580,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:8899->9988/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "4.3.2.1", PrivatePort: 9988, @@ -591,7 +591,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:9988->9988/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9988, Type: "udp", @@ -603,7 +603,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 9988/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "1.2.3.4", PublicPort: 9998, @@ -619,7 +619,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "1.2.3.4:9998-9999->9998-9999/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "1.2.3.4", PublicPort: 8887, @@ -635,7 +635,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9998, Type: "udp", @@ -647,7 +647,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9998-9999/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "1.2.3.4", PrivatePort: 6677, @@ -662,7 +662,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 1.2.3.4:7766->6677/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { IP: "1.2.3.4", PrivatePort: 9988, @@ -683,7 +683,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 9988, PublicPort: 8899, @@ -703,7 +703,7 @@ func TestDisplayablePorts(t *testing.T) { expected: "9988/udp, 4.3.2.1:3322->2233/tcp, 1.2.3.4:7766->6677/tcp", }, { - ports: []types.Port{ + ports: []container.Port{ { PrivatePort: 80, Type: "tcp", diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index cd1d75bef3..01edd2b042 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -9,6 +9,7 @@ import ( "github.com/distribution/reference" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/volume" units "github.com/docker/go-units" @@ -36,7 +37,7 @@ type DiskUsageContext struct { Verbose bool LayersSize int64 Images []*image.Summary - Containers []*types.Container + Containers []*container.Summary Volumes []*volume.Volume BuildCache []*types.BuildCache BuilderSize int64 @@ -124,7 +125,7 @@ func (ctx *DiskUsageContext) Write() (err error) { return err } - diskUsageContainersCtx := diskUsageContainersContext{containers: []*types.Container{}} + diskUsageContainersCtx := diskUsageContainersContext{containers: []*container.Summary{}} diskUsageContainersCtx.Header = SubHeaderContext{ "Type": typeHeader, "TotalCount": totalHeader, @@ -313,7 +314,7 @@ func (c *diskUsageImagesContext) Reclaimable() string { type diskUsageContainersContext struct { HeaderContext - containers []*types.Container + containers []*container.Summary } func (c *diskUsageContainersContext) MarshalJSON() ([]byte, error) { @@ -328,10 +329,10 @@ func (c *diskUsageContainersContext) TotalCount() string { return strconv.Itoa(len(c.containers)) } -func (c *diskUsageContainersContext) isActive(container types.Container) bool { - return strings.Contains(container.State, "running") || - strings.Contains(container.State, "paused") || - strings.Contains(container.State, "restarting") +func (c *diskUsageContainersContext) isActive(ctr container.Summary) bool { + return strings.Contains(ctr.State, "running") || + strings.Contains(ctr.State, "paused") || + strings.Contains(ctr.State, "restarting") } func (c *diskUsageContainersContext) Active() string { diff --git a/cli/command/image/client_test.go b/cli/command/image/client_test.go index 8789a34789..4e14bcf7ab 100644 --- a/cli/command/image/client_test.go +++ b/cli/command/image/client_test.go @@ -24,7 +24,7 @@ type fakeClient struct { imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error) imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error) imageListFunc func(options image.ListOptions) ([]image.Summary, error) - imageInspectFunc func(img string) (types.ImageInspect, []byte, error) + imageInspectFunc func(img string) (image.InspectResponse, []byte, error) imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error) imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error) @@ -95,11 +95,11 @@ func (cli *fakeClient) ImageList(_ context.Context, options image.ListOptions) ( return []image.Summary{}, nil } -func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, img string) (types.ImageInspect, []byte, error) { +func (cli *fakeClient) ImageInspectWithRaw(_ context.Context, img string) (image.InspectResponse, []byte, error) { if cli.imageInspectFunc != nil { return cli.imageInspectFunc(img) } - return types.ImageInspect{}, nil, nil + return image.InspectResponse{}, nil, nil } func (cli *fakeClient) ImageImport(_ context.Context, source image.ImportSource, ref string, diff --git a/cli/command/image/inspect_test.go b/cli/command/image/inspect_test.go index c7c2f3f249..61ea36012e 100644 --- a/cli/command/image/inspect_test.go +++ b/cli/command/image/inspect_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/docker/cli/internal/test" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -42,39 +42,39 @@ func TestNewInspectCommandSuccess(t *testing.T) { name string args []string imageCount int - imageInspectFunc func(img string) (types.ImageInspect, []byte, error) + imageInspectFunc func(img string) (image.InspectResponse, []byte, error) }{ { name: "simple", args: []string{"image"}, imageCount: 1, - imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) { imageInspectInvocationCount++ assert.Check(t, is.Equal("image", img)) - return types.ImageInspect{}, nil, nil + return image.InspectResponse{}, nil, nil }, }, { name: "format", imageCount: 1, args: []string{"--format='{{.ID}}'", "image"}, - imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) { imageInspectInvocationCount++ - return types.ImageInspect{ID: img}, nil, nil + return image.InspectResponse{ID: img}, nil, nil }, }, { name: "simple-many", args: []string{"image1", "image2"}, imageCount: 2, - imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (image.InspectResponse, []byte, error) { imageInspectInvocationCount++ if imageInspectInvocationCount == 1 { assert.Check(t, is.Equal("image1", img)) } else { assert.Check(t, is.Equal("image2", img)) } - return types.ImageInspect{}, nil, nil + return image.InspectResponse{}, nil, nil }, }, } diff --git a/cli/command/network/disconnect.go b/cli/command/network/disconnect.go index 80c7745373..521aee33f5 100644 --- a/cli/command/network/disconnect.go +++ b/cli/command/network/disconnect.go @@ -6,7 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/spf13/cobra" ) @@ -48,8 +48,8 @@ func runDisconnect(ctx context.Context, apiClient client.NetworkAPIClient, opts return apiClient.NetworkDisconnect(ctx, opts.network, opts.container, opts.force) } -func isConnected(network string) func(types.Container) bool { - return func(ctr types.Container) bool { +func isConnected(network string) func(container.Summary) bool { + return func(ctr container.Summary) bool { if ctr.NetworkSettings == nil { return false } @@ -58,8 +58,8 @@ func isConnected(network string) func(types.Container) bool { } } -func not(fn func(types.Container) bool) func(types.Container) bool { - return func(ctr types.Container) bool { +func not(fn func(container.Summary) bool) func(container.Summary) bool { + return func(ctr container.Summary) bool { ok := fn(ctr) return !ok } diff --git a/cli/command/trust/inspect_pretty_test.go b/cli/command/trust/inspect_pretty_test.go index e64c00c06f..d123e14878 100644 --- a/cli/command/trust/inspect_pretty_test.go +++ b/cli/command/trust/inspect_pretty_test.go @@ -10,7 +10,6 @@ import ( "github.com/docker/cli/cli/trust" "github.com/docker/cli/internal/test" notaryfake "github.com/docker/cli/internal/test/notary" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/system" "github.com/docker/docker/client" @@ -33,8 +32,8 @@ func (c *fakeClient) Info(context.Context) (system.Info, error) { return system.Info{}, nil } -func (c *fakeClient) ImageInspectWithRaw(context.Context, string) (types.ImageInspect, []byte, error) { - return types.ImageInspect{}, []byte{}, nil +func (c *fakeClient) ImageInspectWithRaw(context.Context, string) (image.InspectResponse, []byte, error) { + return image.InspectResponse{}, []byte{}, nil } func (c *fakeClient) ImagePush(context.Context, string, image.PushOptions) (io.ReadCloser, error) { diff --git a/internal/test/builders/container.go b/internal/test/builders/container.go index 359b14e76a..df67f60a07 100644 --- a/internal/test/builders/container.go +++ b/internal/test/builders/container.go @@ -3,15 +3,15 @@ package builders import ( "time" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // Container creates a container with default values. // Any number of container function builder can be passed to augment it. -func Container(name string, builders ...func(c *types.Container)) *types.Container { +func Container(name string, builders ...func(c *container.Summary)) *container.Summary { // now := time.Now() // onehourago := now.Add(-120 * time.Minute) - ctr := &types.Container{ + ctr := &container.Summary{ ID: "container_id", Names: []string{"/" + name}, Command: "top", @@ -28,8 +28,8 @@ func Container(name string, builders ...func(c *types.Container)) *types.Contain } // WithLabel adds a label to the container -func WithLabel(key, value string) func(*types.Container) { - return func(c *types.Container) { +func WithLabel(key, value string) func(*container.Summary) { + return func(c *container.Summary) { if c.Labels == nil { c.Labels = map[string]string{} } @@ -38,19 +38,19 @@ func WithLabel(key, value string) func(*types.Container) { } // WithName adds a name to the container -func WithName(name string) func(*types.Container) { - return func(c *types.Container) { +func WithName(name string) func(*container.Summary) { + return func(c *container.Summary) { c.Names = append(c.Names, "/"+name) } } // WithPort adds a port mapping to the container -func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) func(*types.Container) { - return func(c *types.Container) { +func WithPort(privatePort, publicPort uint16, builders ...func(*container.Port)) func(*container.Summary) { + return func(c *container.Summary) { if c.Ports == nil { - c.Ports = []types.Port{} + c.Ports = []container.Port{} } - port := &types.Port{ + port := &container.Port{ PrivatePort: privatePort, PublicPort: publicPort, } @@ -62,8 +62,8 @@ func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) fun } // WithSize adds size in bytes to the container -func WithSize(size int64) func(*types.Container) { - return func(c *types.Container) { +func WithSize(size int64) func(*container.Summary) { + return func(c *container.Summary) { if size >= 0 { c.SizeRw = size } @@ -71,18 +71,18 @@ func WithSize(size int64) func(*types.Container) { } // IP sets the ip of the port -func IP(ip string) func(*types.Port) { - return func(p *types.Port) { +func IP(ip string) func(*container.Port) { + return func(p *container.Port) { p.IP = ip } } // TCP sets the port to tcp -func TCP(p *types.Port) { +func TCP(p *container.Port) { p.Type = "tcp" } // UDP sets the port to udp -func UDP(p *types.Port) { +func UDP(p *container.Port) { p.Type = "udp" }