From 30f09b4a1a611094878e2c3956f28dfd05be2d6d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Aug 2023 20:10:15 +0200 Subject: [PATCH] api/types: move ContainerAttachOptions to api/types/container Signed-off-by: Sebastiaan van Stijn --- api/types/client.go | 10 ---------- api/types/container/options.go | 10 ++++++++++ api/types/types_deprecated.go | 5 +++++ client/container_attach.go | 3 ++- client/interface.go | 2 +- integration-cli/docker_api_attach_test.go | 3 ++- integration/container/attach_test.go | 6 +++--- integration/container/wait_test.go | 2 +- integration/internal/container/container.go | 2 +- integration/plugin/logging/logging_linux_test.go | 3 ++- 10 files changed, 27 insertions(+), 19 deletions(-) diff --git a/api/types/client.go b/api/types/client.go index 92a48922a8..58000795ea 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -11,16 +11,6 @@ import ( units "github.com/docker/go-units" ) -// ContainerAttachOptions holds parameters to attach to a container. -type ContainerAttachOptions struct { - Stream bool - Stdin bool - Stdout bool - Stderr bool - DetachKeys string - Logs bool -} - // ContainerCommitOptions holds parameters to commit changes into a container. type ContainerCommitOptions struct { Reference string diff --git a/api/types/container/options.go b/api/types/container/options.go index 3a340c130c..1a729b354d 100644 --- a/api/types/container/options.go +++ b/api/types/container/options.go @@ -7,3 +7,13 @@ type ResizeOptions struct { Height uint Width uint } + +// AttachOptions holds parameters to attach to a container. +type AttachOptions struct { + Stream bool + Stdin bool + Stdout bool + Stderr bool + DetachKeys string + Logs bool +} diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index 88d5bc6637..1e98c7a066 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -99,6 +99,11 @@ type ServiceUpdateResponse = swarm.ServiceUpdateResponse // Deprecated: use [container.ResizeOptions]. type ResizeOptions = container.ResizeOptions +// ContainerAttachOptions holds parameters to attach to a container. +// +// Deprecated: use [container.AttachOptions]. +type ContainerAttachOptions = container.AttachOptions + // DecodeSecurityOptions decodes a security options string slice to a type safe // [system.SecurityOpt]. // diff --git a/client/container_attach.go b/client/container_attach.go index a3a009050d..6a32e5f664 100644 --- a/client/container_attach.go +++ b/client/container_attach.go @@ -6,6 +6,7 @@ import ( "net/url" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" ) // ContainerAttach attaches a connection to a container in the server. @@ -32,7 +33,7 @@ import ( // // You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this // stream. -func (cli *Client) ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) { +func (cli *Client) ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error) { query := url.Values{} if options.Stream { query.Set("stream", "1") diff --git a/client/interface.go b/client/interface.go index 4807a7ef69..a0dd92e649 100644 --- a/client/interface.go +++ b/client/interface.go @@ -46,7 +46,7 @@ type CommonAPIClient interface { // ContainerAPIClient defines API client methods for the containers type ContainerAPIClient interface { - ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) + ContainerAttach(ctx context.Context, container string, options container.AttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error) ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error) diff --git a/integration-cli/docker_api_attach_test.go b/integration-cli/docker_api_attach_test.go index 9cf6645d60..b77292db71 100644 --- a/integration-cli/docker_api_attach_test.go +++ b/integration-cli/docker_api_attach_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/testutil" @@ -184,7 +185,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) { cid = strings.TrimSpace(cid) // Make sure we don't see "hello" if Logs is false - attachOpts := types.ContainerAttachOptions{ + attachOpts := container.AttachOptions{ Stream: true, Stdin: true, Stdout: true, diff --git a/integration/container/attach_test.go b/integration/container/attach_test.go index c2c2c4b888..b761615de5 100644 --- a/integration/container/attach_test.go +++ b/integration/container/attach_test.go @@ -13,7 +13,7 @@ import ( func TestAttach(t *testing.T) { ctx := setupTest(t) - client := testEnv.APIClient() + apiClient := testEnv.APIClient() tests := []struct { doc string @@ -36,7 +36,7 @@ func TestAttach(t *testing.T) { t.Parallel() ctx := testutil.StartSpan(ctx, t) - resp, err := client.ContainerCreate(ctx, + resp, err := apiClient.ContainerCreate(ctx, &container.Config{ Image: "busybox", Cmd: []string{"echo", "hello"}, @@ -48,7 +48,7 @@ func TestAttach(t *testing.T) { "", ) assert.NilError(t, err) - attach, err := client.ContainerAttach(ctx, resp.ID, types.ContainerAttachOptions{ + attach, err := apiClient.ContainerAttach(ctx, resp.ID, container.AttachOptions{ Stdout: true, Stderr: true, }) diff --git a/integration/container/wait_test.go b/integration/container/wait_test.go index faf7ea51bb..0a0abee504 100644 --- a/integration/container/wait_test.go +++ b/integration/container/wait_test.go @@ -145,7 +145,7 @@ func TestWaitConditions(t *testing.T) { containerID := container.Create(ctx, t, cli, opts...) t.Logf("ContainerID = %v", containerID) - streams, err := cli.ContainerAttach(ctx, containerID, types.ContainerAttachOptions{Stream: true, Stdin: true}) + streams, err := cli.ContainerAttach(ctx, containerID, containertypes.AttachOptions{Stream: true, Stdin: true}) assert.NilError(t, err) defer streams.Close() diff --git a/integration/internal/container/container.go b/integration/internal/container/container.go index 2eb04ef0ae..950fa2f73c 100644 --- a/integration/internal/container/container.go +++ b/integration/internal/container/container.go @@ -99,7 +99,7 @@ func RunAttach(ctx context.Context, t *testing.T, apiClient client.APIClient, op }) id := Create(ctx, t, apiClient, ops...) - aresp, err := apiClient.ContainerAttach(ctx, id, types.ContainerAttachOptions{ + aresp, err := apiClient.ContainerAttach(ctx, id, container.AttachOptions{ Stream: true, Stdout: true, Stderr: true, diff --git a/integration/plugin/logging/logging_linux_test.go b/integration/plugin/logging/logging_linux_test.go index c0b2995db4..f74e6c41e5 100644 --- a/integration/plugin/logging/logging_linux_test.go +++ b/integration/plugin/logging/logging_linux_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/docker/docker/api/types" + containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/testutil" "github.com/docker/docker/testutil/daemon" @@ -49,7 +50,7 @@ func TestContinueAfterPluginCrash(t *testing.T) { defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) // Attach to the container to make sure it's written a few times to stdout - attach, err := client.ContainerAttach(ctx, id, types.ContainerAttachOptions{Stream: true, Stdout: true}) + attach, err := client.ContainerAttach(ctx, id, containertypes.AttachOptions{Stream: true, Stdout: true}) assert.NilError(t, err) chErr := make(chan error, 1)