Upgrade docker sdk to moby (#491)

* Replace deprecated method

* Upgrade docker sdk to moby
This commit is contained in:
Stavros Panakakis
2021-09-07 14:03:13 +03:00
committed by GitHub
parent 94ec06a3fe
commit 3ee2975d76
17 changed files with 39 additions and 38 deletions

View File

@@ -14,13 +14,13 @@ import (
"strings" "strings"
"time" "time"
client "docker.io/go-docker"
"docker.io/go-docker/api/types"
"docker.io/go-docker/api/types/container"
"docker.io/go-docker/api/types/network"
"docker.io/go-docker/api/types/swarm"
"docker.io/go-docker/api/types/volume"
"github.com/containerd/containerd/reference" "github.com/containerd/containerd/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
) )
@@ -315,7 +315,7 @@ func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) {
pidsLimit = int64(i) pidsLimit = int64(i)
} }
} }
h.Resources.PidsLimit = pidsLimit h.Resources.PidsLimit = &pidsLimit
if memLimit := os.Getenv("MAX_MEMORY_MB"); memLimit != "" { if memLimit := os.Getenv("MAX_MEMORY_MB"); memLimit != "" {
if i, err := strconv.Atoi(memLimit); err == nil { if i, err := strconv.Atoi(memLimit); err == nil {
@@ -344,7 +344,7 @@ func (d *docker) ContainerCreate(opts CreateContainerOpts) (err error) {
} }
if config.ExternalDindVolume { if config.ExternalDindVolume {
_, err = d.c.VolumeCreate(context.Background(), volume.VolumesCreateBody{ _, err = d.c.VolumeCreate(context.Background(), volume.VolumeCreateBody{
Driver: "xfsvol", Driver: "xfsvol",
DriverOpts: map[string]string{ DriverOpts: map[string]string{
"size": opts.DindVolumeSize, "size": opts.DindVolumeSize,
@@ -451,7 +451,9 @@ func (d *docker) ExecAttach(instanceName string, command []string, out io.Writer
if err != nil { if err != nil {
return 0, err return 0, err
} }
resp, err := d.c.ContainerExecAttach(context.Background(), e.ID, types.ExecConfig{AttachStdout: true, AttachStderr: true, Tty: true}) resp, err := d.c.ContainerExecAttach(context.Background(), e.ID, types.ExecStartCheck{
Tty: true,
})
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@@ -8,8 +8,8 @@ import (
"net/url" "net/url"
"time" "time"
client "docker.io/go-docker" "github.com/docker/docker/api"
"docker.io/go-docker/api" "github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/router" "github.com/play-with-docker/play-with-docker/router"

View File

@@ -7,7 +7,7 @@ import (
"sync" "sync"
"time" "time"
client "docker.io/go-docker" "github.com/docker/docker/client"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/storage" "github.com/play-with-docker/play-with-docker/storage"
) )
@@ -37,7 +37,7 @@ func (f *localCachedFactory) GetForSession(session *types.Session) (DockerApi, e
} }
} }
c, err := client.NewEnvClient() c, err := client.NewClientWithOpts()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -5,8 +5,8 @@ import (
"net" "net"
"time" "time"
client "docker.io/go-docker" "github.com/docker/docker/api/types"
"docker.io/go-docker/api/types" "github.com/docker/docker/client"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )

3
go.mod
View File

@@ -4,14 +4,13 @@ go 1.16
require ( require (
cloud.google.com/go v0.58.0 // indirect cloud.google.com/go v0.58.0 // indirect
docker.io/go-docker v1.0.0
github.com/Microsoft/go-winio v0.4.5 // indirect github.com/Microsoft/go-winio v0.4.5 // indirect
github.com/PuerkitoBio/purell v1.1.0 // indirect github.com/PuerkitoBio/purell v1.1.0 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/aws/aws-sdk-go v1.12.15 github.com/aws/aws-sdk-go v1.12.15
github.com/containerd/containerd v1.0.0-beta.2 github.com/containerd/containerd v1.0.0-beta.2
github.com/docker/distribution v2.6.0-rc.1.0.20170726174610-edc3ab29cdff+incompatible // indirect github.com/docker/distribution v2.6.0-rc.1.0.20170726174610-edc3ab29cdff+incompatible // indirect
github.com/docker/docker v1.4.2-0.20200309214505-aa6a9891b09c // indirect github.com/docker/docker v1.4.2-0.20200309214505-aa6a9891b09c
github.com/docker/go-connections v0.3.0 github.com/docker/go-connections v0.3.0
github.com/docker/go-units v0.3.2 github.com/docker/go-units v0.3.2
github.com/emicklei/go-restful v2.4.0+incompatible // indirect github.com/emicklei/go-restful v2.4.0+incompatible // indirect

4
go.sum
View File

@@ -30,8 +30,6 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
docker.io/go-docker v1.0.0 h1:VdXS/aNYQxyA9wdLD5z8Q8Ro688/hG8HzKxYVEVbE6s=
docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Microsoft/go-winio v0.4.5 h1:U2XsGR5dBg1yzwSEJoP2dE2/aAXpmad+CNG2hE9Pd5k= github.com/Microsoft/go-winio v0.4.5 h1:U2XsGR5dBg1yzwSEJoP2dE2/aAXpmad+CNG2hE9Pd5k=
@@ -189,6 +187,7 @@ github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY=
github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk= github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -245,6 +244,7 @@ github.com/satori/go.uuid v1.1.1-0.20170321230731-5bf94b69c6b6/go.mod h1:dA0hQrY
github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible h1:gh3Hq7V5Zb8X2xk4T9FbHVi1m2Yo+oEIyjjJUiezVoY= github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible h1:gh3Hq7V5Zb8X2xk4T9FbHVi1m2Yo+oEIyjjJUiezVoY=
github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v2.16.13-0.20170924065440-6e221c482653+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=

View File

@@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"time" "time"
docker "docker.io/go-docker" "github.com/docker/docker/client"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/shirou/gopsutil/load" "github.com/shirou/gopsutil/load"
) )
@@ -15,7 +15,7 @@ func Ping(rw http.ResponseWriter, req *http.Request) {
defer latencyHistogramVec.WithLabelValues("ping").Observe(float64(time.Since(time.Now()).Nanoseconds()) / 1000000) defer latencyHistogramVec.WithLabelValues("ping").Observe(float64(time.Since(time.Now()).Nanoseconds()) / 1000000)
// Get system load average of the last 5 minutes and compare it against a threashold. // Get system load average of the last 5 minutes and compare it against a threashold.
c, err := docker.NewEnvClient() c, err := client.NewClientWithOpts()
if err != nil { if err != nil {
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)

View File

@@ -7,7 +7,7 @@ import (
"net/url" "net/url"
"strings" "strings"
dtypes "docker.io/go-docker/api/types" dtypes "github.com/docker/docker/api/types"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
dtypes "docker.io/go-docker/api/types" dtypes "github.com/docker/docker/api/types"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
dtypes "docker.io/go-docker/api/types" dtypes "github.com/docker/docker/api/types"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"

View File

@@ -6,7 +6,7 @@ import (
"testing" "testing"
"time" "time"
dtypes "docker.io/go-docker/api/types" dtypes "github.com/docker/docker/api/types"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"

View File

@@ -12,10 +12,10 @@ import (
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
client "docker.io/go-docker" "github.com/docker/docker/api/types"
"docker.io/go-docker/api/types" "github.com/docker/docker/api/types/filters"
"docker.io/go-docker/api/types/filters" "github.com/docker/docker/api/types/network"
"docker.io/go-docker/api/types/network" "github.com/docker/docker/client"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/play-with-docker/play-with-docker/config" "github.com/play-with-docker/play-with-docker/config"
"github.com/play-with-docker/play-with-docker/router" "github.com/play-with-docker/play-with-docker/router"
@@ -60,7 +60,7 @@ func director(protocol router.Protocol, host string) (*router.DirectorInfo, erro
func connectNetworks() error { func connectNetworks() error {
ctx := context.Background() ctx := context.Background()
c, err := client.NewEnvClient() c, err := client.NewClientWithOpts()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -91,7 +91,7 @@ func connectNetworks() error {
} }
func monitorNetworks() { func monitorNetworks() {
c, err := client.NewEnvClient() c, err := client.NewClientWithOpts()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -4,8 +4,8 @@ import (
"context" "context"
"testing" "testing"
dockerTypes "docker.io/go-docker/api/types" dockerTypes "github.com/docker/docker/api/types"
"docker.io/go-docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"

View File

@@ -4,7 +4,7 @@ import (
"context" "context"
"log" "log"
"docker.io/go-docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"

View File

@@ -4,8 +4,8 @@ import (
"context" "context"
"testing" "testing"
dockerTypes "docker.io/go-docker/api/types" dockerTypes "github.com/docker/docker/api/types"
"docker.io/go-docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"

View File

@@ -10,7 +10,7 @@ import (
"net/url" "net/url"
"time" "time"
dockerTypes "docker.io/go-docker/api/types" dockerTypes "github.com/docker/docker/api/types"
units "github.com/docker/go-units" units "github.com/docker/go-units"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"

View File

@@ -7,7 +7,7 @@ import (
"io" "io"
"testing" "testing"
dockerTypes "docker.io/go-docker/api/types" dockerTypes "github.com/docker/docker/api/types"
"github.com/play-with-docker/play-with-docker/docker" "github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event" "github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types" "github.com/play-with-docker/play-with-docker/pwd/types"