Skip to content

Commit

Permalink
chore(deps): bump github.com/docker/docker from v25.0.5 to v26.1.4 (#…
Browse files Browse the repository at this point in the history
…2584)

* rename some variables that shadowed imports

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

* go.mod: github.com/docker/docker v26.1.4

- Update docker and dependencies
- Remove uses of deprecated API types
- Deprecate network.WithCheckDuplicate(), which is automatically set on older API versions
- Deprecate NetworkCreate.CheckDuplicate
- Remove uses of network.WithCheckDuplicate()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

* chore: run make tidy-all

* fix: update types in the registry module

* fix: more types

---------

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Co-authored-by: Manuel de la Peña <mdelapenya@gmail.com>
  • Loading branch information
thaJeztah and mdelapenya committed Jun 17, 2024
1 parent da6bcf4 commit 9adfbf9
Show file tree
Hide file tree
Showing 119 changed files with 1,643 additions and 1,689 deletions.
13 changes: 7 additions & 6 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -199,21 +200,21 @@ func newContainer(ctx context.Context, req Request) (*DockerContainer, error) {
if req.AlwaysPullImage {
shouldPullImage = true // If requested always attempt to pull image
} else {
image, _, err := cli.ImageInspectWithRaw(ctx, imageName)
img, _, err := cli.ImageInspectWithRaw(ctx, imageName)
if err != nil {
if client.IsErrNotFound(err) {
shouldPullImage = true
} else {
return nil, err
}
}
if platform != nil && (image.Architecture != platform.Architecture || image.Os != platform.OS) {
if platform != nil && (img.Architecture != platform.Architecture || img.Os != platform.OS) {
shouldPullImage = true
}
}

if shouldPullImage {
pullOpt := types.ImagePullOptions{
pullOpt := image.PullOptions{
Platform: req.ImagePlatform, // may be empty
}
if err := tcimage.Pull(ctx, imageName, req.Logger, pullOpt); err != nil {
Expand Down Expand Up @@ -392,8 +393,8 @@ func reuseOrCreateContainer(ctx context.Context, req Request) (*DockerContainer,
}

func waitContainerCreation(ctx context.Context, name string) (*types.Container, error) {
var container *types.Container
return container, backoff.Retry(func() error {
var ctr *types.Container
return ctr, backoff.Retry(func() error {
c, err := findContainerByName(ctx, name)
if err != nil {
if !errdefs.IsNotFound(err) && core.IsPermanentClientError(err) {
Expand All @@ -406,7 +407,7 @@ func waitContainerCreation(ctx context.Context, name string) (*types.Container,
return fmt.Errorf("container %s not found", name)
}

container = c
ctr = c
return nil
}, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))
}
16 changes: 8 additions & 8 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ func (s errorSubstitutor) Description() string {
}

// Substitute returns the original image, but returns an error
func (s errorSubstitutor) Substitute(image string) (string, error) {
return image, errSubstitution
func (s errorSubstitutor) Substitute(img string) (string, error) {
return img, errSubstitution
}

func TestImageSubstitutors(t *testing.T) {
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestImageSubstitutors(t *testing.T) {
Started: true,
}

container, err := testcontainers.New(ctx, req)
ctr, err := testcontainers.New(ctx, req)
if test.expectedError != nil {
require.ErrorIs(t, err, test.expectedError)
return
Expand All @@ -408,10 +408,10 @@ func TestImageSubstitutors(t *testing.T) {
t.Fatal(err)
}
defer func() {
testcontainers.TerminateContainerOnEnd(t, ctx, container)
testcontainers.TerminateContainerOnEnd(t, ctx, ctr)
}()

assert.Equal(t, test.expectedImage, container.Image)
assert.Equal(t, test.expectedImage, ctr.Image)
})
}
}
Expand All @@ -431,18 +431,18 @@ func TestShouldStartContainersInParallel(t *testing.T) {
WaitingFor: wait.ForHTTP("/").WithStartupTimeout(10 * time.Second),
Started: true,
}
container, err := testcontainers.New(ctx, req)
ctr, err := testcontainers.New(ctx, req)
if err != nil {
t.Fatalf("could not start container: %v", err)
}
// mappedPort {
port, err := container.MappedPort(ctx, nginxDefaultPort)
port, err := ctr.MappedPort(ctx, nginxDefaultPort)
// }
if err != nil {
t.Fatalf("could not get mapped port: %v", err)
}

testcontainers.TerminateContainerOnEnd(t, ctx, container)
testcontainers.TerminateContainerOnEnd(t, ctx, ctr)

t.Logf("Parallel container [iteration_%d] listening on %d\n", i, port.Int())
})
Expand Down
43 changes: 22 additions & 21 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/go-connections/nat"

tcexec "github.com/testcontainers/testcontainers-go/exec"
Expand Down Expand Up @@ -54,38 +55,38 @@ type DockerContainer struct {

// containerFromDockerResponse builds a Docker container struct from the response of the Docker API
func containerFromDockerResponse(ctx context.Context, response types.Container) (*DockerContainer, error) {
container := DockerContainer{}
ctr := DockerContainer{}

container.ID = response.ID
container.WaitingFor = nil
container.Image = response.Image
container.imageWasBuilt = false
ctr.ID = response.ID
ctr.WaitingFor = nil
ctr.Image = response.Image
ctr.imageWasBuilt = false

// TODO define a logger for the library
// container.logger = provider.Logger
container.lifecycleHooks = []LifecycleHooks{
DefaultLoggingHook(container.logger),
// ctr.logger = provider.Logger
ctr.lifecycleHooks = []LifecycleHooks{
DefaultLoggingHook(ctr.logger),
}

container.logger = log.StandardLogger() // assign the standard logger to the container
container.sessionID = core.SessionID()
container.isRunning = response.State == "running"
ctr.logger = log.StandardLogger() // assign the standard logger to the container
ctr.sessionID = core.SessionID()
ctr.isRunning = response.State == "running"

// the termination signal should be obtained from the reaper
container.terminationSignal = nil
ctr.terminationSignal = nil

// populate the raw representation of the container
_, err := container.inspectRawContainer(ctx)
_, err := ctr.inspectRawContainer(ctx)
if err != nil {
return nil, err
}

// the health status of the container, if any
if health := container.raw.State.Health; health != nil {
container.healthStatus = health.Status
if health := ctr.raw.State.Health; health != nil {
ctr.healthStatus = health.Status
}

return &container, nil
return &ctr, nil
}

// ContainerIP gets the IP address of the primary network within the container.
Expand Down Expand Up @@ -332,12 +333,12 @@ func (c *DockerContainer) Exec(ctx context.Context, cmd []string, options ...tce
}

func (c *DockerContainer) GetImage() string {
json, err := c.inspectRawContainer(context.Background())
jsonRaw, err := c.inspectRawContainer(context.Background())
if err != nil {
return ""
}

return json.Config.Image
return jsonRaw.Config.Image
}

// Host gets host (ip or name) of the docker daemon where the container port is exposed
Expand All @@ -357,12 +358,12 @@ func (c *DockerContainer) Inspect(ctx context.Context) (*types.ContainerJSON, er
return c.raw, nil
}

json, err := c.inspectRawContainer(ctx)
jsonRaw, err := c.inspectRawContainer(ctx)
if err != nil {
return nil, err
}

return json, nil
return jsonRaw, nil
}

// update container raw info
Expand Down Expand Up @@ -682,7 +683,7 @@ func (c *DockerContainer) Terminate(ctx context.Context) error {
}

if c.imageWasBuilt && !c.keepBuiltImage {
_, err := cli.ImageRemove(ctx, c.Image, types.ImageRemoveOptions{
_, err := cli.ImageRemove(ctx, c.Image, image.RemoveOptions{
Force: true,
PruneChildren: true,
})
Expand Down
8 changes: 4 additions & 4 deletions docker_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/stretchr/testify/require"

Expand All @@ -32,7 +32,7 @@ func TestBuildContainerFromDockerfile(t *testing.T) {
}

// removeImageFromLocalCache removes the image from the local cache
func removeImageFromLocalCache(t *testing.T, image string) {
func removeImageFromLocalCache(t *testing.T, img string) {
ctx := context.Background()

testcontainersClient, err := core.NewClient(ctx, client.WithVersion(daemonMaxVersion))
Expand All @@ -41,12 +41,12 @@ func removeImageFromLocalCache(t *testing.T, image string) {
}
defer testcontainersClient.Close()

_, err = testcontainersClient.ImageRemove(ctx, image, types.ImageRemoveOptions{
_, err = testcontainersClient.ImageRemove(ctx, img, image.RemoveOptions{
Force: true,
PruneChildren: true,
})
if err != nil {
t.Logf("could not remove image %s: %v\n", image, err)
t.Logf("could not remove image %s: %v\n", img, err)
}
}

Expand Down
10 changes: 5 additions & 5 deletions docker_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/docker/docker/api/types"

"github.com/testcontainers/testcontainers-go/image"
tcimage "github.com/testcontainers/testcontainers-go/image"
"github.com/testcontainers/testcontainers-go/network"
"github.com/testcontainers/testcontainers-go/wait"
)
Expand Down Expand Up @@ -248,9 +248,9 @@ func ExampleNew_withSubstitutors() {
ctx := context.Background()

// applyImageSubstitutors {
container, err := New(ctx, Request{
ctr, err := New(ctx, Request{
Image: "alpine:latest",
ImageSubstitutors: []image.Substitutor{image.DockerSubstitutor{}},
ImageSubstitutors: []tcimage.Substitutor{tcimage.DockerSubstitutor{}},
Started: true,
})
// }
Expand All @@ -259,13 +259,13 @@ func ExampleNew_withSubstitutors() {
}

defer func() {
err := container.Terminate(ctx)
err := ctr.Terminate(ctx)
if err != nil {
log.Fatalf("could not terminate container: %v", err)
}
}()

fmt.Println(container.Image)
fmt.Println(ctr.Image)

// Output: docker.io/alpine:latest
}
18 changes: 9 additions & 9 deletions docker_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func TestExecWithOptions(t *testing.T) {
Started: true,
}

container, err := New(ctx, req)
ctr, err := New(ctx, req)
require.NoError(t, err)
TerminateContainerOnEnd(t, ctx, container)
TerminateContainerOnEnd(t, ctx, ctr)

// always append the multiplexed option for having the output
// in a readable format
tt.opts = append(tt.opts, tcexec.Multiplexed())

code, reader, err := container.Exec(ctx, tt.cmds, tt.opts...)
code, reader, err := ctr.Exec(ctx, tt.cmds, tt.opts...)
require.NoError(t, err)
require.Zero(t, code)
require.NotNil(t, reader)
Expand All @@ -82,11 +82,11 @@ func TestExecWithMultiplexedResponse(t *testing.T) {
Started: true,
}

container, err := New(ctx, req)
ctr, err := New(ctx, req)
require.NoError(t, err)
TerminateContainerOnEnd(t, ctx, container)
TerminateContainerOnEnd(t, ctx, ctr)

code, reader, err := container.Exec(ctx, []string{"sh", "-c", "echo stdout; echo stderr >&2"}, tcexec.Multiplexed())
code, reader, err := ctr.Exec(ctx, []string{"sh", "-c", "echo stdout; echo stderr >&2"}, tcexec.Multiplexed())
require.NoError(t, err)
require.Zero(t, code)
require.NotNil(t, reader)
Expand All @@ -107,11 +107,11 @@ func TestExecWithNonMultiplexedResponse(t *testing.T) {
Started: true,
}

container, err := New(ctx, req)
ctr, err := New(ctx, req)
require.NoError(t, err)
TerminateContainerOnEnd(t, ctx, container)
TerminateContainerOnEnd(t, ctx, ctr)

code, reader, err := container.Exec(ctx, []string{"sh", "-c", "echo stdout; echo stderr >&2"})
code, reader, err := ctr.Exec(ctx, []string{"sh", "-c", "echo stdout; echo stderr >&2"})
require.NoError(t, err)
require.Zero(t, code)
require.NotNil(t, reader)
Expand Down
Loading

0 comments on commit 9adfbf9

Please sign in to comment.