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 15, 2024
1 parent dd7d7a9 commit 9a93db4
Show file tree
Hide file tree
Showing 103 changed files with 1,592 additions and 1,632 deletions.
86 changes: 43 additions & 43 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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 @@ -171,12 +172,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
}

// MappedPort gets externally mapped port for a container port
Expand Down Expand Up @@ -307,7 +308,7 @@ func (c *DockerContainer) Terminate(ctx context.Context) error {
}

if c.imageWasBuilt && !c.keepBuiltImage {
_, err := c.provider.client.ImageRemove(ctx, c.Image, types.ImageRemoveOptions{
_, err := c.provider.client.ImageRemove(ctx, c.Image, image.RemoveOptions{
Force: true,
PruneChildren: true,
})
Expand Down Expand Up @@ -1056,21 +1057,21 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
if req.AlwaysPullImage {
shouldPullImage = true // If requested always attempt to pull image
} else {
image, _, err := p.client.ImageInspectWithRaw(ctx, imageName)
img, _, err := p.client.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 := p.attemptToPullImage(ctx, imageName, pullOpt); err != nil {
Expand Down Expand Up @@ -1202,8 +1203,8 @@ func (p *DockerProvider) findContainerByName(ctx context.Context, name string) (
}

func (p *DockerProvider) 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 := p.findContainerByName(ctx, name)
if err != nil {
if !errdefs.IsNotFound(err) && isPermanentClientError(err) {
Expand All @@ -1216,7 +1217,7 @@ func (p *DockerProvider) waitContainerCreation(ctx context.Context, name string)
return fmt.Errorf("container %s not found", name)
}

container = c
ctr = c
return nil
}, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))
}
Expand Down Expand Up @@ -1291,7 +1292,7 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain

// attemptToPullImage tries to pull the image while respecting the ctx cancellations.
// Besides, if the image cannot be pulled due to ErrorNotFound then no need to retry but terminate immediately.
func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt types.ImagePullOptions) error {
func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt image.PullOptions) error {
registry, imageAuth, err := DockerImageAuth(ctx, tag)
if err != nil {
p.Logger.Printf("Failed to get image auth for %s. Setting empty credentials for the image: %s. Error is:%s", registry, tag, err)
Expand Down Expand Up @@ -1377,15 +1378,15 @@ func daemonHost(ctx context.Context, p *DockerProvider) (string, error) {
}

// infer from Docker host
url, err := url.Parse(p.client.DaemonHost())
daemonURL, err := url.Parse(p.client.DaemonHost())
if err != nil {
return "", err
}
defer p.Close()

switch url.Scheme {
switch daemonURL.Scheme {
case "http", "https", "tcp":
p.hostCache = url.Hostname()
p.hostCache = daemonURL.Hostname()
case "unix", "npipe":
if core.InAContainer() {
ip, err := p.GetGatewayIP(ctx)
Expand Down Expand Up @@ -1429,13 +1430,12 @@ func (p *DockerProvider) CreateNetwork(ctx context.Context, req NetworkRequest)
tcConfig := p.Config().Config

nc := types.NetworkCreate{
Driver: req.Driver,
CheckDuplicate: req.CheckDuplicate,
Internal: req.Internal,
EnableIPv6: req.EnableIPv6,
Attachable: req.Attachable,
Labels: req.Labels,
IPAM: req.IPAM,
Driver: req.Driver,
Internal: req.Internal,
EnableIPv6: req.EnableIPv6,
Attachable: req.Attachable,
Labels: req.Labels,
IPAM: req.IPAM,
}

sessionID := core.SessionID()
Expand Down Expand Up @@ -1510,9 +1510,9 @@ func (p *DockerProvider) GetGatewayIP(ctx context.Context) (string, error) {
}

var ip string
for _, config := range nw.IPAM.Config {
if config.Gateway != "" {
ip = config.Gateway
for _, cfg := range nw.IPAM.Config {
if cfg.Gateway != "" {
ip = cfg.Gateway
break
}
}
Expand Down Expand Up @@ -1566,46 +1566,46 @@ func containerFromDockerResponse(ctx context.Context, response types.Container)
return nil, err
}

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

container.logger = provider.Logger
container.lifecycleHooks = []ContainerLifecycleHooks{
DefaultLoggingHook(container.logger),
ctr.logger = provider.Logger
ctr.lifecycleHooks = []ContainerLifecycleHooks{
DefaultLoggingHook(ctr.logger),
}
container.provider = provider
ctr.provider = provider

container.sessionID = core.SessionID()
container.consumers = []LogConsumer{}
container.isRunning = response.State == "running"
ctr.sessionID = core.SessionID()
ctr.consumers = []LogConsumer{}
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
}

// ListImages list images from the provider. If an image has multiple Tags, each tag is reported
// individually with the same ID and same labels
func (p *DockerProvider) ListImages(ctx context.Context) ([]ImageInfo, error) {
images := []ImageInfo{}

imageList, err := p.client.ImageList(ctx, types.ImageListOptions{})
imageList, err := p.client.ImageList(ctx, image.ListOptions{})
if err != nil {
return images, fmt.Errorf("listing images %w", err)
}
Expand Down Expand Up @@ -1647,8 +1647,8 @@ func (p *DockerProvider) SaveImages(ctx context.Context, output string, images .
}

// PullImage pulls image from registry
func (p *DockerProvider) PullImage(ctx context.Context, image string) error {
return p.attemptToPullImage(ctx, image, types.ImagePullOptions{})
func (p *DockerProvider) PullImage(ctx context.Context, img string) error {
return p.attemptToPullImage(ctx, img, image.PullOptions{})
}

var permanentClientErrors = []func(error) bool{
Expand Down
8 changes: 4 additions & 4 deletions docker_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/cpuguy83/dockercfg"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -204,7 +204,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 := NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion))
Expand All @@ -213,12 +213,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

0 comments on commit 9a93db4

Please sign in to comment.