api/types: move ContainerAttachOptions to api/types/container

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-25 20:10:15 +02:00
parent 95b92b1f97
commit 30f09b4a1a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
10 changed files with 27 additions and 19 deletions

View file

@ -11,16 +11,6 @@ import (
units "github.com/docker/go-units" 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. // ContainerCommitOptions holds parameters to commit changes into a container.
type ContainerCommitOptions struct { type ContainerCommitOptions struct {
Reference string Reference string

View file

@ -7,3 +7,13 @@ type ResizeOptions struct {
Height uint Height uint
Width 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
}

View file

@ -99,6 +99,11 @@ type ServiceUpdateResponse = swarm.ServiceUpdateResponse
// Deprecated: use [container.ResizeOptions]. // Deprecated: use [container.ResizeOptions].
type ResizeOptions = 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 // DecodeSecurityOptions decodes a security options string slice to a type safe
// [system.SecurityOpt]. // [system.SecurityOpt].
// //

View file

@ -6,6 +6,7 @@ import (
"net/url" "net/url"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
) )
// ContainerAttach attaches a connection to a container in the server. // 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 // You can use github.com/docker/docker/pkg/stdcopy.StdCopy to demultiplex this
// stream. // 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{} query := url.Values{}
if options.Stream { if options.Stream {
query.Set("stream", "1") query.Set("stream", "1")

View file

@ -46,7 +46,7 @@ type CommonAPIClient interface {
// ContainerAPIClient defines API client methods for the containers // ContainerAPIClient defines API client methods for the containers
type ContainerAPIClient interface { 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) 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) 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) ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)

View file

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
@ -184,7 +185,7 @@ func (s *DockerAPISuite) TestPostContainersAttach(c *testing.T) {
cid = strings.TrimSpace(cid) cid = strings.TrimSpace(cid)
// Make sure we don't see "hello" if Logs is false // Make sure we don't see "hello" if Logs is false
attachOpts := types.ContainerAttachOptions{ attachOpts := container.AttachOptions{
Stream: true, Stream: true,
Stdin: true, Stdin: true,
Stdout: true, Stdout: true,

View file

@ -13,7 +13,7 @@ import (
func TestAttach(t *testing.T) { func TestAttach(t *testing.T) {
ctx := setupTest(t) ctx := setupTest(t)
client := testEnv.APIClient() apiClient := testEnv.APIClient()
tests := []struct { tests := []struct {
doc string doc string
@ -36,7 +36,7 @@ func TestAttach(t *testing.T) {
t.Parallel() t.Parallel()
ctx := testutil.StartSpan(ctx, t) ctx := testutil.StartSpan(ctx, t)
resp, err := client.ContainerCreate(ctx, resp, err := apiClient.ContainerCreate(ctx,
&container.Config{ &container.Config{
Image: "busybox", Image: "busybox",
Cmd: []string{"echo", "hello"}, Cmd: []string{"echo", "hello"},
@ -48,7 +48,7 @@ func TestAttach(t *testing.T) {
"", "",
) )
assert.NilError(t, err) assert.NilError(t, err)
attach, err := client.ContainerAttach(ctx, resp.ID, types.ContainerAttachOptions{ attach, err := apiClient.ContainerAttach(ctx, resp.ID, container.AttachOptions{
Stdout: true, Stdout: true,
Stderr: true, Stderr: true,
}) })

View file

@ -145,7 +145,7 @@ func TestWaitConditions(t *testing.T) {
containerID := container.Create(ctx, t, cli, opts...) containerID := container.Create(ctx, t, cli, opts...)
t.Logf("ContainerID = %v", containerID) 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) assert.NilError(t, err)
defer streams.Close() defer streams.Close()

View file

@ -99,7 +99,7 @@ func RunAttach(ctx context.Context, t *testing.T, apiClient client.APIClient, op
}) })
id := Create(ctx, t, apiClient, ops...) id := Create(ctx, t, apiClient, ops...)
aresp, err := apiClient.ContainerAttach(ctx, id, types.ContainerAttachOptions{ aresp, err := apiClient.ContainerAttach(ctx, id, container.AttachOptions{
Stream: true, Stream: true,
Stdout: true, Stdout: true,
Stderr: true, Stderr: true,

View file

@ -9,6 +9,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types" "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/integration/internal/container"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"github.com/docker/docker/testutil/daemon" "github.com/docker/docker/testutil/daemon"
@ -49,7 +50,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
defer client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true}) 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 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) assert.NilError(t, err)
chErr := make(chan error, 1) chErr := make(chan error, 1)