Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions cli/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"strings"

"github.com/apex/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stdcopy"
archive "github.com/moby/go-archive"
"github.com/moby/moby/api/pkg/stdcopy"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/client"
"github.com/moby/moby/client/pkg/jsonmessage"
"github.com/moby/term"
)

Expand Down Expand Up @@ -72,7 +71,7 @@ func buildDockerImage(dockerClient *client.Client, imageTag, buildContextDir str
return err
}

opts := types.ImageBuildOptions{
opts := client.ImageBuildOptions{
Dockerfile: dockerFileName,
Tags: []string{imageTag},
Remove: true,
Expand Down Expand Up @@ -121,12 +120,15 @@ func createContainer(dockerClient *client.Client, runOptions RunOptions) (string

log.Debug("Creating docker container.")
ctx := context.Background()
createResponse, err := dockerClient.ContainerCreate(ctx, &container.Config{
Image: runOptions.ImageTag,
Cmd: runOptions.Command,
Tty: false,
User: fmt.Sprintf("%s:%s", currentUser.Uid, currentUser.Gid),
}, &container.HostConfig{Binds: runOptions.Binds}, nil, nil, "")
createResponse, err := dockerClient.ContainerCreate(ctx, client.ContainerCreateOptions{
Config: &container.Config{
Image: runOptions.ImageTag,
Cmd: runOptions.Command,
Tty: false,
User: fmt.Sprintf("%s:%s", currentUser.Uid, currentUser.Gid),
},
HostConfig: &container.HostConfig{Binds: runOptions.Binds},
})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -157,8 +159,8 @@ func RunContainer(runOptions RunOptions, writer io.Writer) error {
}
defer func() {
log.Debugf("Removing container %s", containerId[:12])
if err := dockerClient.ContainerRemove(context.Background(), containerId,
container.RemoveOptions{}); err != nil {
if _, err := dockerClient.ContainerRemove(context.Background(), containerId,
client.ContainerRemoveOptions{}); err != nil {
log.Warnf("Failed to remove container %s", containerId[:12])
}
}()
Expand All @@ -167,14 +169,14 @@ func RunContainer(runOptions RunOptions, writer io.Writer) error {
ctx, cancelFunc := context.WithCancel(context.Background())
log.Debugf("The following command is going to be invoked in the container: %s.",
strings.Join(runOptions.Command, " "))
if err := dockerClient.ContainerStart(ctx, containerId,
container.StartOptions{}); err != nil {
if _, err := dockerClient.ContainerStart(ctx, containerId,
client.ContainerStartOptions{}); err != nil {
cancelFunc()
return err
}
defer interruptHandler(cancelFunc)()

out, err := dockerClient.ContainerLogs(ctx, containerId, container.LogsOptions{
out, err := dockerClient.ContainerLogs(ctx, containerId, client.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
Expand All @@ -185,19 +187,19 @@ func RunContainer(runOptions RunOptions, writer io.Writer) error {
stdcopy.StdCopy(writer, writer, out)
out.Close()

statusCh, errCh := dockerClient.ContainerWait(ctx, containerId,
container.WaitConditionNotRunning)
res := dockerClient.ContainerWait(ctx, containerId,
client.ContainerWaitOptions{})
select {
case err := <-errCh:
case err := <-res.Error:
if ctx.Err() == context.Canceled {
if err = dockerClient.ContainerStop(context.Background(), containerId,
container.StopOptions{}); err != nil {
if _, err = dockerClient.ContainerStop(context.Background(), containerId,
client.ContainerStopOptions{}); err != nil {
log.Warnf("Failed to stop the container %s", containerId[:12])
}
return fmt.Errorf("the operation is interrupted")
}
return err
case st := <-statusCh:
case st := <-res.Result:
if st.StatusCode != 0 {
return fmt.Errorf("container exit code is %d", st.StatusCode)
}
Expand Down
14 changes: 6 additions & 8 deletions cli/docker/docker_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ import (
"strings"
"testing"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/moby/moby/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func findAndRemoveBuiltImage(t *testing.T, dockerClient *client.Client, expectedTag string) {
ctx := context.Background()
imageList, err := dockerClient.ImageList(ctx, image.ListOptions{})
imageList, err := dockerClient.ImageList(ctx, client.ImageListOptions{})
require.NoError(t, err)
imgFound := false
for _, img := range imageList {
for _, img := range imageList.Items {
for _, imgTag := range img.RepoTags {
if imgTag == "ubuntu:tt_test" {
imgFound = true
dockerClient.ImageRemove(ctx, img.ID, image.RemoveOptions{})
dockerClient.ImageRemove(ctx, img.ID, client.ImageRemoveOptions{})
}
}
}
Expand Down Expand Up @@ -117,13 +115,13 @@ func checkNoContainers(t *testing.T, imageTag string) {
require.NoError(t, err)
defer cli.Close()

containers, err := cli.ContainerList(ctx, container.ListOptions{
containers, err := cli.ContainerList(ctx, client.ContainerListOptions{
Latest: true,
Limit: 1,
})
require.NoError(t, err)
containerFound := false
for _, container := range containers {
for _, container := range containers.Items {
if container.Image == imageTag {
containerFound = true
}
Expand Down
42 changes: 22 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/avast/retry-go v3.0.0+incompatible
github.com/briandowns/spinner v1.23.2
github.com/dave/jennifer v1.7.1
github.com/docker/docker v27.3.1+incompatible
github.com/fatih/color v1.18.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.8.0
Expand All @@ -19,13 +18,16 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/go-archive v0.2.0
github.com/moby/moby/api v1.54.0
github.com/moby/moby/client v0.3.0
github.com/moby/term v0.5.2
github.com/nxadm/tail v1.4.11
github.com/otiai10/copy v1.14.1
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/tarantool/cartridge-cli v0.0.0-20251201151815-3c65b031a88a
github.com/tarantool/cartridge-cli v0.0.0-00010101000000-000000000000
github.com/tarantool/go-prompt v1.0.1
github.com/tarantool/go-tarantool v1.12.3
github.com/tarantool/go-tarantool/v2 v2.4.2
Expand All @@ -49,26 +51,28 @@ require (
)

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
github.com/FZambia/tarantool v0.2.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/alecthomas/repr v0.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.2.0 // indirect
github.com/c-bata/go-prompt v0.2.6 // indirect
github.com/c-bata/go-prompt v0.2.5 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.6 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.7.0 // indirect
github.com/creack/pty v1.1.24 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.5.2+incompatible // indirect
github.com/docker/go-connections v0.6.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand All @@ -77,7 +81,7 @@ require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
Expand All @@ -99,10 +103,10 @@ require (
github.com/mattn/go-tty v0.0.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/atomicwriter v0.1.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/user v0.4.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/morikuni/aec v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand All @@ -115,22 +119,21 @@ require (
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.19.2 // indirect
github.com/robfig/config v0.0.0-20141207224736-0f78529c8c7e // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil v3.21.2+incompatible // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/sirupsen/logrus v1.9.4 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/tarantool/go-iproto v1.1.0 // indirect
github.com/tarantool/go-openssl v1.2.1 // indirect
github.com/tarantool/go-tlsdialer v1.0.2 // indirect
github.com/tklauser/go-sysconf v0.3.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
github.com/tklauser/go-sysconf v0.3.4 // indirect
github.com/tklauser/numcpus v0.2.1 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xiang90/probing v0.0.0-20221125231312-a49e3df8f510 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.etcd.io/bbolt v1.4.3 // indirect
go.etcd.io/etcd/api/v3 v3.6.8 // indirect
go.etcd.io/etcd/etcdctl/v3 v3.6.8 // indirect
Expand All @@ -141,13 +144,13 @@ require (
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 // indirect
go.opentelemetry.io/otel v1.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect
go.opentelemetry.io/otel v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0 // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/otel/sdk v1.40.0 // indirect
go.opentelemetry.io/otel/trace v1.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.42.0 // indirect
go.opentelemetry.io/otel/metric v1.42.0 // indirect
go.opentelemetry.io/otel/sdk v1.42.0 // indirect
go.opentelemetry.io/otel/trace v1.42.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.1 // indirect
Expand All @@ -160,12 +163,11 @@ require (
gonum.org/v1/gonum v0.17.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260223185530-2f722ef697dc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260316180232-0b37fe3546d5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260319201613-d00831a3d3e7 // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/vmihailenco/msgpack.v2 v2.9.2 // indirect
gotest.tools/v3 v3.5.2 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
Expand Down
Loading
Loading