Skip to content

Commit

Permalink
bump github.com/docker/docker from v20.10.23+incompatible to v23.0.5+…
Browse files Browse the repository at this point in the history
…incompatible (#76)
  • Loading branch information
jesusfcr authored May 4, 2023
1 parent 11cdb18 commit 70b4bfb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: go
services:
- docker
go:
- 1.18.x
- 1.19.x
env:
global:
- CGO_ENABLED=1
Expand Down
20 changes: 15 additions & 5 deletions backend/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

const (
abortTimeout = 5 * time.Second
abortTimeout = 5 // Seconds.
defaultDockerIfaceName = "docker0"
)

Expand Down Expand Up @@ -158,7 +158,7 @@ func NewBackend(log log.Logger, cfg config.Config, updater ConfigUpdater) (backe
retries := cfgReg.BackoffMaxRetries
re := retryer.NewRetryer(retries, interval, log)

envCli, err := client.NewClientWithOpts(client.FromEnv)
envCli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return &Docker{}, err
}
Expand Down Expand Up @@ -316,6 +316,7 @@ func (b *Docker) run(ctx context.Context, params backend.RunParams, res chan<- b
cc, err := b.cli.ContainerCreate(ctx, cfg.ContainerConfig, cfg.HostConfig, cfg.NetConfig, nil, "")
contID := cc.ID
if err != nil {
b.log.Errorf("Container create error: %+v", err)
res <- backend.RunResult{Error: err}
return
}
Expand All @@ -339,6 +340,10 @@ func (b *Docker) run(ctx context.Context, params backend.RunParams, res chan<- b
var exit int64
select {
case err = <-errC:
b.log.Errorf("containerWait err: err.Error(): %s ctx.Err(): %+v", err.Error(), ctx.Err())
if err.Error() == "" && ctx.Err() != nil {
err = ctx.Err()
}
case result := <-resultC:
if result.Error == nil {
exit = result.StatusCode
Expand All @@ -364,17 +369,22 @@ func (b *Docker) run(ctx context.Context, params backend.RunParams, res chan<- b
// finish a time out.
b.log.Infof("check: %s timeout or aborted ensure container %s is stopped", params.CheckID, contID)
timeout := abortTimeout
b.cli.ContainerStop(context.Background(), contID, &timeout)
stopErr := b.cli.ContainerStop(context.Background(), contID, container.StopOptions{
Timeout: &timeout,
})
if stopErr != nil {
b.log.Errorf("Unable to stop container %s, %+v", contID, stopErr)
}
}

out, logErr := b.getContainerlogs(contID)
if logErr != nil {
b.log.Errorf("getting logs for the check %s, %+v", params.CheckID, err)
b.log.Errorf("getting logs for the check %s, %+v", params.CheckID, logErr)
}
res <- backend.RunResult{Output: out, Error: err}
}

func (b Docker) getContainerlogs(ID string) ([]byte, error) {
func (b *Docker) getContainerlogs(ID string) ([]byte, error) {
logOpts := types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Expand Down
28 changes: 18 additions & 10 deletions backend/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/docker/docker/client"
"github.com/google/go-cmp/cmp"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)

func TestIntegrationDockerRun(t *testing.T) {
Expand All @@ -44,7 +45,7 @@ func TestIntegrationDockerRun(t *testing.T) {
{
name: "ExecutesADockerContainer",
setup: func() *Docker {
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func TestIntegrationDockerRunKillContainer(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
Expand All @@ -127,7 +128,7 @@ func TestIntegrationDockerRunKillContainer(t *testing.T) {
PullPolicy: config.PullPolicyNever,
},
agentAddr: "an addr",
log: &log.NullLog{},
log: logrus.New(),
cli: cli,
}
err = buildDockerImage("testdata/DockerfileSleep", "vulcan-check")
Expand Down Expand Up @@ -175,7 +176,7 @@ func TestIntegrationDockerDetectUnexpectedExit(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
Expand All @@ -185,7 +186,7 @@ func TestIntegrationDockerDetectUnexpectedExit(t *testing.T) {
PullPolicy: config.PullPolicyNever,
},
agentAddr: "an addr",
log: &log.NullLog{},
log: logrus.New(),
cli: cli,
}
err = buildDockerImage("testdata/DockerfileSleep", "vulcan-check")
Expand Down Expand Up @@ -227,7 +228,7 @@ func TestIntegrationDockerRunAbortGracefully(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -287,7 +288,7 @@ func TestIntegrationDockerFindImage(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
cli, err := client.NewClientWithOpts(client.FromEnv)
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -351,7 +352,11 @@ func TestIntegrationDockerFindImage(t *testing.T) {

// Check if the valid references are valid.
for _, v := range c.valids {
if exists, _ := b.imageExists(context.Background(), v); !exists {
exists, err := b.imageExists(context.Background(), v)
if err != nil {
t.Errorf("image:%s %s error:%+v", c.image, v, err)
}
if !exists {
t.Errorf("image:%s %s should exists", c.image, v)
}
}
Expand All @@ -367,8 +372,11 @@ func TestIntegrationDockerFindImage(t *testing.T) {

// Skip if it is valid.
if !valid {
// This reference should'n exists
if exists, _ := b.imageExists(context.Background(), r); exists {
exists, err := b.imageExists(context.Background(), r)
if err != nil {
t.Errorf("image:%s %s error:%+v", c.image, r, err)
}
if exists {
t.Errorf("image:%s %s should not exists", c.image, r)
}
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/adevinta/vulcan-agent

go 1.18
go 1.19

require (
github.com/BurntSushi/toml v1.2.1
Expand All @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go v1.44.256
github.com/docker/cli v23.0.5+incompatible
github.com/docker/distribution v2.8.1+incompatible
github.com/docker/docker v20.10.23+incompatible
github.com/docker/docker v23.0.5+incompatible
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/gorilla/websocket v1.5.0
Expand All @@ -31,7 +31,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
gotest.tools/v3 v3.2.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/docker/cli v23.0.5+incompatible h1:ufWmAOuD3Vmr7JP2G5K3cyuNC4YZWiAsuD
github.com/docker/cli v23.0.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v20.10.23+incompatible h1:1ZQUUYAdh+oylOT85aA2ZcfRp22jmLhoaEcVEfK8dyA=
github.com/docker/docker v20.10.23+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v23.0.5+incompatible h1:DaxtlTJjFSnLOXVNUBU1+6kXGz2lpDoEAH6QoxaSg8k=
github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.6.4 h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
github.com/docker/docker-credential-helpers v0.6.4/go.mod h1:ofX3UI0Gz1TteYBjtgs07O36Pyasyp66D2uKT7H8W1c=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
Expand Down Expand Up @@ -92,8 +92,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down

0 comments on commit 70b4bfb

Please sign in to comment.