mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-17 04:38:06 +01:00
chore: update Docker API types to use new image package
This commit is contained in:
parent
d084f5604d
commit
ca0d37a4ac
11 changed files with 89 additions and 978 deletions
|
|
@ -77,7 +77,7 @@ const (
|
|||
)
|
||||
|
||||
type dockerClient struct {
|
||||
api sdkClient.CommonAPIClient
|
||||
api sdkClient.APIClient
|
||||
ClientOptions
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ func (client dockerClient) GetContainer(containerID t.ContainerID) (t.Container,
|
|||
}
|
||||
}
|
||||
|
||||
imageInfo, _, err := client.api.ImageInspectWithRaw(bg, containerInfo.Image)
|
||||
imageInfo, err := client.api.ImageInspect(bg, containerInfo.Image)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to retrieve container image info: %v", err)
|
||||
return &Container{containerInfo: &containerInfo, imageInfo: nil}, nil
|
||||
|
|
@ -332,7 +332,7 @@ func (client dockerClient) HasNewImage(ctx context.Context, container t.Containe
|
|||
currentImageID := t.ImageID(container.ContainerInfo().ContainerJSONBase.Image)
|
||||
imageName := container.ImageName()
|
||||
|
||||
newImageInfo, _, err := client.api.ImageInspectWithRaw(ctx, imageName)
|
||||
newImageInfo, err := client.api.ImageInspect(ctx, imageName)
|
||||
if err != nil {
|
||||
return false, currentImageID, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,8 @@ import (
|
|||
"github.com/beatkind/watchtower/pkg/filters"
|
||||
t "github.com/beatkind/watchtower/pkg/types"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
cli "github.com/docker/docker/client"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/onsi/gomega/gbytes"
|
||||
|
|
@ -79,8 +78,8 @@ var _ = Describe("the client", func() {
|
|||
When("removing a running container", func() {
|
||||
When("the container still exist after stopping", func() {
|
||||
It("should attempt to remove the container", func() {
|
||||
container := MockContainer(WithContainerState(types.ContainerState{Running: true}))
|
||||
containerStopped := MockContainer(WithContainerState(types.ContainerState{Running: false}))
|
||||
container := MockContainer(WithContainerState(dockerContainer.State{Running: true}))
|
||||
containerStopped := MockContainer(WithContainerState(dockerContainer.State{Running: false}))
|
||||
|
||||
cid := container.ContainerInfo().ID
|
||||
mockServer.AppendHandlers(
|
||||
|
|
@ -95,7 +94,7 @@ var _ = Describe("the client", func() {
|
|||
})
|
||||
When("the container does not exist after stopping", func() {
|
||||
It("should not cause an error", func() {
|
||||
container := MockContainer(WithContainerState(types.ContainerState{Running: true}))
|
||||
container := MockContainer(WithContainerState(dockerContainer.State{Running: true}))
|
||||
|
||||
cid := container.ContainerInfo().ID
|
||||
mockServer.AppendHandlers(
|
||||
|
|
@ -271,7 +270,7 @@ var _ = Describe("the client", func() {
|
|||
// API.ContainerExecCreate
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("POST", HaveSuffix("containers/%v/exec", containerID)),
|
||||
ghttp.VerifyJSONRepresenting(container.ExecOptions{
|
||||
ghttp.VerifyJSONRepresenting(dockerContainer.ExecOptions{
|
||||
User: user,
|
||||
Detach: false,
|
||||
Tty: true,
|
||||
|
|
@ -281,12 +280,12 @@ var _ = Describe("the client", func() {
|
|||
cmd,
|
||||
},
|
||||
}),
|
||||
ghttp.RespondWithJSONEncoded(http.StatusOK, types.IDResponse{ID: execID}),
|
||||
ghttp.RespondWithJSONEncoded(http.StatusOK, dockerContainer.CommitResponse{ID: execID}),
|
||||
),
|
||||
// API.ContainerExecStart
|
||||
ghttp.CombineHandlers(
|
||||
ghttp.VerifyRequest("POST", HaveSuffix("exec/%v/start", execID)),
|
||||
ghttp.VerifyJSONRepresenting(container.ExecStartOptions{
|
||||
ghttp.VerifyJSONRepresenting(dockerContainer.ExecStartOptions{
|
||||
Detach: false,
|
||||
Tty: true,
|
||||
}),
|
||||
|
|
@ -330,7 +329,7 @@ var _ = Describe("the client", func() {
|
|||
endpoints := map[string]*network.EndpointSettings{
|
||||
`test`: {Aliases: aliases},
|
||||
}
|
||||
container.containerInfo.NetworkSettings = &types.NetworkSettings{Networks: endpoints}
|
||||
container.containerInfo.NetworkSettings = &dockerContainer.NetworkSettings{Networks: endpoints}
|
||||
Expect(container.ContainerInfo().NetworkSettings.Networks[`test`].Aliases).To(Equal(aliases))
|
||||
Expect(client.GetNetworkConfig(container).EndpointsConfig[`test`].Aliases).To(Equal([]string{"One", "Two", "Four"}))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ import (
|
|||
wt "github.com/beatkind/watchtower/pkg/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
dockercontainer "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
|
||||
// NewContainer returns a new Container instance instantiated with the
|
||||
// specified ContainerInfo and ImageInfo structs.
|
||||
func NewContainer(containerInfo *types.ContainerJSON, imageInfo *types.ImageInspect) *Container {
|
||||
func NewContainer(containerInfo *dockercontainer.InspectResponse, imageInfo *image.InspectResponse) *Container {
|
||||
return &Container{
|
||||
containerInfo: containerInfo,
|
||||
imageInfo: imageInfo,
|
||||
|
|
@ -30,8 +30,8 @@ type Container struct {
|
|||
LinkedToRestarting bool
|
||||
Stale bool
|
||||
|
||||
containerInfo *types.ContainerJSON
|
||||
imageInfo *types.ImageInspect
|
||||
containerInfo *dockercontainer.InspectResponse
|
||||
imageInfo *image.InspectResponse
|
||||
}
|
||||
|
||||
// IsLinkedToRestarting returns the current value of the LinkedToRestarting field for the container
|
||||
|
|
@ -55,7 +55,7 @@ func (c *Container) SetStale(value bool) {
|
|||
}
|
||||
|
||||
// ContainerInfo fetches JSON info for the container
|
||||
func (c Container) ContainerInfo() *types.ContainerJSON {
|
||||
func (c Container) ContainerInfo() *dockercontainer.InspectResponse {
|
||||
return c.containerInfo
|
||||
}
|
||||
|
||||
|
|
@ -368,7 +368,7 @@ func (c Container) HasImageInfo() bool {
|
|||
}
|
||||
|
||||
// ImageInfo fetches the ImageInspect data of the current container
|
||||
func (c Container) ImageInfo() *types.ImageInspect {
|
||||
func (c Container) ImageInfo() *image.InspectResponse {
|
||||
return c.imageInfo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/api/types"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
|
||||
type MockContainerUpdate func(*types.ContainerJSON, *types.ImageInspect)
|
||||
type MockContainerUpdate func(*dockerContainer.InspectResponse, *image.InspectResponse)
|
||||
|
||||
func MockContainer(updates ...MockContainerUpdate) *Container {
|
||||
containerInfo := types.ContainerJSON{
|
||||
ContainerJSONBase: &types.ContainerJSONBase{
|
||||
containerInfo := dockerContainer.InspectResponse{
|
||||
ContainerJSONBase: &dockerContainer.ContainerJSONBase{
|
||||
ID: "container_id",
|
||||
Image: "image",
|
||||
Name: "test-containrrr",
|
||||
|
|
@ -20,7 +20,7 @@ func MockContainer(updates ...MockContainerUpdate) *Container {
|
|||
Labels: map[string]string{},
|
||||
},
|
||||
}
|
||||
image := types.ImageInspect{
|
||||
image := image.InspectResponse{
|
||||
ID: "image_id",
|
||||
Config: &dockerContainer.Config{},
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ func MockContainer(updates ...MockContainerUpdate) *Container {
|
|||
}
|
||||
|
||||
func WithPortBindings(portBindingSources ...string) MockContainerUpdate {
|
||||
return func(c *types.ContainerJSON, i *types.ImageInspect) {
|
||||
return func(c *dockerContainer.InspectResponse, i *image.InspectResponse) {
|
||||
portBindings := nat.PortMap{}
|
||||
for _, pbs := range portBindingSources {
|
||||
portBindings[nat.Port(pbs)] = []nat.PortBinding{}
|
||||
|
|
@ -42,38 +42,38 @@ func WithPortBindings(portBindingSources ...string) MockContainerUpdate {
|
|||
}
|
||||
|
||||
func WithImageName(name string) MockContainerUpdate {
|
||||
return func(c *types.ContainerJSON, i *types.ImageInspect) {
|
||||
return func(c *dockerContainer.InspectResponse, i *image.InspectResponse) {
|
||||
c.Config.Image = name
|
||||
i.RepoTags = append(i.RepoTags, name)
|
||||
}
|
||||
}
|
||||
|
||||
func WithLinks(links []string) MockContainerUpdate {
|
||||
return func(c *types.ContainerJSON, i *types.ImageInspect) {
|
||||
return func(c *dockerContainer.InspectResponse, i *image.InspectResponse) {
|
||||
c.HostConfig.Links = links
|
||||
}
|
||||
}
|
||||
|
||||
func WithLabels(labels map[string]string) MockContainerUpdate {
|
||||
return func(c *types.ContainerJSON, i *types.ImageInspect) {
|
||||
return func(c *dockerContainer.InspectResponse, i *image.InspectResponse) {
|
||||
c.Config.Labels = labels
|
||||
}
|
||||
}
|
||||
|
||||
func WithContainerState(state types.ContainerState) MockContainerUpdate {
|
||||
return func(cnt *types.ContainerJSON, img *types.ImageInspect) {
|
||||
func WithContainerState(state dockerContainer.State) MockContainerUpdate {
|
||||
return func(cnt *dockerContainer.InspectResponse, img *image.InspectResponse) {
|
||||
cnt.State = &state
|
||||
}
|
||||
}
|
||||
|
||||
func WithHealthcheck(healthConfig dockerContainer.HealthConfig) MockContainerUpdate {
|
||||
return func(cnt *types.ContainerJSON, img *types.ImageInspect) {
|
||||
return func(cnt *dockerContainer.InspectResponse, img *image.InspectResponse) {
|
||||
cnt.Config.Healthcheck = &healthConfig
|
||||
}
|
||||
}
|
||||
|
||||
func WithImageHealthcheck(healthConfig dockerContainer.HealthConfig) MockContainerUpdate {
|
||||
return func(cnt *types.ContainerJSON, img *types.ImageInspect) {
|
||||
return func(cnt *dockerContainer.InspectResponse, img *image.InspectResponse) {
|
||||
img.Config.Healthcheck = &healthConfig
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package container
|
|||
|
||||
import (
|
||||
"github.com/beatkind/watchtower/pkg/types"
|
||||
dc "github.com/docker/docker/api/types/container"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/go-connections/nat"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
|
@ -71,51 +71,51 @@ var _ = Describe("the container", func() {
|
|||
Describe("GetCreateConfig", func() {
|
||||
When("container healthcheck config is equal to image config", func() {
|
||||
It("should return empty healthcheck values", func() {
|
||||
c := MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c := MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
}), WithImageHealthcheck(dc.HealthConfig{
|
||||
}), WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{}))
|
||||
|
||||
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c = MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
Timeout: 30,
|
||||
}), WithImageHealthcheck(dc.HealthConfig{
|
||||
}), WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
Timeout: 30,
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{}))
|
||||
|
||||
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c = MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
StartPeriod: 30,
|
||||
}), WithImageHealthcheck(dc.HealthConfig{
|
||||
}), WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
StartPeriod: 30,
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{}))
|
||||
|
||||
c = MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c = MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
Retries: 30,
|
||||
}), WithImageHealthcheck(dc.HealthConfig{
|
||||
}), WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
Retries: 30,
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{}))
|
||||
})
|
||||
})
|
||||
When("container healthcheck config is different to image config", func() {
|
||||
It("should return the container healthcheck values", func() {
|
||||
c := MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c := MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
Interval: 30,
|
||||
Timeout: 30,
|
||||
StartPeriod: 10,
|
||||
Retries: 2,
|
||||
}), WithImageHealthcheck(dc.HealthConfig{
|
||||
}), WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "10s"},
|
||||
Interval: 10,
|
||||
Timeout: 60,
|
||||
StartPeriod: 30,
|
||||
Retries: 10,
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
Interval: 30,
|
||||
Timeout: 30,
|
||||
|
|
@ -126,7 +126,7 @@ var _ = Describe("the container", func() {
|
|||
})
|
||||
When("container healthcheck config is empty", func() {
|
||||
It("should not panic", func() {
|
||||
c := MockContainer(WithImageHealthcheck(dc.HealthConfig{
|
||||
c := MockContainer(WithImageHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "10s"},
|
||||
Interval: 10,
|
||||
Timeout: 60,
|
||||
|
|
@ -138,14 +138,14 @@ var _ = Describe("the container", func() {
|
|||
})
|
||||
When("container image healthcheck config is empty", func() {
|
||||
It("should not panic", func() {
|
||||
c := MockContainer(WithHealthcheck(dc.HealthConfig{
|
||||
c := MockContainer(WithHealthcheck(dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
Interval: 30,
|
||||
Timeout: 30,
|
||||
StartPeriod: 10,
|
||||
Retries: 2,
|
||||
}))
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dc.HealthConfig{
|
||||
Expect(c.GetCreateConfig().Healthcheck).To(Equal(&dockerContainer.HealthConfig{
|
||||
Test: []string{"/usr/bin/sleep", "1s"},
|
||||
Interval: 30,
|
||||
Timeout: 30,
|
||||
|
|
|
|||
|
|
@ -3,18 +3,19 @@ package mocks
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/onsi/ginkgo"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
|
||||
t "github.com/beatkind/watchtower/pkg/types"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
I "github.com/docker/docker/api/types/image"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
dockerImage "github.com/docker/docker/api/types/image"
|
||||
O "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/ghttp"
|
||||
)
|
||||
|
|
@ -166,7 +167,7 @@ func getContainerHandler(containerId string, responseHandler http.HandlerFunc) h
|
|||
}
|
||||
|
||||
// GetContainerHandler mocks the GET containers/{id}/json endpoint
|
||||
func GetContainerHandler(containerID string, containerInfo *types.ContainerJSON) http.HandlerFunc {
|
||||
func GetContainerHandler(containerID string, containerInfo *dockerContainer.InspectResponse) http.HandlerFunc {
|
||||
responseHandler := containerNotFoundResponse(containerID)
|
||||
if containerInfo != nil {
|
||||
responseHandler = ghttp.RespondWithJSONEncoded(http.StatusOK, containerInfo)
|
||||
|
|
@ -175,7 +176,7 @@ func GetContainerHandler(containerID string, containerInfo *types.ContainerJSON)
|
|||
}
|
||||
|
||||
// GetImageHandler mocks the GET images/{id}/json endpoint
|
||||
func GetImageHandler(imageInfo *types.ImageInspect) http.HandlerFunc {
|
||||
func GetImageHandler(imageInfo *dockerImage.InspectResponse) http.HandlerFunc {
|
||||
return getImageHandler(t.ImageID(imageInfo.ID), ghttp.RespondWithJSONEncoded(http.StatusOK, imageInfo))
|
||||
}
|
||||
|
||||
|
|
@ -196,8 +197,8 @@ func ListContainersHandler(statuses ...string) http.HandlerFunc {
|
|||
func respondWithFilteredContainers(filters filters.Args) http.HandlerFunc {
|
||||
containersJSON, err := getMockJSONFile("./mocks/data/containers.json")
|
||||
O.ExpectWithOffset(2, err).ShouldNot(O.HaveOccurred())
|
||||
var filteredContainers []types.Container
|
||||
var containers []types.Container
|
||||
var filteredContainers []dockerContainer.Summary
|
||||
var containers []dockerContainer.Summary
|
||||
O.ExpectWithOffset(2, json.Unmarshal(containersJSON, &containers)).To(O.Succeed())
|
||||
for _, v := range containers {
|
||||
for _, key := range filters.Get("status") {
|
||||
|
|
@ -263,12 +264,12 @@ func RemoveImageHandler(imagesWithParents map[string][]string) http.HandlerFunc
|
|||
image := parts[len(parts)-1]
|
||||
|
||||
if parents, found := imagesWithParents[image]; found {
|
||||
items := []I.DeleteResponse{
|
||||
items := []dockerImage.DeleteResponse{
|
||||
{Untagged: image},
|
||||
{Deleted: image},
|
||||
}
|
||||
for _, parent := range parents {
|
||||
items = append(items, I.DeleteResponse{Deleted: parent})
|
||||
items = append(items, dockerImage.DeleteResponse{Deleted: parent})
|
||||
}
|
||||
ghttp.RespondWithJSONEncoded(http.StatusOK, items)(w, r)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue