diff --git a/api/types/container/exec.go b/api/types/container/exec.go index 29c7b96268..6895926aef 100644 --- a/api/types/container/exec.go +++ b/api/types/container/exec.go @@ -8,21 +8,6 @@ import "github.com/moby/moby/api/types/common" // TODO(thaJeztah): make this a distinct type. type ExecCreateResponse = common.IDResponse -// ExecInspect holds information returned by exec inspect. -// -// It is used by the client to unmarshal a [ExecInspectResponse], -// but currently only provides a subset of the information included -// in that type. -// -// TODO(thaJeztah): merge [ExecInspect] and [ExecInspectResponse], -type ExecInspect struct { - ExecID string `json:"ID"` - ContainerID string `json:"ContainerID"` - Running bool `json:"Running"` - ExitCode int `json:"ExitCode"` - Pid int `json:"Pid"` -} - // ExecInspectResponse is the API response for the "GET /exec/{id}/json" // endpoint and holds information about and exec. type ExecInspectResponse struct { diff --git a/client/client_interfaces.go b/client/client_interfaces.go index a1059e68d3..dbfe8cbcb7 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -71,7 +71,7 @@ type ContainerAPIClient interface { ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error) ContainerExecAttach(ctx context.Context, execID string, options ExecAttachOptions) (HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, options ExecCreateOptions) (container.ExecCreateResponse, error) - ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) + ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error ContainerExecStart(ctx context.Context, execID string, options ExecStartOptions) error ContainerExport(ctx context.Context, container string) (io.ReadCloser, error) diff --git a/client/container_exec.go b/client/container_exec.go index d2fb4cba1b..2a0cdec79d 100644 --- a/client/container_exec.go +++ b/client/container_exec.go @@ -146,15 +146,43 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi }) } +// ExecInspect holds information returned by exec inspect. +// +// It provides a subset of the information included in [container.ExecInspectResponse]. +// +// TODO(thaJeztah): include all fields of [container.ExecInspectResponse] ? +type ExecInspect struct { + ExecID string `json:"ID"` + ContainerID string `json:"ContainerID"` + Running bool `json:"Running"` + ExitCode int `json:"ExitCode"` + Pid int `json:"Pid"` +} + // ContainerExecInspect returns information about a specific exec process on the docker host. -func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) { +func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) { resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil) defer ensureReaderClosed(resp) if err != nil { - return container.ExecInspect{}, err + return ExecInspect{}, err } - var response container.ExecInspect + var response container.ExecInspectResponse err = json.NewDecoder(resp.Body).Decode(&response) - return response, err + if err != nil { + return ExecInspect{}, err + } + + var ec int + if response.ExitCode != nil { + ec = *response.ExitCode + } + + return ExecInspect{ + ExecID: response.ID, + ContainerID: response.ContainerID, + Running: response.Running, + ExitCode: ec, + Pid: response.Pid, + }, nil } diff --git a/client/container_exec_test.go b/client/container_exec_test.go index 337d43c163..4539430cea 100644 --- a/client/container_exec_test.go +++ b/client/container_exec_test.go @@ -146,10 +146,10 @@ func TestContainerExecInspect(t *testing.T) { client, err := NewClientWithOpts( WithMockClient(func(req *http.Request) (*http.Response, error) { if !strings.HasPrefix(req.URL.Path, expectedURL) { - return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) + return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) } - b, err := json.Marshal(container.ExecInspect{ - ExecID: "exec_id", + b, err := json.Marshal(container.ExecInspectResponse{ + ID: "exec_id", ContainerID: "container_id", }) if err != nil { diff --git a/vendor/github.com/moby/moby/api/types/container/exec.go b/vendor/github.com/moby/moby/api/types/container/exec.go index 29c7b96268..6895926aef 100644 --- a/vendor/github.com/moby/moby/api/types/container/exec.go +++ b/vendor/github.com/moby/moby/api/types/container/exec.go @@ -8,21 +8,6 @@ import "github.com/moby/moby/api/types/common" // TODO(thaJeztah): make this a distinct type. type ExecCreateResponse = common.IDResponse -// ExecInspect holds information returned by exec inspect. -// -// It is used by the client to unmarshal a [ExecInspectResponse], -// but currently only provides a subset of the information included -// in that type. -// -// TODO(thaJeztah): merge [ExecInspect] and [ExecInspectResponse], -type ExecInspect struct { - ExecID string `json:"ID"` - ContainerID string `json:"ContainerID"` - Running bool `json:"Running"` - ExitCode int `json:"ExitCode"` - Pid int `json:"Pid"` -} - // ExecInspectResponse is the API response for the "GET /exec/{id}/json" // endpoint and holds information about and exec. type ExecInspectResponse struct { diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index a1059e68d3..dbfe8cbcb7 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -71,7 +71,7 @@ type ContainerAPIClient interface { ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error) ContainerExecAttach(ctx context.Context, execID string, options ExecAttachOptions) (HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, options ExecCreateOptions) (container.ExecCreateResponse, error) - ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) + ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error ContainerExecStart(ctx context.Context, execID string, options ExecStartOptions) error ContainerExport(ctx context.Context, container string) (io.ReadCloser, error) diff --git a/vendor/github.com/moby/moby/client/container_exec.go b/vendor/github.com/moby/moby/client/container_exec.go index d2fb4cba1b..2a0cdec79d 100644 --- a/vendor/github.com/moby/moby/client/container_exec.go +++ b/vendor/github.com/moby/moby/client/container_exec.go @@ -146,15 +146,43 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi }) } +// ExecInspect holds information returned by exec inspect. +// +// It provides a subset of the information included in [container.ExecInspectResponse]. +// +// TODO(thaJeztah): include all fields of [container.ExecInspectResponse] ? +type ExecInspect struct { + ExecID string `json:"ID"` + ContainerID string `json:"ContainerID"` + Running bool `json:"Running"` + ExitCode int `json:"ExitCode"` + Pid int `json:"Pid"` +} + // ContainerExecInspect returns information about a specific exec process on the docker host. -func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) { +func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) { resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil) defer ensureReaderClosed(resp) if err != nil { - return container.ExecInspect{}, err + return ExecInspect{}, err } - var response container.ExecInspect + var response container.ExecInspectResponse err = json.NewDecoder(resp.Body).Decode(&response) - return response, err + if err != nil { + return ExecInspect{}, err + } + + var ec int + if response.ExitCode != nil { + ec = *response.ExitCode + } + + return ExecInspect{ + ExecID: response.ID, + ContainerID: response.ContainerID, + Running: response.Running, + ExitCode: ec, + Pid: response.Pid, + }, nil }