Skip to content

Commit dafbfc2

Browse files
authored
Merge pull request #6576 from robmry/bump_modules_again
vendor: github.com/moby/moby/api, moby/moby/client master
2 parents 965a0e3 + 4a60806 commit dafbfc2

File tree

19 files changed

+164
-120
lines changed

19 files changed

+164
-120
lines changed

cli/command/container/attach.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ type AttachOptions struct {
2323
}
2424

2525
func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*container.InspectResponse, error) {
26-
c, err := apiClient.ContainerInspect(ctx, args)
26+
c, err := apiClient.ContainerInspect(ctx, args, client.ContainerInspectOptions{})
2727
if err != nil {
2828
return nil, err
2929
}
30-
if !c.State.Running {
30+
if !c.Container.State.Running {
3131
return nil, errors.New("cannot attach to a stopped container, start it first")
3232
}
33-
if c.State.Paused {
33+
if c.Container.State.Paused {
3434
return nil, errors.New("cannot attach to a paused container, unpause it first")
3535
}
36-
if c.State.Restarting {
36+
if c.Container.State.Restarting {
3737
return nil, errors.New("cannot attach to a restarting container, wait until it is running")
3838
}
3939

40-
return &c, nil
40+
return &c.Container, nil
4141
}
4242

4343
// newAttachCommand creates a new cobra.Command for `docker attach`

cli/command/container/attach_test.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/internal/test"
1010
"github.com/moby/moby/api/types/container"
11+
"github.com/moby/moby/client"
1112
"gotest.tools/v3/assert"
1213
)
1314

@@ -16,24 +17,26 @@ func TestNewAttachCommandErrors(t *testing.T) {
1617
name string
1718
args []string
1819
expectedError string
19-
containerInspectFunc func(img string) (container.InspectResponse, error)
20+
containerInspectFunc func(img string) (client.ContainerInspectResult, error)
2021
}{
2122
{
2223
name: "client-error",
2324
args: []string{"5cb5bb5e4a3b"},
2425
expectedError: "something went wrong",
25-
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
26-
return container.InspectResponse{}, errors.New("something went wrong")
26+
containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
27+
return client.ContainerInspectResult{}, errors.New("something went wrong")
2728
},
2829
},
2930
{
3031
name: "client-stopped",
3132
args: []string{"5cb5bb5e4a3b"},
3233
expectedError: "cannot attach to a stopped container",
33-
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
34-
return container.InspectResponse{
35-
State: &container.State{
36-
Running: false,
34+
containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
35+
return client.ContainerInspectResult{
36+
Container: container.InspectResponse{
37+
State: &container.State{
38+
Running: false,
39+
},
3740
},
3841
}, nil
3942
},
@@ -42,11 +45,13 @@ func TestNewAttachCommandErrors(t *testing.T) {
4245
name: "client-paused",
4346
args: []string{"5cb5bb5e4a3b"},
4447
expectedError: "cannot attach to a paused container",
45-
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
46-
return container.InspectResponse{
47-
State: &container.State{
48-
Running: true,
49-
Paused: true,
48+
containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
49+
return client.ContainerInspectResult{
50+
Container: container.InspectResponse{
51+
State: &container.State{
52+
Running: true,
53+
Paused: true,
54+
},
5055
},
5156
}, nil
5257
},
@@ -55,12 +60,14 @@ func TestNewAttachCommandErrors(t *testing.T) {
5560
name: "client-restarting",
5661
args: []string{"5cb5bb5e4a3b"},
5762
expectedError: "cannot attach to a restarting container",
58-
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
59-
return container.InspectResponse{
60-
State: &container.State{
61-
Running: true,
62-
Paused: false,
63-
Restarting: true,
63+
containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
64+
return client.ContainerInspectResult{
65+
Container: container.InspectResponse{
66+
State: &container.State{
67+
Running: true,
68+
Paused: false,
69+
Restarting: true,
70+
},
6471
},
6572
}, nil
6673
},

cli/command/container/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
type fakeClient struct {
1313
client.Client
14-
inspectFunc func(string) (container.InspectResponse, error)
14+
inspectFunc func(string) (client.ContainerInspectResult, error)
1515
execInspectFunc func(execID string) (client.ExecInspectResult, error)
1616
execCreateFunc func(containerID string, options client.ExecCreateOptions) (client.ExecCreateResult, error)
1717
createContainerFunc func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
@@ -45,11 +45,11 @@ func (f *fakeClient) ContainerList(_ context.Context, options client.ContainerLi
4545
return []container.Summary{}, nil
4646
}
4747

48-
func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (container.InspectResponse, error) {
48+
func (f *fakeClient) ContainerInspect(_ context.Context, containerID string, options client.ContainerInspectOptions) (client.ContainerInspectResult, error) {
4949
if f.inspectFunc != nil {
5050
return f.inspectFunc(containerID)
5151
}
52-
return container.InspectResponse{}, nil
52+
return client.ContainerInspectResult{}, nil
5353
}
5454

5555
func (f *fakeClient) ExecCreate(_ context.Context, containerID string, config client.ExecCreateOptions) (client.ExecCreateResult, error) {

cli/command/container/exec.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin
9797
// otherwise if we error out we will leak execIDs on the server (and
9898
// there's no easy way to clean those up). But also in order to make "not
9999
// exist" errors take precedence we do a dummy inspect first.
100-
if _, err := apiClient.ContainerInspect(ctx, containerIDorName); err != nil {
100+
if _, err := apiClient.ContainerInspect(ctx, containerIDorName, client.ContainerInspectOptions{}); err != nil {
101101
return err
102102
}
103103
if !options.Detach {
@@ -119,10 +119,17 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin
119119
}
120120

121121
if options.Detach {
122+
var cs client.ConsoleSize
123+
if execOptions.ConsoleSize != nil {
124+
cs = client.ConsoleSize{
125+
Height: execOptions.ConsoleSize[0],
126+
Width: execOptions.ConsoleSize[1],
127+
}
128+
}
122129
_, err := apiClient.ExecStart(ctx, execID, client.ExecStartOptions{
123130
Detach: options.Detach,
124-
Tty: execOptions.Tty,
125-
ConsoleSize: execOptions.ConsoleSize,
131+
TTY: execOptions.Tty,
132+
ConsoleSize: cs,
126133
})
127134
return err
128135
}
@@ -159,9 +166,16 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, execOptions *cl
159166
fillConsoleSize(execOptions, dockerCli)
160167

161168
apiClient := dockerCli.Client()
169+
var cs client.ConsoleSize
170+
if execOptions.ConsoleSize != nil {
171+
cs = client.ConsoleSize{
172+
Height: execOptions.ConsoleSize[0],
173+
Width: execOptions.ConsoleSize[1],
174+
}
175+
}
162176
resp, err := apiClient.ExecAttach(ctx, execID, client.ExecAttachOptions{
163-
Tty: execOptions.Tty,
164-
ConsoleSize: execOptions.ConsoleSize,
177+
TTY: execOptions.Tty,
178+
ConsoleSize: cs,
165179
})
166180
if err != nil {
167181
return err

cli/command/container/exec_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/docker/cli/cli/config/configfile"
1313
"github.com/docker/cli/internal/test"
1414
"github.com/docker/cli/opts"
15-
"github.com/moby/moby/api/types/container"
1615
"github.com/moby/moby/client"
1716
"gotest.tools/v3/assert"
1817
is "gotest.tools/v3/assert/cmp"
@@ -177,8 +176,8 @@ func TestRunExec(t *testing.T) {
177176
doc: "inspect error",
178177
options: NewExecOptions(),
179178
client: &fakeClient{
180-
inspectFunc: func(string) (container.InspectResponse, error) {
181-
return container.InspectResponse{}, errors.New("failed inspect")
179+
inspectFunc: func(string) (client.ContainerInspectResult, error) {
180+
return client.ContainerInspectResult{}, errors.New("failed inspect")
182181
},
183182
},
184183
expectedError: "failed inspect",
@@ -251,14 +250,14 @@ func TestNewExecCommandErrors(t *testing.T) {
251250
name string
252251
args []string
253252
expectedError string
254-
containerInspectFunc func(img string) (container.InspectResponse, error)
253+
containerInspectFunc func(img string) (client.ContainerInspectResult, error)
255254
}{
256255
{
257256
name: "client-error",
258257
args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"},
259258
expectedError: "something went wrong",
260-
containerInspectFunc: func(containerID string) (container.InspectResponse, error) {
261-
return container.InspectResponse{}, errors.New("something went wrong")
259+
containerInspectFunc: func(containerID string) (client.ContainerInspectResult, error) {
260+
return client.ContainerInspectResult{}, errors.New("something went wrong")
262261
},
263262
},
264263
}

cli/command/container/inspect.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/cli/cli/command/completion"
1212
"github.com/docker/cli/cli/command/inspect"
1313
flagsHelper "github.com/docker/cli/cli/flags"
14+
"github.com/moby/moby/client"
1415
"github.com/spf13/cobra"
1516
)
1617

@@ -46,6 +47,10 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
4647
func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions) error {
4748
apiClient := dockerCLI.Client()
4849
return inspect.Inspect(dockerCLI.Out(), opts.refs, opts.format, func(ref string) (any, []byte, error) {
49-
return apiClient.ContainerInspectWithRaw(ctx, ref, opts.size)
50+
res, err := apiClient.ContainerInspect(ctx, ref, client.ContainerInspectOptions{Size: opts.size})
51+
if err != nil {
52+
return nil, nil, err
53+
}
54+
return &res.Container, res.Raw, nil
5055
})
5156
}

cli/command/container/logs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func newLogsCommand(dockerCLI command.Cli) *cobra.Command {
5454
}
5555

5656
func runLogs(ctx context.Context, dockerCli command.Cli, opts *logsOptions) error {
57-
c, err := dockerCli.Client().ContainerInspect(ctx, opts.container)
57+
c, err := dockerCli.Client().ContainerInspect(ctx, opts.container, client.ContainerInspectOptions{})
5858
if err != nil {
5959
return err
6060
}
6161

62-
responseBody, err := dockerCli.Client().ContainerLogs(ctx, c.ID, client.ContainerLogsOptions{
62+
responseBody, err := dockerCli.Client().ContainerLogs(ctx, c.Container.ID, client.ContainerLogsOptions{
6363
ShowStdout: true,
6464
ShowStderr: true,
6565
Since: opts.since,
@@ -74,7 +74,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, opts *logsOptions) erro
7474
}
7575
defer responseBody.Close()
7676

77-
if c.Config.Tty {
77+
if c.Container.Config.Tty {
7878
_, err = io.Copy(dockerCli.Out(), responseBody)
7979
} else {
8080
_, err = stdcopy.StdCopy(dockerCli.Out(), dockerCli.Err(), responseBody)

cli/command/container/logs_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ var logFn = func(expectedOut string) func(string, client.ContainerLogsOptions) (
2020
}
2121

2222
func TestRunLogs(t *testing.T) {
23-
inspectFn := func(containerID string) (container.InspectResponse, error) {
24-
return container.InspectResponse{
25-
Config: &container.Config{Tty: true},
26-
State: &container.State{Running: false},
23+
inspectFn := func(containerID string) (client.ContainerInspectResult, error) {
24+
return client.ContainerInspectResult{
25+
Container: container.InspectResponse{
26+
Config: &container.Config{Tty: true},
27+
State: &container.State{Running: false},
28+
},
2729
}, nil
2830
}
2931

cli/command/container/port.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/cli/cli/command/completion"
1313
"github.com/fvbommel/sortorder"
1414
"github.com/moby/moby/api/types/network"
15+
"github.com/moby/moby/client"
1516
"github.com/spf13/cobra"
1617
)
1718

@@ -52,7 +53,7 @@ func newPortCommand(dockerCLI command.Cli) *cobra.Command {
5253
// proto is specified. We should consider changing this to "any" protocol
5354
// for the given private port.
5455
func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) error {
55-
c, err := dockerCli.Client().ContainerInspect(ctx, opts.container)
56+
c, err := dockerCli.Client().ContainerInspect(ctx, opts.container, client.ContainerInspectOptions{})
5657
if err != nil {
5758
return err
5859
}
@@ -63,15 +64,15 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
6364
if err != nil {
6465
return err
6566
}
66-
frontends, exists := c.NetworkSettings.Ports[port]
67+
frontends, exists := c.Container.NetworkSettings.Ports[port]
6768
if !exists || len(frontends) == 0 {
6869
return fmt.Errorf("no public port '%s' published for %s", opts.port, opts.container)
6970
}
7071
for _, frontend := range frontends {
7172
out = append(out, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort))
7273
}
7374
} else {
74-
for from, frontends := range c.NetworkSettings.Ports {
75+
for from, frontends := range c.Container.NetworkSettings.Ports {
7576
for _, frontend := range frontends {
7677
out = append(out, fmt.Sprintf("%s -> %s", from, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort)))
7778
}

cli/command/container/port_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/cli/internal/test"
99
"github.com/moby/moby/api/types/container"
1010
"github.com/moby/moby/api/types/network"
11+
"github.com/moby/moby/client"
1112
"gotest.tools/v3/assert"
1213
"gotest.tools/v3/golden"
1314
)
@@ -46,7 +47,7 @@ func TestNewPortCommandOutput(t *testing.T) {
4647
for _, tc := range testCases {
4748
t.Run(tc.name, func(t *testing.T) {
4849
cli := test.NewFakeCli(&fakeClient{
49-
inspectFunc: func(string) (container.InspectResponse, error) {
50+
inspectFunc: func(string) (client.ContainerInspectResult, error) {
5051
ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}}
5152
ci.NetworkSettings.Ports = network.PortMap{
5253
network.MustParsePort("80/tcp"): make([]network.PortBinding, len(tc.ips)),
@@ -64,7 +65,7 @@ func TestNewPortCommandOutput(t *testing.T) {
6465
HostIP: ip, HostPort: "5678",
6566
}
6667
}
67-
return ci, nil
68+
return client.ContainerInspectResult{Container: ci}, nil
6869
},
6970
})
7071
cmd := newPortCommand(cli)

0 commit comments

Comments
 (0)