Skip to content

Commit 6010d61

Browse files
dependabot[bot]m90
andauthored
Bump github.com/docker/cli from 28.5.2+incompatible to 29.0.2+incompatible (#676)
* Bump github.com/docker/cli Bumps [github.com/docker/cli](https://github.com/docker/cli) from 28.5.2+incompatible to 29.0.2+incompatible. - [Commits](docker/cli@v28.5.2...v29.0.2) --- updated-dependencies: - dependency-name: github.com/docker/cli dependency-version: 29.0.2+incompatible dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * github.com/docker/docker has been superseded by moby packages * Fix usage of new filter API * Base test env off Docker 29 --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Frederik Ring <[email protected]>
1 parent 173f08f commit 6010d61

File tree

8 files changed

+121
-227
lines changed

8 files changed

+121
-227
lines changed

cmd/backup/exec.go

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616
"strings"
1717

1818
"github.com/cosiner/argv"
19-
"github.com/docker/docker/api/types/container"
20-
"github.com/docker/docker/api/types/filters"
21-
"github.com/docker/docker/pkg/stdcopy"
19+
"github.com/moby/moby/api/pkg/stdcopy"
20+
"github.com/moby/moby/client"
2221
"github.com/offen/docker-volume-backup/internal/errwrap"
2322
"golang.org/x/sync/errgroup"
2423
)
@@ -36,7 +35,7 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte,
3635
fmt.Sprintf("COMMAND_RUNTIME_ARCHIVE_FILEPATH=%s", s.file),
3736
}
3837

39-
execID, err := s.cli.ContainerExecCreate(context.Background(), containerRef, container.ExecOptions{
38+
execID, err := s.cli.ExecCreate(context.Background(), containerRef, client.ExecCreateOptions{
4039
Cmd: args[0],
4140
AttachStdin: true,
4241
AttachStderr: true,
@@ -47,7 +46,7 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte,
4746
return nil, nil, errwrap.Wrap(err, "error creating container exec")
4847
}
4948

50-
resp, err := s.cli.ContainerExecAttach(context.Background(), execID.ID, container.ExecStartOptions{})
49+
resp, err := s.cli.ExecAttach(context.Background(), execID.ID, client.ExecAttachOptions{})
5150
if err != nil {
5251
return nil, nil, errwrap.Wrap(err, "error attaching container exec")
5352
}
@@ -82,7 +81,7 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte,
8281
return nil, nil, errwrap.Wrap(err, "error reading stderr")
8382
}
8483

85-
res, err := s.cli.ContainerExecInspect(context.Background(), execID.ID)
84+
res, err := s.cli.ExecInspect(context.Background(), execID.ID, client.ExecInspectOptions{})
8685
if err != nil {
8786
return nil, nil, errwrap.Wrap(err, "error inspecting container exec")
8887
}
@@ -95,54 +94,45 @@ func (s *script) exec(containerRef string, command string, user string) ([]byte,
9594
}
9695

9796
func (s *script) runLabeledCommands(label string) error {
98-
f := []filters.KeyValuePair{
99-
{Key: "label", Value: label},
100-
}
97+
f := client.Filters{}
98+
f.Add("label", label)
10199
if s.c.ExecLabel != "" {
102-
f = append(f, filters.KeyValuePair{
103-
Key: "label",
104-
Value: fmt.Sprintf("docker-volume-backup.exec-label=%s", s.c.ExecLabel),
105-
})
100+
f.Add("label", fmt.Sprintf("docker-volume-backup.exec-label=%s", s.c.ExecLabel))
106101
}
107-
containersWithCommand, err := s.cli.ContainerList(context.Background(), container.ListOptions{
108-
Filters: filters.NewArgs(f...),
102+
containersWithCommandResult, err := s.cli.ContainerList(context.Background(), client.ContainerListOptions{
103+
Filters: f,
109104
})
110105
if err != nil {
111106
return errwrap.Wrap(err, "error querying for containers")
112107
}
108+
containersWithCommand := containersWithCommandResult.Items
113109

114110
var hasDeprecatedContainers bool
115111
if label == "docker-volume-backup.archive-pre" {
116-
f[0] = filters.KeyValuePair{
117-
Key: "label",
118-
Value: "docker-volume-backup.exec-pre",
119-
}
120-
deprecatedContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{
121-
Filters: filters.NewArgs(f...),
112+
f = client.Filters{}.Add("label", "docker-volume-backup.exec-pre")
113+
deprecatedContainers, err := s.cli.ContainerList(context.Background(), client.ContainerListOptions{
114+
Filters: f,
122115
})
123116
if err != nil {
124117
return errwrap.Wrap(err, "error querying for containers")
125118
}
126-
if len(deprecatedContainers) != 0 {
119+
if len(deprecatedContainers.Items) != 0 {
127120
hasDeprecatedContainers = true
128-
containersWithCommand = append(containersWithCommand, deprecatedContainers...)
121+
containersWithCommand = append(containersWithCommand, deprecatedContainers.Items...)
129122
}
130123
}
131124

132125
if label == "docker-volume-backup.archive-post" {
133-
f[0] = filters.KeyValuePair{
134-
Key: "label",
135-
Value: "docker-volume-backup.exec-post",
136-
}
137-
deprecatedContainers, err := s.cli.ContainerList(context.Background(), container.ListOptions{
138-
Filters: filters.NewArgs(f...),
126+
f = client.Filters{}.Add("label", "docker-volume-backup.exec-post")
127+
deprecatedContainers, err := s.cli.ContainerList(context.Background(), client.ContainerListOptions{
128+
Filters: f,
139129
})
140130
if err != nil {
141131
return errwrap.Wrap(err, "error querying for containers")
142132
}
143-
if len(deprecatedContainers) != 0 {
133+
if len(deprecatedContainers.Items) != 0 {
144134
hasDeprecatedContainers = true
145-
containersWithCommand = append(containersWithCommand, deprecatedContainers...)
135+
containersWithCommand = append(containersWithCommand, deprecatedContainers.Items...)
146136
}
147137
}
148138

cmd/backup/script.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"github.com/offen/docker-volume-backup/internal/storage/ssh"
2323
"github.com/offen/docker-volume-backup/internal/storage/webdav"
2424

25-
"github.com/docker/docker/client"
2625
"github.com/leekchan/timeutil"
26+
"github.com/moby/moby/client"
2727
"github.com/nicholas-fedor/shoutrrr"
2828
"github.com/nicholas-fedor/shoutrrr/pkg/router"
2929
)
@@ -109,7 +109,7 @@ func (s *script) init() error {
109109
_, err := os.Stat("/var/run/docker.sock")
110110
_, dockerHostSet := os.LookupEnv("DOCKER_HOST")
111111
if !os.IsNotExist(err) || dockerHostSet {
112-
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
112+
cli, err := client.New(client.FromEnv, client.WithAPIVersionNegotiation())
113113
if err != nil {
114114
return errwrap.Wrap(err, "failed to create docker client")
115115
}

cmd/backup/stop_restart.go

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ import (
1313
"time"
1414

1515
"github.com/docker/cli/cli/command/service/progress"
16-
ctr "github.com/docker/docker/api/types/container"
17-
"github.com/docker/docker/api/types/filters"
18-
"github.com/docker/docker/api/types/swarm"
19-
"github.com/docker/docker/api/types/system"
20-
"github.com/docker/docker/client"
16+
"github.com/moby/moby/api/types/swarm"
17+
"github.com/moby/moby/client"
2118
"github.com/offen/docker-volume-backup/internal/errwrap"
2219
)
2320

2421
func scaleService(cli *client.Client, serviceID string, replicas uint64) ([]string, error) {
25-
service, _, err := cli.ServiceInspectWithRaw(context.Background(), serviceID, swarm.ServiceInspectOptions{})
22+
result, err := cli.ServiceInspect(context.Background(), serviceID, client.ServiceInspectOptions{})
2623
if err != nil {
2724
return nil, errwrap.Wrap(err, fmt.Sprintf("error inspecting service %s", serviceID))
2825
}
26+
service := result.Service
2927
serviceMode := &service.Spec.Mode
3028
switch {
3129
case serviceMode.Replicated != nil:
@@ -34,7 +32,7 @@ func scaleService(cli *client.Client, serviceID string, replicas uint64) ([]stri
3432
return nil, errwrap.Wrap(nil, fmt.Sprintf("service to be scaled %s has to be in replicated mode", service.Spec.Name))
3533
}
3634

37-
response, err := cli.ServiceUpdate(context.Background(), service.ID, service.Version, service.Spec, swarm.ServiceUpdateOptions{})
35+
response, err := cli.ServiceUpdate(context.Background(), service.ID, client.ServiceUpdateOptions{Version: service.Version, Spec: service.Spec})
3836
if err != nil {
3937
return nil, errwrap.Wrap(err, "error updating service")
4038
}
@@ -65,30 +63,27 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
6563
),
6664
)
6765
case <-poll.C:
68-
containers, err := cli.ContainerList(context.Background(), ctr.ListOptions{
69-
Filters: filters.NewArgs(filters.KeyValuePair{
70-
Key: "label",
71-
Value: fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID),
72-
}),
66+
containers, err := cli.ContainerList(context.Background(), client.ContainerListOptions{
67+
Filters: client.Filters{}.Add("label", fmt.Sprintf("com.docker.swarm.service.id=%s", serviceID)),
7368
})
7469
if err != nil {
7570
return errwrap.Wrap(err, "error listing containers")
7671
}
77-
if len(containers) == count {
72+
if len(containers.Items) == count {
7873
return nil
7974
}
8075
}
8176
}
8277
}
8378

8479
func isSwarm(c interface {
85-
Info(context.Context) (system.Info, error)
80+
Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error)
8681
}) (bool, error) {
87-
info, err := c.Info(context.Background())
82+
result, err := c.Info(context.Background(), client.InfoOptions{})
8883
if err != nil {
8984
return false, errwrap.Wrap(err, "error getting docker info")
9085
}
91-
return info.Swarm.LocalNodeState != "" && info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.ControlAvailable, nil
86+
return result.Info.Swarm.LocalNodeState != "" && result.Info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && result.Info.Swarm.ControlAvailable, nil
9287
}
9388

9489
func hasLabel(labels map[string]string, key, value string) bool {
@@ -113,7 +108,6 @@ func (s *script) stopContainersAndServices() (func() error, error) {
113108
if s.cli == nil {
114109
return noop, nil
115110
}
116-
117111
isDockerSwarm, err := isSwarm(s.cli)
118112
if err != nil {
119113
return noop, errwrap.Wrap(err, "error determining swarm state")
@@ -143,13 +137,13 @@ func (s *script) stopContainersAndServices() (func() error, error) {
143137
s.c.BackupStopDuringBackupNoRestartLabel,
144138
)
145139

146-
allContainers, err := s.cli.ContainerList(context.Background(), ctr.ListOptions{})
140+
allContainers, err := s.cli.ContainerList(context.Background(), client.ContainerListOptions{})
147141
if err != nil {
148142
return noop, errwrap.Wrap(err, "error querying for containers")
149143
}
150144

151145
var containersToStop []handledContainer
152-
for _, c := range allContainers {
146+
for _, c := range allContainers.Items {
153147
hasStopDuringBackupLabel, hasStopDuringBackupNoRestartLabel, err := checkStopLabels(c.Labels, labelValue, s.c.BackupStopDuringBackupNoRestartLabel)
154148
if err != nil {
155149
return noop, errwrap.Wrap(err, "error querying for containers to stop")
@@ -168,7 +162,8 @@ func (s *script) stopContainersAndServices() (func() error, error) {
168162
var allServices []swarm.Service
169163
var servicesToScaleDown []handledSwarmService
170164
if isDockerSwarm {
171-
allServices, err = s.cli.ServiceList(context.Background(), swarm.ServiceListOptions{Status: true})
165+
result, err := s.cli.ServiceList(context.Background(), client.ServiceListOptions{Status: true})
166+
allServices := result.Items
172167
if err != nil {
173168
return noop, errwrap.Wrap(err, "error querying for services")
174169
}
@@ -205,18 +200,18 @@ func (s *script) stopContainersAndServices() (func() error, error) {
205200
if isDockerSwarm {
206201
for _, container := range containersToStop {
207202
if swarmServiceID, ok := container.summary.Labels["com.docker.swarm.service.id"]; ok {
208-
parentService, _, err := s.cli.ServiceInspectWithRaw(context.Background(), swarmServiceID, swarm.ServiceInspectOptions{})
203+
parentService, err := s.cli.ServiceInspect(context.Background(), swarmServiceID, client.ServiceInspectOptions{})
209204
if err != nil {
210205
return noop, errwrap.Wrap(err, fmt.Sprintf("error querying for parent service with ID %s", swarmServiceID))
211206
}
212-
for label := range parentService.Spec.Labels {
207+
for label := range parentService.Service.Spec.Labels {
213208
if label == "docker-volume-backup.stop-during-backup" {
214209
return noop, errwrap.Wrap(
215210
nil,
216211
fmt.Sprintf(
217212
"container %s is labeled to stop but has parent service %s which is also labeled, cannot continue",
218213
container.summary.Names[0],
219-
parentService.Spec.Name,
214+
parentService.Service.Spec.Name,
220215
),
221216
)
222217
}
@@ -229,7 +224,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
229224
fmt.Sprintf(
230225
"Stopping %d out of %d running container(s) as they were labeled %s or %s.",
231226
len(containersToStop),
232-
len(allContainers),
227+
len(allContainers.Items),
233228
stopDuringBackupLabel,
234229
stopDuringBackupNoRestartLabel,
235230
),
@@ -249,7 +244,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
249244
var stoppedContainers []handledContainer
250245
var stopErrors []error
251246
for _, container := range containersToStop {
252-
if err := s.cli.ContainerStop(context.Background(), container.summary.ID, ctr.StopOptions{}); err != nil {
247+
if _, err := s.cli.ContainerStop(context.Background(), container.summary.ID, client.ContainerStopOptions{}); err != nil {
253248
stopErrors = append(stopErrors, err)
254249
} else {
255250
stoppedContainers = append(stoppedContainers, container)
@@ -286,7 +281,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
286281
}
287282

288283
s.stats.Containers = ContainersStats{
289-
All: uint(len(allContainers)),
284+
All: uint(len(allContainers.Items)),
290285
ToStop: uint(len(containersToStop)),
291286
Stopped: uint(len(stoppedContainers)),
292287
StopErrors: uint(len(stopErrors)),
@@ -328,7 +323,8 @@ func (s *script) stopContainersAndServices() (func() error, error) {
328323
// in case a container was part of a swarm service, the service requires to
329324
// be force updated instead of restarting the container as it would otherwise
330325
// remain in a "completed" state
331-
service, _, err := s.cli.ServiceInspectWithRaw(context.Background(), swarmServiceID, swarm.ServiceInspectOptions{})
326+
result, err := s.cli.ServiceInspect(context.Background(), swarmServiceID, client.ServiceInspectOptions{})
327+
service := result.Service
332328
if err != nil {
333329
restartErrors = append(
334330
restartErrors,
@@ -339,14 +335,14 @@ func (s *script) stopContainersAndServices() (func() error, error) {
339335
service.Spec.TaskTemplate.ForceUpdate += 1
340336
if _, err := s.cli.ServiceUpdate(
341337
context.Background(), service.ID,
342-
service.Version, service.Spec, swarm.ServiceUpdateOptions{},
338+
client.ServiceUpdateOptions{Spec: service.Spec, Version: service.Version},
343339
); err != nil {
344340
restartErrors = append(restartErrors, err)
345341
}
346342
continue
347343
}
348344

349-
if err := s.cli.ContainerStart(context.Background(), container.summary.ID, ctr.StartOptions{}); err != nil {
345+
if _, err := s.cli.ContainerStart(context.Background(), container.summary.ID, client.ContainerStartOptions{}); err != nil {
350346
restartErrors = append(restartErrors, err)
351347
} else {
352348
restartedContainers = append(restartedContainers, container)

cmd/backup/stop_restart_test.go

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import (
55
"errors"
66
"testing"
77

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

1213
type mockInfoClient struct {
13-
result system.Info
14+
result client.SystemInfoResult
1415
err error
1516
}
1617

17-
func (m *mockInfoClient) Info(context.Context) (system.Info, error) {
18+
func (m *mockInfoClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) {
1819
return m.result, m.err
1920
}
2021

@@ -28,10 +29,12 @@ func TestIsSwarm(t *testing.T) {
2829
{
2930
"swarm",
3031
&mockInfoClient{
31-
result: system.Info{
32-
Swarm: swarm.Info{
33-
LocalNodeState: swarm.LocalNodeStateActive,
34-
ControlAvailable: true,
32+
result: client.SystemInfoResult{
33+
Info: system.Info{
34+
Swarm: swarm.Info{
35+
LocalNodeState: swarm.LocalNodeStateActive,
36+
ControlAvailable: true,
37+
},
3538
},
3639
},
3740
},
@@ -41,9 +44,11 @@ func TestIsSwarm(t *testing.T) {
4144
{
4245
"worker",
4346
&mockInfoClient{
44-
result: system.Info{
45-
Swarm: swarm.Info{
46-
LocalNodeState: swarm.LocalNodeStateActive,
47+
result: client.SystemInfoResult{
48+
Info: system.Info{
49+
Swarm: swarm.Info{
50+
LocalNodeState: swarm.LocalNodeStateActive,
51+
},
4752
},
4853
},
4954
},
@@ -53,9 +58,11 @@ func TestIsSwarm(t *testing.T) {
5358
{
5459
"compose",
5560
&mockInfoClient{
56-
result: system.Info{
57-
Swarm: swarm.Info{
58-
LocalNodeState: swarm.LocalNodeStateInactive,
61+
result: client.SystemInfoResult{
62+
Info: system.Info{
63+
Swarm: swarm.Info{
64+
LocalNodeState: swarm.LocalNodeStateInactive,
65+
},
5966
},
6067
},
6168
},
@@ -65,9 +72,11 @@ func TestIsSwarm(t *testing.T) {
6572
{
6673
"balena",
6774
&mockInfoClient{
68-
result: system.Info{
69-
Swarm: swarm.Info{
70-
LocalNodeState: "",
75+
result: client.SystemInfoResult{
76+
Info: system.Info{
77+
Swarm: swarm.Info{
78+
LocalNodeState: "",
79+
},
7180
},
7281
},
7382
},

0 commit comments

Comments
 (0)