diff --git a/go.mod b/go.mod index 758ce36..8eca0f4 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.18 require ( github.com/containrrr/shoutrrr v0.7.1 - github.com/docker/cli v20.10.23+incompatible + github.com/docker/cli v23.0.1+incompatible github.com/docker/distribution v2.8.1+incompatible - github.com/docker/docker v20.10.23+incompatible + github.com/docker/docker v23.0.1+incompatible github.com/docker/go-connections v0.4.0 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.26.0 diff --git a/go.sum b/go.sum index e2fcad6..14d752b 100644 --- a/go.sum +++ b/go.sum @@ -240,10 +240,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/cli v20.10.23+incompatible h1:qwyha/T3rXk9lfuVcn533cKFc7n/6IzL5GXVAgMVPBg= github.com/docker/cli v20.10.23+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/cli v23.0.1+incompatible h1:LRyWITpGzl2C9e9uGxzisptnxAn1zfZKXy13Ul2Q5oM= +github.com/docker/cli v23.0.1+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.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= +github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.6.1 h1:Dq4iIfcM7cNtddhLVWe9h4QDjsi4OER3Z8voPu/I52g= github.com/docker/docker-credential-helpers v0.6.1/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= diff --git a/pkg/container/client.go b/pkg/container/client.go index 7447828..908229e 100644 --- a/pkg/container/client.go +++ b/pkg/container/client.go @@ -39,9 +39,9 @@ type Client interface { // NewClient returns a new Client instance which can be used to interact with // the Docker API. // The client reads its configuration from the following environment variables: -// * DOCKER_HOST the docker-engine host to send api requests to -// * DOCKER_TLS_VERIFY whether to verify tls certificates -// * DOCKER_API_VERSION the minimum docker api version to work with +// - DOCKER_HOST the docker-engine host to send api requests to +// - DOCKER_TLS_VERIFY whether to verify tls certificates +// - DOCKER_API_VERSION the minimum docker api version to work with func NewClient(opts ClientOptions) Client { cli, err := sdkClient.NewClientWithOpts(sdkClient.FromEnv) @@ -177,14 +177,20 @@ func (client dockerClient) StopContainer(c Container, timeout time.Duration) err shortID := c.ID().ShortID() if c.IsRunning() { - log.Infof("Stopping %s (%s) with %s", c.Name(), shortID, signal) - if err := client.api.ContainerKill(bg, idStr, signal); err != nil { + var maxWaitSeconds int = int(timeout.Milliseconds()) + stopOptions := container.StopOptions{ + Signal: "", + Timeout: &maxWaitSeconds, + } + log.Infof("Stopping %s (%s) with %s, Timeout: %i", c.Name(), shortID, signal, maxWaitSeconds) + if err := client.api.ContainerStop(bg, idStr, stopOptions); err != nil { return err } } // TODO: This should probably be checked. - _ = client.waitForStopOrTimeout(c, timeout) + // ContainerStop has been implemented above with a SIGKILL if timeout is reached. This is no longer required + // _ = client.waitForStopOrTimeout(c, timeout) if c.containerInfo.HostConfig.AutoRemove { log.Debugf("AutoRemove container %s, skipping ContainerRemove call.", shortID)