Skip to content

Commit

Permalink
engine: resources: docker: Update docker
Browse files Browse the repository at this point in the history
Several types were renamed and moved

Signed-off-by: Joe Groocock <[email protected]>
  • Loading branch information
frebib committed Apr 27, 2024
1 parent c12452b commit 351a61c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
15 changes: 8 additions & 7 deletions engine/resources/docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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/client"
"github.com/docker/go-connections/nat"
)
Expand Down Expand Up @@ -234,7 +235,7 @@ func (obj *DockerContainerRes) CheckApply(ctx context.Context, apply bool) (bool
defer cancel()

// List any container whose name matches this resource.
opts := types.ContainerListOptions{
opts := container.ListOptions{
All: true,
Filters: filters.NewArgs(filters.KeyValuePair{Key: "name", Value: obj.Name()}),
}
Expand Down Expand Up @@ -279,22 +280,22 @@ func (obj *DockerContainerRes) CheckApply(ctx context.Context, apply bool) (bool
if err := obj.containerStop(ctx, id, nil); err != nil {
return false, err
}
return false, obj.containerRemove(ctx, id, types.ContainerRemoveOptions{})
return false, obj.containerRemove(ctx, id, container.RemoveOptions{})
}

if destroy {
if err := obj.containerStop(ctx, id, nil); err != nil {
return false, err
}
if err := obj.containerRemove(ctx, id, types.ContainerRemoveOptions{}); err != nil {
if err := obj.containerRemove(ctx, id, container.RemoveOptions{}); err != nil {
return false, err
}
containerList = []types.Container{} // zero the list
}

if len(containerList) == 0 { // no container was found
// Download the specified image if it doesn't exist locally.
p, err := obj.client.ImagePull(ctx, obj.Image, types.ImagePullOptions{})
p, err := obj.client.ImagePull(ctx, obj.Image, image.PullOptions{})
if err != nil {
return false, errwrap.Wrapf(err, "error pulling image")
}
Expand Down Expand Up @@ -334,11 +335,11 @@ func (obj *DockerContainerRes) CheckApply(ctx context.Context, apply bool) (bool
id = c.ID
}

return false, obj.containerStart(ctx, id, types.ContainerStartOptions{})
return false, obj.containerStart(ctx, id, container.StartOptions{})
}

// containerStart starts the specified container, and waits for it to start.
func (obj *DockerContainerRes) containerStart(ctx context.Context, id string, opts types.ContainerStartOptions) error {
func (obj *DockerContainerRes) containerStart(ctx context.Context, id string, opts container.StartOptions) error {
// Get an events channel for the container we're about to start.
eventOpts := types.EventsOptions{
Filters: filters.NewArgs(filters.KeyValuePair{Key: "container", Value: id}),
Expand Down Expand Up @@ -377,7 +378,7 @@ func (obj *DockerContainerRes) containerStop(ctx context.Context, id string, tim

// containerRemove removes the specified container and waits for it to be
// removed.
func (obj *DockerContainerRes) containerRemove(ctx context.Context, id string, opts types.ContainerRemoveOptions) error {
func (obj *DockerContainerRes) containerRemove(ctx context.Context, id string, opts container.RemoveOptions) error {
ch, errCh := obj.client.ContainerWait(ctx, id, container.WaitConditionRemoved)
obj.client.ContainerRemove(ctx, id, opts)
select {
Expand Down
18 changes: 9 additions & 9 deletions engine/resources/docker_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
"testing"
"time"

"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"
)

var res *DockerContainerRes
Expand Down Expand Up @@ -75,14 +75,14 @@ func BrokenTestContainerStart(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

if err := res.containerStart(ctx, id, types.ContainerStartOptions{}); err != nil {
if err := res.containerStart(ctx, id, container.StartOptions{}); err != nil {
t.Errorf("containerStart() error: %s", err)
return
}

l, err := res.client.ContainerList(
ctx,
types.ContainerListOptions{
container.ListOptions{
Filters: filters.NewArgs(
filters.KeyValuePair{Key: "id", Value: id},
filters.KeyValuePair{Key: "status", Value: "running"},
Expand Down Expand Up @@ -110,7 +110,7 @@ func BrokenTestContainerStop(t *testing.T) {

l, err := res.client.ContainerList(
ctx,
types.ContainerListOptions{
container.ListOptions{
Filters: filters.NewArgs(
filters.KeyValuePair{Key: "id", Value: id},
),
Expand All @@ -130,14 +130,14 @@ func BrokenTestContainerRemove(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

if err := res.containerRemove(ctx, id, types.ContainerRemoveOptions{}); err != nil {
if err := res.containerRemove(ctx, id, container.RemoveOptions{}); err != nil {
t.Errorf("containerRemove() error: %s", err)
return
}

l, err := res.client.ContainerList(
ctx,
types.ContainerListOptions{
container.ListOptions{
All: true,
Filters: filters.NewArgs(
filters.KeyValuePair{Key: "id", Value: id},
Expand All @@ -163,7 +163,7 @@ func setup() error {
res = &DockerContainerRes{}
res.Init(res.init)

p, err := res.client.ImagePull(ctx, "alpine", types.ImagePullOptions{})
p, err := res.client.ImagePull(ctx, "alpine", image.PullOptions{})
if err != nil {
return fmt.Errorf("error pulling image: %s", err)
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func cleanup() error {

l, err := res.client.ContainerList(
ctx,
types.ContainerListOptions{
container.ListOptions{
All: true,
Filters: filters.NewArgs(filters.KeyValuePair{Key: "id", Value: id}),
},
Expand All @@ -209,7 +209,7 @@ func cleanup() error {
if err := res.client.ContainerStop(ctx, id, stopOpts); err != nil {
return fmt.Errorf("error stopping container: %s", err)
}
if err := res.client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}); err != nil {
if err := res.client.ContainerRemove(ctx, id, container.RemoveOptions{}); err != nil {
return fmt.Errorf("error removing container: %s", err)
}
}
Expand Down
7 changes: 4 additions & 3 deletions engine/resources/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
errwrap "github.com/pkg/errors"
)
Expand Down Expand Up @@ -188,7 +189,7 @@ func (obj *DockerImageRes) CheckApply(ctx context.Context, apply bool) (checkOK
ctx, cancel := context.WithTimeout(ctx, dockerImageCheckApplyCtxTimeout*time.Second)
defer cancel()

s, err := obj.client.ImageList(ctx, types.ImageListOptions{
s, err := obj.client.ImageList(ctx, image.ListOptions{
Filters: filters.NewArgs(filters.Arg("reference", obj.image)),
})
if err != nil {
Expand All @@ -211,14 +212,14 @@ func (obj *DockerImageRes) CheckApply(ctx context.Context, apply bool) (checkOK

if obj.State == "absent" {
// TODO: force? prune children?
if _, err := obj.client.ImageRemove(ctx, obj.image, types.ImageRemoveOptions{}); err != nil {
if _, err := obj.client.ImageRemove(ctx, obj.image, image.RemoveOptions{}); err != nil {
return false, errwrap.Wrapf(err, "error removing image")
}
return false, nil
}

// pull the image
p, err := obj.client.ImagePull(ctx, obj.image, types.ImagePullOptions{})
p, err := obj.client.ImagePull(ctx, obj.image, image.PullOptions{})
if err != nil {
return false, errwrap.Wrapf(err, "error pulling image")
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deniswernert/go-fstab v0.0.0-20141204152952-eb4090f26517
github.com/docker/docker v25.0.4+incompatible
github.com/docker/docker v26.1.0+incompatible
github.com/docker/go-connections v0.5.0
github.com/fsnotify/fsnotify v1.7.0
github.com/go-git/go-git/v5 v5.11.0
Expand Down Expand Up @@ -108,6 +108,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/docker v25.0.4+incompatible h1:XITZTrq+52tZyZxUOtFIahUf3aH367FLxJzt9vZeAF8=
github.com/docker/docker v25.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.1.0+incompatible h1:W1G9MPNbskA6VZWL7b3ZljTh0pXI68FpINx0GKaOdaM=
github.com/docker/docker v26.1.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down Expand Up @@ -388,6 +388,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd h1:aY7OQNf2XqY/JQ6qREWamhI/81os/agb2BAGpcx5yWI=
github.com/moby/term v0.0.0-20200312100748-672ec06f55cd/go.mod h1:DdlQx2hp0Ss5/fLikoLlEeIYiATotOjgB//nb973jeo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down

0 comments on commit 351a61c

Please sign in to comment.