Skip to content

Commit

Permalink
Update calls deprecated in Moby 25
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWiegman committed Jan 19, 2024
1 parent 79a6570 commit f9eddc0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
14 changes: 7 additions & 7 deletions internal/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (d *Client) ContainerGetMounts(containerName string) []types.MountPoint {

// containerIsRunning Checks if a given container is running by name.
func (d *Client) containerIsRunning(containerName string) (id string, isRunning bool) {
containers, err := d.apiClient.ContainerList(context.Background(), types.ContainerListOptions{})
containers, err := d.apiClient.ContainerList(context.Background(), container.ListOptions{})
if err != nil {
return "", false
}
Expand All @@ -151,7 +151,7 @@ func (d *Client) ContainerList(site string) ([]types.Container, error) {
f.Add("label", fmt.Sprintf("kana.site=%s", site))
}

options := types.ContainerListOptions{
options := container.ListOptions{
All: true,
Filters: f,
}
Expand All @@ -165,7 +165,7 @@ func (d *Client) containerLog(id string) (result string, err error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(sleepDuration)*time.Second)
defer cancel()

reader, err := d.apiClient.ContainerLogs(ctx, id, types.ContainerLogsOptions{
reader, err := d.apiClient.ContainerLogs(ctx, id, container.LogsOptions{
ShowStdout: true,
ShowStderr: true})

Expand Down Expand Up @@ -193,7 +193,7 @@ func (d *Client) ContainerRestart(containerName string) (bool, error) {
return false, err
}

err = d.apiClient.ContainerStart(context.Background(), containerID, types.ContainerStartOptions{})
err = d.apiClient.ContainerStart(context.Background(), containerID, container.StartOptions{})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func (d *Client) ContainerRun(config *ContainerConfig, randomPorts, localUser bo
return "", err
}

err = d.apiClient.ContainerStart(context.Background(), resp.ID, types.ContainerStartOptions{})
err = d.apiClient.ContainerStart(context.Background(), resp.ID, container.StartOptions{})
if err != nil {
return "", err
}
Expand All @@ -278,7 +278,7 @@ func (d *Client) ContainerRunAndClean(config *ContainerConfig) (statusCode int64
// Get the log
body, _ = d.containerLog(id)

err = d.apiClient.ContainerRemove(context.Background(), id, types.ContainerRemoveOptions{})
err = d.apiClient.ContainerRemove(context.Background(), id, container.RemoveOptions{})
return statusCode, body, err
}

Expand All @@ -293,7 +293,7 @@ func (d *Client) ContainerStop(containerName string) (bool, error) {
return false, err
}

err = d.apiClient.ContainerRemove(context.Background(), containerID, types.ContainerRemoveOptions{})
err = d.apiClient.ContainerRemove(context.Background(), containerID, container.RemoveOptions{})
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/ChrisWiegman/kana-cli/internal/console"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func getCurrentDockerEndpoint() (string, error) {
}

func ensureDockerIsAvailable(apiClient APIClient) error {
_, err := apiClient.ContainerList(context.Background(), types.ContainerListOptions{})
_, err := apiClient.ContainerList(context.Background(), container.ListOptions{})
if err != nil {
return fmt.Errorf("Could not connect to Docker. Is Docker running?") //nolint:stylecheck
}
Expand Down
5 changes: 3 additions & 2 deletions internal/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ChrisWiegman/kana-cli/internal/docker/mocks"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -37,9 +38,9 @@ func TestEnsureDockerIsAvailable(t *testing.T) {
apiClient := new(mocks.APIClient)

if test.exitStatus == 0 {
apiClient.On("ContainerList", context.Background(), types.ContainerListOptions{}).Return([]types.Container{}, test.dockerOutput).Once()
apiClient.On("ContainerList", context.Background(), container.ListOptions{}).Return([]types.Container{}, test.dockerOutput).Once()
} else {
apiClient.On("ContainerList", context.Background(), types.ContainerListOptions{}).Return([]types.Container{}, fmt.Errorf(""))
apiClient.On("ContainerList", context.Background(), container.ListOptions{}).Return([]types.Container{}, fmt.Errorf(""))
}

execCommand = mocks.MockExecCommand
Expand Down
12 changes: 6 additions & 6 deletions internal/docker/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ChrisWiegman/kana-cli/internal/console"
"github.com/ChrisWiegman/kana-cli/internal/docker/mocks"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/image"
"github.com/moby/moby/pkg/jsonmessage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -28,7 +28,7 @@ func TestEnsureImage(t *testing.T) {
ExpectedErr: nil,
}

imageList := []types.ImageSummary{
imageList := []image.Summary{
{RepoTags: []string{
"alpine:latest",
}},
Expand Down Expand Up @@ -64,28 +64,28 @@ func TestRemoveImage(t *testing.T) {

var tests = []struct {
name string
imageDeleteResponse []types.ImageDeleteResponseItem
imageDeleteResponse []image.DeleteResponse
imageRemoveError error
expectedError error
expectedRemove bool
}{
{
"image doesn't exist to remove",
[]types.ImageDeleteResponseItem{},
[]image.DeleteResponse{},
nil,
nil,
false},
{
"image successfully removed",
[]types.ImageDeleteResponseItem{
[]image.DeleteResponse{
{},
},
nil,
nil,
true},
{
"image successfully removed",
[]types.ImageDeleteResponseItem{
[]image.DeleteResponse{
{},
},
fmt.Errorf("image remove function hit error"),
Expand Down
25 changes: 13 additions & 12 deletions internal/docker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"time"

"github.com/docker/docker/api/types"
containerTypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
networkTypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
specs "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -26,31 +27,31 @@ var _ APIClient = &client.Client{}
type ContainerAPIClient interface {
ContainerCreate(
ctx context.Context,
config *containerTypes.Config,
hostConfig *containerTypes.HostConfig,
config *container.Config,
hostConfig *container.HostConfig,
networkingConfig *networkTypes.NetworkingConfig,
platform *specs.Platform,
containerName string) (containerTypes.CreateResponse, error)
containerName string) (container.CreateResponse, error)
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
ContainerStop(ctx context.Context, name string, options containerTypes.StopOptions) error
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
ContainerLogs(ctx context.Context, container string, options container.LogsOptions) (io.ReadCloser, error)
ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
ContainerStop(ctx context.Context, name string, options container.StopOptions) error
ContainerWait(
ctx context.Context,
container string,
condition containerTypes.WaitCondition) (<-chan containerTypes.WaitResponse, <-chan error)
condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
}

// ImageAPIClient defines API client methods for the images.
type ImageAPIClient interface {
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]image.DeleteResponse, error)
ImageList(ctx context.Context, options types.ImageListOptions) ([]image.Summary, error)
}

// NetworkAPIClient defines API client methods for the networks.
Expand Down

0 comments on commit f9eddc0

Please sign in to comment.