api/types: move ContainerCommitOptions 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:15:25 +02:00
parent 30f09b4a1a
commit 9498d897ab
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
11 changed files with 34 additions and 25 deletions

View file

@ -11,16 +11,6 @@ import (
units "github.com/docker/go-units"
)
// ContainerCommitOptions holds parameters to commit changes into a container.
type ContainerCommitOptions struct {
Reference string
Comment string
Author string
Changes []string
Pause bool
Config *container.Config
}
// ContainerExecInspect holds information returned by exec inspect.
type ContainerExecInspect struct {
ExecID string `json:"ID"`

View file

@ -17,3 +17,13 @@ type AttachOptions struct {
DetachKeys string
Logs bool
}
// CommitOptions holds parameters to commit changes into a container.
type CommitOptions struct {
Reference string
Comment string
Author string
Changes []string
Pause bool
Config *Config
}

View file

@ -104,6 +104,11 @@ type ResizeOptions = container.ResizeOptions
// Deprecated: use [container.AttachOptions].
type ContainerAttachOptions = container.AttachOptions
// ContainerCommitOptions holds parameters to commit changes into a container.
//
// Deprecated: use [container.CommitOptions].
type ContainerCommitOptions = container.CommitOptions
// DecodeSecurityOptions decodes a security options string slice to a type safe
// [system.SecurityOpt].
//

View file

@ -8,10 +8,11 @@ import (
"github.com/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
)
// ContainerCommit applies changes to a container and creates a new tagged image.
func (cli *Client) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) {
func (cli *Client) ContainerCommit(ctx context.Context, container string, options container.CommitOptions) (types.IDResponse, error) {
var repository, tag string
if options.Reference != "" {
ref, err := reference.ParseNormalizedNamed(options.Reference)

View file

@ -11,6 +11,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -20,7 +21,7 @@ func TestContainerCommitError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.ContainerCommit(context.Background(), "nothing", types.ContainerCommitOptions{})
_, err := client.ContainerCommit(context.Background(), "nothing", container.CommitOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@ -81,7 +82,7 @@ func TestContainerCommit(t *testing.T) {
}),
}
r, err := client.ContainerCommit(context.Background(), expectedContainerID, types.ContainerCommitOptions{
r, err := client.ContainerCommit(context.Background(), expectedContainerID, container.CommitOptions{
Reference: specifiedReference,
Comment: expectedComment,
Author: expectedAuthor,

View file

@ -47,7 +47,7 @@ type CommonAPIClient interface {
// ContainerAPIClient defines API client methods for the containers
type ContainerAPIClient interface {
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 container.CommitOptions) (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)
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)

View file

@ -454,7 +454,7 @@ func (s *DockerAPISuite) TestContainerAPICommit(c *testing.T) {
assert.NilError(c, err)
defer apiClient.Close()
options := types.ContainerCommitOptions{
options := container.CommitOptions{
Reference: "testcontainerapicommit:testtag",
}
@ -480,7 +480,7 @@ func (s *DockerAPISuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) {
Labels: map[string]string{"key1": "value1", "key2": "value2"},
}
options := types.ContainerCommitOptions{
options := container.CommitOptions{
Reference: "testcontainerapicommitwithconfig",
Config: &config,
}

View file

@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
@ -22,7 +22,7 @@ func TestCommitInheritsEnv(t *testing.T) {
cID1 := container.Create(ctx, t, client)
imgName := strings.ToLower(t.Name())
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
commitResp1, err := client.ContainerCommit(ctx, cID1, containertypes.CommitOptions{
Changes: []string{"ENV PATH=/bin"},
Reference: imgName,
})
@ -36,7 +36,7 @@ func TestCommitInheritsEnv(t *testing.T) {
cID2 := container.Create(ctx, t, client, container.WithImage(image1.ID))
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
commitResp2, err := client.ContainerCommit(ctx, cID2, containertypes.CommitOptions{
Changes: []string{"ENV PATH=/usr/bin:$PATH"},
Reference: imgName,
})

View file

@ -7,6 +7,7 @@ import (
"time"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/integration/internal/container"
@ -70,7 +71,7 @@ func TestImagesFilterBeforeSince(t *testing.T) {
// Make really really sure each image has a distinct timestamp.
time.Sleep(time.Millisecond)
}
id, err := client.ContainerCommit(ctx, ctr, types.ContainerCommitOptions{Reference: fmt.Sprintf("%s:v%d", name, i)})
id, err := client.ContainerCommit(ctx, ctr, containertypes.CommitOptions{Reference: fmt.Sprintf("%s:v%d", name, i)})
assert.NilError(t, err)
imgs[i] = id.ID
}

View file

@ -5,6 +5,7 @@ import (
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
@ -21,7 +22,7 @@ func TestRemoveImageOrphaning(t *testing.T) {
// Create a container from busybox, and commit a small change so we have a new image
cID1 := container.Create(ctx, t, client, container.WithCmd(""))
commitResp1, err := client.ContainerCommit(ctx, cID1, types.ContainerCommitOptions{
commitResp1, err := client.ContainerCommit(ctx, cID1, containertypes.CommitOptions{
Changes: []string{`ENTRYPOINT ["true"]`},
Reference: imgName,
})
@ -34,7 +35,7 @@ func TestRemoveImageOrphaning(t *testing.T) {
// Create a container from created image, and commit a small change with same reference name
cID2 := container.Create(ctx, t, client, container.WithImage(imgName), container.WithCmd(""))
commitResp2, err := client.ContainerCommit(ctx, cID2, types.ContainerCommitOptions{
commitResp2, err := client.ContainerCommit(ctx, cID2, containertypes.CommitOptions{
Changes: []string{`LABEL Maintainer="Integration Tests"`},
Reference: imgName,
})

View file

@ -16,7 +16,7 @@ import (
"github.com/cpuguy83/tar2go"
"github.com/docker/docker/api/types"
containerapi "github.com/docker/docker/api/types/container"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/build"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/pkg/archive"
@ -91,7 +91,7 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
cfg.Config.Cmd = []string{"true"}
})
chW, chErr := client.ContainerWait(ctx, id, containerapi.WaitConditionNotRunning)
chW, chErr := client.ContainerWait(ctx, id, containertypes.WaitConditionNotRunning)
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
@ -104,7 +104,7 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
t.Fatal("timeout waiting for container to exit")
}
res, err := client.ContainerCommit(ctx, id, types.ContainerCommitOptions{Reference: tag})
res, err := client.ContainerCommit(ctx, id, containertypes.CommitOptions{Reference: tag})
assert.NilError(t, err)
err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{Force: true})