Skip to content

Commit 6df128d

Browse files
committed
WIP - Update to moby 29.0.0 api/client
Signed-off-by: Rob Murray <[email protected]>
1 parent 0a1aaf5 commit 6df128d

File tree

118 files changed

+918
-1137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+918
-1137
lines changed

client/client.container.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import (
55
"fmt"
66

77
"github.com/containerd/errdefs"
8+
"github.com/moby/moby/api/types/container"
9+
"github.com/moby/moby/api/types/network"
10+
"github.com/moby/moby/client"
811
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
9-
10-
"github.com/docker/docker/api/types/container"
11-
"github.com/docker/docker/api/types/filters"
12-
"github.com/docker/docker/api/types/network"
1312
)
1413

1514
// ContainerCreate creates a new container.
@@ -27,8 +26,10 @@ func (c *sdkClient) FindContainerByName(ctx context.Context, name string) (*cont
2726
}
2827

2928
// Note that, 'name' filter will use regex to find the containers
30-
filter := filters.NewArgs(filters.Arg("name", fmt.Sprintf("^%s$", name)))
31-
containers, err := c.ContainerList(ctx, container.ListOptions{All: true, Filters: filter})
29+
containers, err := c.ContainerList(ctx, client.ContainerListOptions{
30+
All: true,
31+
Filters: make(client.Filters).Add("name", "^"+name+"$"),
32+
})
3233
if err != nil {
3334
return nil, fmt.Errorf("container list: %w", err)
3435
}

client/client.container_benchmarks_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"sync"
88
"testing"
99

10+
dockerclient "github.com/moby/moby/client"
1011
"github.com/stretchr/testify/require"
1112

12-
"github.com/docker/docker/api/types/container"
1313
"github.com/docker/go-sdk/client"
1414
)
1515

@@ -42,7 +42,7 @@ func BenchmarkContainerList(b *testing.B) {
4242
b.ReportAllocs()
4343
b.RunParallel(func(pb *testing.PB) {
4444
for pb.Next() {
45-
_, err := dockerClient.ContainerList(context.Background(), container.ListOptions{All: true})
45+
_, err := dockerClient.ContainerList(context.Background(), dockerclient.ContainerListOptions{All: true})
4646
require.NoError(b, err)
4747
}
4848
})
@@ -73,7 +73,7 @@ func BenchmarkContainerPause(b *testing.B) {
7373
createContainer(b, dockerClient, img, containerName)
7474

7575
b.Run("container-pause-unpause", func(b *testing.B) {
76-
err = dockerClient.ContainerStart(context.Background(), containerName, container.StartOptions{})
76+
err = dockerClient.ContainerStart(context.Background(), containerName, dockerclient.ContainerStartOptions{})
7777
require.NoError(b, err)
7878

7979
b.ResetTimer()

client/client.container_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"testing"
99

1010
"github.com/containerd/errdefs"
11+
"github.com/moby/moby/api/types/container"
12+
"github.com/moby/moby/api/types/network"
13+
dockerclient "github.com/moby/moby/client"
1114
"github.com/stretchr/testify/require"
1215

13-
"github.com/docker/docker/api/types/container"
14-
"github.com/docker/docker/api/types/image"
15-
"github.com/docker/go-connections/nat"
1616
"github.com/docker/go-sdk/client"
1717
)
1818

@@ -40,7 +40,7 @@ func TestContainerList(t *testing.T) {
4040

4141
wg.Wait()
4242

43-
containers, err := dockerClient.ContainerList(context.Background(), container.ListOptions{All: true})
43+
containers, err := dockerClient.ContainerList(context.Background(), dockerclient.ContainerListOptions{All: true})
4444
require.NoError(t, err)
4545
require.NotEmpty(t, containers)
4646
require.Len(t, containers, max)
@@ -84,7 +84,7 @@ func TestContainerPause(t *testing.T) {
8484
pullImage(t, dockerClient, img)
8585
createContainer(t, dockerClient, img, "nginx-test-pause")
8686

87-
err = dockerClient.ContainerStart(context.Background(), "nginx-test-pause", container.StartOptions{})
87+
err = dockerClient.ContainerStart(context.Background(), "nginx-test-pause", dockerclient.ContainerStartOptions{})
8888
require.NoError(t, err)
8989

9090
err = dockerClient.ContainerPause(context.Background(), "nginx-test-pause")
@@ -99,24 +99,24 @@ func createContainer(tb testing.TB, dockerClient client.SDKClient, img string, n
9999

100100
resp, err := dockerClient.ContainerCreate(context.Background(), &container.Config{
101101
Image: img,
102-
ExposedPorts: nat.PortSet{
103-
"80/tcp": {},
102+
ExposedPorts: network.PortSet{
103+
network.MustParsePort("80/tcp"): {},
104104
},
105105
}, nil, nil, nil, name)
106106
require.NoError(tb, err)
107107
require.NotNil(tb, resp)
108108
require.NotEmpty(tb, resp.ID)
109109

110110
tb.Cleanup(func() {
111-
err := dockerClient.ContainerRemove(context.Background(), resp.ID, container.RemoveOptions{Force: true})
111+
err := dockerClient.ContainerRemove(context.Background(), resp.ID, dockerclient.ContainerRemoveOptions{Force: true})
112112
require.NoError(tb, err)
113113
})
114114
}
115115

116116
func pullImage(tb testing.TB, client client.SDKClient, img string) {
117117
tb.Helper()
118118

119-
r, err := client.ImagePull(context.Background(), img, image.PullOptions{})
119+
r, err := client.ImagePull(context.Background(), img, dockerclient.ImagePullOptions{})
120120
require.NoError(tb, err)
121121
defer r.Close()
122122

client/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"path/filepath"
1010
"time"
1111

12-
"github.com/docker/docker/client"
12+
"github.com/moby/moby/client"
13+
1314
dockercontext "github.com/docker/go-sdk/context"
1415
)
1516

@@ -34,7 +35,7 @@ var (
3435
return func(c SDKClient) error {
3536
var pingErr error
3637
for i := range 3 {
37-
if _, pingErr = c.Ping(ctx); pingErr == nil {
38+
if _, pingErr = c.Ping(ctx, client.PingOptions{}); pingErr == nil {
3839
return nil
3940
}
4041
select {

client/client.image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"context"
55
"io"
66

7-
"github.com/docker/docker/api/types/build"
7+
"github.com/moby/moby/client"
88
)
99

1010
// ImageBuild builds an image from a build context and options.
11-
func (c *sdkClient) ImageBuild(ctx context.Context, context io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error) {
11+
func (c *sdkClient) ImageBuild(ctx context.Context, context io.Reader, options client.ImageBuildOptions) (client.ImageBuildResult, error) {
1212
// Add client labels
1313
AddSDKLabels(options.Labels)
1414

client/client.network.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package client
33
import (
44
"context"
55

6-
"github.com/docker/docker/api/types/network"
6+
"github.com/moby/moby/api/types/network"
7+
"github.com/moby/moby/client"
78
)
89

910
// NetworkCreate creates a new network
10-
func (c *sdkClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
11+
func (c *sdkClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) {
1112
// Add the labels that identify this as a network created by the SDK.
1213
AddSDKLabels(options.Labels)
1314

client/client.volume.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package client
33
import (
44
"context"
55

6-
"github.com/docker/docker/api/types/volume"
6+
"github.com/moby/moby/client"
77
)
88

99
// VolumeCreate creates a new volume.
10-
func (c *sdkClient) VolumeCreate(ctx context.Context, options volume.CreateOptions) (volume.Volume, error) {
10+
func (c *sdkClient) VolumeCreate(ctx context.Context, options client.VolumeCreateOptions) (client.VolumeCreateResult, error) {
1111
// Add the labels that identify this as a volume created by the SDK.
1212
AddSDKLabels(options.Labels)
1313

client/client_benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"testing"
66

7+
dockerclient "github.com/moby/moby/client"
78
"github.com/stretchr/testify/require"
89

9-
dockerclient "github.com/docker/docker/client"
1010
"github.com/docker/go-sdk/client"
1111
)
1212

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"path/filepath"
66
"testing"
77

8+
dockerclient "github.com/moby/moby/client"
89
"github.com/stretchr/testify/require"
910

10-
dockerclient "github.com/docker/docker/client"
1111
"github.com/docker/go-sdk/client"
1212
dockercontext "github.com/docker/go-sdk/context"
1313
)

client/daemon.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package client
33
import (
44
"context"
55
"errors"
6+
"net/netip"
67
"net/url"
78
"os"
89

9-
"github.com/docker/docker/api/types/network"
10+
"github.com/moby/moby/client"
1011
)
1112

1213
// dockerEnvFile is the file that is created when running inside a container.
1314
// It's a variable to allow testing.
1415
var dockerEnvFile = "/.dockerenv"
1516

16-
// DaemonHost gets the host or ip of the Docker daemon where ports are exposed on
17+
// DaemonHostWithContext gets the host or ip of the Docker daemon where ports are exposed on
1718
// Warning: this is based on your Docker host setting. Will fail if using an SSH tunnel
1819
func (c *sdkClient) DaemonHostWithContext(ctx context.Context) (string, error) {
1920
c.mtx.Lock()
@@ -38,9 +39,10 @@ func (c *sdkClient) daemonHostLocked(ctx context.Context) (string, error) {
3839
if inAContainer(dockerEnvFile) {
3940
ip, err := c.getGatewayIP(ctx, "bridge")
4041
if err != nil {
41-
ip = "localhost"
42+
host = "localhost"
43+
} else {
44+
host = ip.String()
4245
}
43-
host = ip
4446
} else {
4547
host = "localhost"
4648
}
@@ -51,21 +53,21 @@ func (c *sdkClient) daemonHostLocked(ctx context.Context) (string, error) {
5153
return host, nil
5254
}
5355

54-
func (c *sdkClient) getGatewayIP(ctx context.Context, defaultNetwork string) (string, error) {
55-
nw, err := c.NetworkInspect(ctx, defaultNetwork, network.InspectOptions{})
56+
func (c *sdkClient) getGatewayIP(ctx context.Context, defaultNetwork string) (netip.Addr, error) {
57+
nw, err := c.NetworkInspect(ctx, defaultNetwork, client.NetworkInspectOptions{})
5658
if err != nil {
57-
return "", err
59+
return netip.Addr{}, err
5860
}
5961

60-
var ip string
61-
for _, cfg := range nw.IPAM.Config {
62-
if cfg.Gateway != "" {
62+
var ip netip.Addr
63+
for _, cfg := range nw.Network.IPAM.Config {
64+
if cfg.Gateway.IsValid() {
6365
ip = cfg.Gateway
6466
break
6567
}
6668
}
67-
if ip == "" {
68-
return "", errors.New("failed to get gateway IP from network settings")
69+
if !ip.IsValid() {
70+
return netip.Addr{}, errors.New("failed to get gateway IP from network settings")
6971
}
7072

7173
return ip, nil

0 commit comments

Comments
 (0)