Skip to content

Commit 2f74185

Browse files
authored
chore: update docker to v27.3.1 (#109)
1 parent 7e87bc0 commit 2f74185

File tree

14 files changed

+151
-137
lines changed

14 files changed

+151
-137
lines changed

cli/clitest/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Mounter(ctx context.Context) *mount.FakeMounter {
3535
func DockerClient(t *testing.T, ctx context.Context) *dockerfake.MockClient {
3636
t.Helper()
3737

38-
client, err := dockerutil.Client(ctx)
38+
client, err := dockerutil.ExtractClient(ctx)
3939
require.NoError(t, err)
4040
//nolint we should panic if this isn't the case.
4141
return client.(*dockerfake.MockClient)
@@ -71,7 +71,7 @@ func New(t *testing.T, cmd string, args ...string) (context.Context, *cobra.Comm
7171
return ctx, root
7272
}
7373

74-
func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.DockerClient) context.Context {
74+
func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.Client) context.Context {
7575
t.Helper()
7676

7777
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)

cli/clitest/fake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewFakeExecer() *xunixfake.FakeExec {
3030
}
3131
}
3232

33-
func NewFakeDockerClient() dockerutil.DockerClient {
33+
func NewFakeDockerClient() dockerutil.Client {
3434
client := &dockerfake.MockClient{}
3535

3636
client.ContainerInspectFn = func(_ context.Context, _ string) (dockertypes.ContainerJSON, error) {

cli/docker.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"strconv"
1414
"strings"
1515

16-
dockertypes "github.com/docker/docker/api/types"
1716
"github.com/docker/docker/api/types/container"
1817
"github.com/google/go-containerregistry/pkg/name"
1918
"github.com/spf13/cobra"
@@ -244,7 +243,7 @@ func dockerCmd() *cobra.Command {
244243
return xerrors.Errorf("wait for sysbox-mgr: %w", err)
245244
}
246245

247-
client, err := dockerutil.Client(ctx)
246+
client, err := dockerutil.ExtractClient(ctx)
248247
if err != nil {
249248
return xerrors.Errorf("new docker client: %w", err)
250249
}
@@ -388,7 +387,7 @@ func dockerCmd() *cobra.Command {
388387
return cmd
389388
}
390389

391-
func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.DockerClient, blog buildlog.Logger, flags flags) error {
390+
func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Client, blog buildlog.Logger, flags flags) error {
392391
fs := xunix.GetFS(ctx)
393392

394393
// Set our OOM score to something really unfavorable to avoid getting killed
@@ -664,7 +663,7 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
664663
// TODO fix iptables when istio detected.
665664

666665
blog.Info("Starting up workspace...")
667-
err = client.ContainerStart(ctx, containerID, dockertypes.ContainerStartOptions{})
666+
err = client.ContainerStart(ctx, containerID, container.StartOptions{})
668667
if err != nil {
669668
return xerrors.Errorf("start container: %w", err)
670669
}

cli/docker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
dockertypes "github.com/docker/docker/api/types"
1717
"github.com/docker/docker/api/types/container"
18+
"github.com/docker/docker/api/types/image"
1819
"github.com/docker/docker/api/types/network"
1920
v1 "github.com/opencontainers/image-spec/specs-go/v1"
2021
"github.com/spf13/afero"
@@ -486,7 +487,7 @@ func TestDocker(t *testing.T) {
486487
authB64 := base64.URLEncoding.EncodeToString(raw)
487488

488489
client := clitest.DockerClient(t, ctx)
489-
client.ImagePullFn = func(_ context.Context, _ string, options dockertypes.ImagePullOptions) (io.ReadCloser, error) {
490+
client.ImagePullFn = func(_ context.Context, _ string, options image.PullOptions) (io.ReadCloser, error) {
490491
// Assert that we call the image pull function with the credentials.
491492
require.Equal(t, authB64, options.RegistryAuth)
492493
return io.NopCloser(bytes.NewReader(nil)), nil

deploy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LABEL \
2222
ARG DEBIAN_FRONTEND=noninteractive
2323
# Pin docker to avoid any breaking API changes between the Go client and
2424
# the server.
25-
ARG DOCKER_VERSION="5:27.1.2-1~ubuntu.22.04~jammy"
25+
ARG DOCKER_VERSION="5:27.3.1-1~ubuntu.22.04~jammy"
2626
# Ignore other repositories, as some require HTTPS
2727
RUN apt-get update --quiet --option Dir::Etc::SourceParts="" && \
2828
apt-get upgrade -y && \

dockerutil/client.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@ import (
77
"os"
88

99
"github.com/cpuguy83/dockercfg"
10-
dockertypes "github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/registry"
1111
dockerclient "github.com/docker/docker/client"
1212

1313
"golang.org/x/xerrors"
1414
)
1515

16+
type Client interface {
17+
dockerclient.SystemAPIClient
18+
dockerclient.ContainerAPIClient
19+
dockerclient.ImageAPIClient
20+
}
21+
1622
type clientKey struct{}
1723

1824
// WithClient sets the provided DockerClient on the context.
1925
// It should only be used for tests.
20-
func WithClient(ctx context.Context, client DockerClient) context.Context {
26+
func WithClient(ctx context.Context, client Client) context.Context {
2127
return context.WithValue(ctx, clientKey{}, client)
2228
}
2329

24-
// Client returns the DockerClient set on the context. If one can't be
30+
// ExtractClient returns the DockerClient set on the context. If one can't be
2531
// found a default client is returned.
26-
func Client(ctx context.Context) (DockerClient, error) {
32+
func ExtractClient(ctx context.Context) (Client, error) {
2733
client := ctx.Value(clientKey{})
2834
if client == nil {
2935
client, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv)
@@ -35,10 +41,10 @@ func Client(ctx context.Context) (DockerClient, error) {
3541
}
3642

3743
//nolint we should panic if this isn't the case.
38-
return client.(DockerClient), nil
44+
return client.(Client), nil
3945
}
4046

41-
type AuthConfig dockertypes.AuthConfig
47+
type AuthConfig registry.AuthConfig
4248

4349
func (a AuthConfig) Base64() (string, error) {
4450
authStr, err := json.Marshal(a)
@@ -67,8 +73,8 @@ func AuthConfigFromString(raw string, reg string) (AuthConfig, error) {
6773
return parseConfig(cfg, reg)
6874
}
6975

70-
func parseConfig(cfg dockercfg.Config, registry string) (AuthConfig, error) {
71-
hostname := dockercfg.ResolveRegistryHost(registry)
76+
func parseConfig(cfg dockercfg.Config, reg string) (AuthConfig, error) {
77+
hostname := dockercfg.ResolveRegistryHost(reg)
7278

7379
username, secret, err := cfg.GetRegistryCredentials(hostname)
7480
if err != nil {
@@ -87,5 +93,5 @@ func parseConfig(cfg dockercfg.Config, registry string) (AuthConfig, error) {
8793
}, nil
8894
}
8995

90-
return AuthConfig{}, xerrors.Errorf("no auth config found for registry %s: %w", registry, os.ErrNotExist)
96+
return AuthConfig{}, xerrors.Errorf("no auth config found for registry %s: %w", reg, os.ErrNotExist)
9197
}

dockerutil/container.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/docker/docker/api/types/container"
13-
dockerclient "github.com/docker/docker/client"
1413
"github.com/spf13/afero"
1514
"golang.org/x/xerrors"
1615

@@ -25,12 +24,6 @@ const (
2524
DefaultCPUPeriod uint64 = 1e5
2625
)
2726

28-
type DockerClient interface {
29-
dockerclient.SystemAPIClient
30-
dockerclient.ContainerAPIClient
31-
dockerclient.ImageAPIClient
32-
}
33-
3427
type ContainerConfig struct {
3528
Log slog.Logger
3629
Mounts []xunix.Mount
@@ -48,7 +41,7 @@ type ContainerConfig struct {
4841
}
4942

5043
// CreateContainer creates a sysbox-runc container.
51-
func CreateContainer(ctx context.Context, client DockerClient, conf *ContainerConfig) (string, error) {
44+
func CreateContainer(ctx context.Context, client Client, conf *ContainerConfig) (string, error) {
5245
host := &container.HostConfig{
5346
Runtime: runtime,
5447
AutoRemove: true,
@@ -106,7 +99,7 @@ type BootstrapConfig struct {
10699

107100
// BoostrapContainer runs a script inside the container as the provided user.
108101
// If conf.Script is empty then it is a noop.
109-
func BootstrapContainer(ctx context.Context, client DockerClient, conf BootstrapConfig) error {
102+
func BootstrapContainer(ctx context.Context, client Client, conf BootstrapConfig) error {
110103
if conf.Script == "" {
111104
return nil
112105
}

dockerutil/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
// WaitForDaemon waits for a Docker daemon to startup. It waits a max
1111
// of 5m before giving up.
12-
func WaitForDaemon(ctx context.Context, client DockerClient) error {
12+
func WaitForDaemon(ctx context.Context, client Client) error {
1313
ticker := time.NewTicker(time.Millisecond * 250)
1414
defer ticker.Stop()
1515

dockerutil/dockerfake/client.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,26 @@ import (
1212
"github.com/docker/docker/api/types/image"
1313
networktypes "github.com/docker/docker/api/types/network"
1414
"github.com/docker/docker/api/types/registry"
15+
"github.com/docker/docker/api/types/system"
1516
specs "github.com/opencontainers/image-spec/specs-go/v1"
1617

1718
"github.com/coder/envbox/dockerutil"
1819
)
1920

20-
var _ dockerutil.DockerClient = MockClient{}
21+
var _ dockerutil.Client = MockClient{}
2122

2223
// MockClient provides overrides for functions that are called in envbox.
2324
type MockClient struct {
24-
ImagePullFn func(_ context.Context, ref string, options dockertypes.ImagePullOptions) (io.ReadCloser, error)
25+
ImagePullFn func(_ context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
2526
ContainerCreateFn func(_ context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, _ *specs.Platform, containerName string) (containertypes.CreateResponse, error)
2627
ImagePruneFn func(_ context.Context, pruneFilter filters.Args) (dockertypes.ImagesPruneReport, error)
27-
ContainerStartFn func(_ context.Context, container string, options dockertypes.ContainerStartOptions) error
28+
ContainerStartFn func(_ context.Context, container string, options containertypes.StartOptions) error
2829
ContainerExecAttachFn func(_ context.Context, execID string, config dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error)
2930
ContainerExecCreateFn func(_ context.Context, container string, config dockertypes.ExecConfig) (dockertypes.IDResponse, error)
3031
ContainerExecStartFn func(_ context.Context, execID string, config dockertypes.ExecStartCheck) error
3132
ContainerExecInspectFn func(_ context.Context, execID string) (dockertypes.ContainerExecInspect, error)
3233
ContainerInspectFn func(_ context.Context, container string) (dockertypes.ContainerJSON, error)
33-
ContainerRemoveFn func(_ context.Context, container string, options dockertypes.ContainerRemoveOptions) error
34+
ContainerRemoveFn func(_ context.Context, container string, options containertypes.RemoveOptions) error
3435
PingFn func(_ context.Context) (dockertypes.Ping, error)
3536
}
3637

@@ -46,42 +47,42 @@ func (MockClient) BuildCancel(_ context.Context, _ string) error {
4647
panic("not implemented")
4748
}
4849

49-
func (MockClient) ImageCreate(_ context.Context, _ string, _ dockertypes.ImageCreateOptions) (io.ReadCloser, error) {
50+
func (MockClient) ImageCreate(_ context.Context, _ string, _ image.CreateOptions) (io.ReadCloser, error) {
5051
panic("not implemented")
5152
}
5253

5354
func (MockClient) ImageHistory(_ context.Context, _ string) ([]image.HistoryResponseItem, error) {
5455
panic("not implemented")
5556
}
5657

57-
func (MockClient) ImageImport(_ context.Context, _ dockertypes.ImageImportSource, _ string, _ dockertypes.ImageImportOptions) (io.ReadCloser, error) {
58+
func (MockClient) ImageImport(_ context.Context, _ image.ImportSource, _ string, _ image.ImportOptions) (io.ReadCloser, error) {
5859
panic("not implemented")
5960
}
6061

6162
func (MockClient) ImageInspectWithRaw(_ context.Context, _ string) (dockertypes.ImageInspect, []byte, error) {
6263
panic("not implemented")
6364
}
6465

65-
func (MockClient) ImageList(_ context.Context, _ dockertypes.ImageListOptions) ([]dockertypes.ImageSummary, error) {
66+
func (MockClient) ImageList(_ context.Context, _ image.ListOptions) ([]image.Summary, error) {
6667
panic("not implemented")
6768
}
6869

6970
func (MockClient) ImageLoad(_ context.Context, _ io.Reader, _ bool) (dockertypes.ImageLoadResponse, error) {
7071
panic("not implemented")
7172
}
7273

73-
func (m MockClient) ImagePull(ctx context.Context, ref string, options dockertypes.ImagePullOptions) (io.ReadCloser, error) {
74+
func (m MockClient) ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error) {
7475
if m.ImagePullFn == nil {
7576
return io.NopCloser(strings.NewReader("")), nil
7677
}
7778
return m.ImagePullFn(ctx, ref, options)
7879
}
7980

80-
func (MockClient) ImagePush(_ context.Context, _ string, _ dockertypes.ImagePushOptions) (io.ReadCloser, error) {
81+
func (MockClient) ImagePush(_ context.Context, _ string, _ image.PushOptions) (io.ReadCloser, error) {
8182
panic("not implemented")
8283
}
8384

84-
func (MockClient) ImageRemove(_ context.Context, _ string, _ dockertypes.ImageRemoveOptions) ([]dockertypes.ImageDeleteResponseItem, error) {
85+
func (MockClient) ImageRemove(_ context.Context, _ string, _ image.RemoveOptions) ([]image.DeleteResponse, error) {
8586
panic("not implemented")
8687
}
8788

@@ -108,11 +109,11 @@ func (MockClient) Events(_ context.Context, _ dockertypes.EventsOptions) (<-chan
108109
panic("not implemented")
109110
}
110111

111-
func (MockClient) Info(_ context.Context) (dockertypes.Info, error) {
112+
func (MockClient) Info(_ context.Context) (system.Info, error) {
112113
panic("not implemented")
113114
}
114115

115-
func (MockClient) RegistryLogin(_ context.Context, _ dockertypes.AuthConfig) (registry.AuthenticateOKBody, error) {
116+
func (MockClient) RegistryLogin(_ context.Context, _ registry.AuthConfig) (registry.AuthenticateOKBody, error) {
116117
panic("not implemented")
117118
}
118119

@@ -127,11 +128,11 @@ func (m MockClient) Ping(ctx context.Context) (dockertypes.Ping, error) {
127128
return m.PingFn(ctx)
128129
}
129130

130-
func (MockClient) ContainerAttach(_ context.Context, _ string, _ dockertypes.ContainerAttachOptions) (dockertypes.HijackedResponse, error) {
131+
func (MockClient) ContainerAttach(_ context.Context, _ string, _ containertypes.AttachOptions) (dockertypes.HijackedResponse, error) {
131132
panic("not implemented")
132133
}
133134

134-
func (MockClient) ContainerCommit(_ context.Context, _ string, _ dockertypes.ContainerCommitOptions) (dockertypes.IDResponse, error) {
135+
func (MockClient) ContainerCommit(_ context.Context, _ string, _ containertypes.CommitOptions) (dockertypes.IDResponse, error) {
135136
panic("not implemented")
136137
}
137138

@@ -142,7 +143,7 @@ func (m MockClient) ContainerCreate(ctx context.Context, config *containertypes.
142143
return m.ContainerCreateFn(ctx, config, hostConfig, networkingConfig, pspecs, containerName)
143144
}
144145

145-
func (MockClient) ContainerDiff(_ context.Context, _ string) ([]containertypes.ContainerChangeResponseItem, error) {
146+
func (MockClient) ContainerDiff(_ context.Context, _ string) ([]containertypes.FilesystemChange, error) {
146147
panic("not implemented")
147148
}
148149

@@ -168,7 +169,7 @@ func (m MockClient) ContainerExecInspect(ctx context.Context, id string) (docker
168169
return m.ContainerExecInspectFn(ctx, id)
169170
}
170171

171-
func (MockClient) ContainerExecResize(_ context.Context, _ string, _ dockertypes.ResizeOptions) error {
172+
func (MockClient) ContainerExecResize(_ context.Context, _ string, _ containertypes.ResizeOptions) error {
172173
panic("not implemented")
173174
}
174175

@@ -198,19 +199,19 @@ func (MockClient) ContainerKill(_ context.Context, _ string, _ string) error {
198199
panic("not implemented")
199200
}
200201

201-
func (MockClient) ContainerList(_ context.Context, _ dockertypes.ContainerListOptions) ([]dockertypes.Container, error) {
202+
func (MockClient) ContainerList(_ context.Context, _ containertypes.ListOptions) ([]dockertypes.Container, error) {
202203
panic("not implemented")
203204
}
204205

205-
func (MockClient) ContainerLogs(_ context.Context, _ string, _ dockertypes.ContainerLogsOptions) (io.ReadCloser, error) {
206+
func (MockClient) ContainerLogs(_ context.Context, _ string, _ containertypes.LogsOptions) (io.ReadCloser, error) {
206207
panic("not implemented")
207208
}
208209

209210
func (MockClient) ContainerPause(_ context.Context, _ string) error {
210211
panic("not implemented")
211212
}
212213

213-
func (m MockClient) ContainerRemove(ctx context.Context, name string, options dockertypes.ContainerRemoveOptions) error {
214+
func (m MockClient) ContainerRemove(ctx context.Context, name string, options containertypes.RemoveOptions) error {
214215
if m.ContainerRemoveFn == nil {
215216
return nil
216217
}
@@ -221,7 +222,7 @@ func (MockClient) ContainerRename(_ context.Context, _ string, _ string) error {
221222
panic("not implemented")
222223
}
223224

224-
func (MockClient) ContainerResize(_ context.Context, _ string, _ dockertypes.ResizeOptions) error {
225+
func (MockClient) ContainerResize(_ context.Context, _ string, _ containertypes.ResizeOptions) error {
225226
panic("not implemented")
226227
}
227228

@@ -237,7 +238,7 @@ func (MockClient) ContainerStats(_ context.Context, _ string, _ bool) (dockertyp
237238
panic("not implemented")
238239
}
239240

240-
func (m MockClient) ContainerStart(ctx context.Context, name string, options dockertypes.ContainerStartOptions) error {
241+
func (m MockClient) ContainerStart(ctx context.Context, name string, options containertypes.StartOptions) error {
241242
if m.ContainerStartFn == nil {
242243
return nil
243244
}

dockerutil/dockerfake/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// Package dockerfake contains logic for mocking out Docker-related
22
// functionality.
3+
//
4+
//go:generate mockgen -destination ./mock.go -package dockerfake github.com/coder/envbox/dockerutil/dockerfake Client
35
package dockerfake

0 commit comments

Comments
 (0)