From 7cf2d7f1d85171b0a8f5791c94712da27b9ef9fa Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Wed, 12 Aug 2015 20:49:45 +0000 Subject: [PATCH] Support Zodiac-based deployments Since Zodiac always uses image IDs for deployments we can relay on the standard container image field to determine the image that was used to start the container. Luckily, Zodiac writes the original image name to a label in the container metadata. If we find that Zodiac-specific label on a running container we will use the associated value when trying to determine if the container's image has changed. --- container/container.go | 8 +++++++- container/container_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/container/container.go b/container/container.go index 024b83d..6693807 100644 --- a/container/container.go +++ b/container/container.go @@ -10,6 +10,7 @@ import ( const ( watchtowerLabel = "com.centurylinklabs.watchtower" signalLabel = "com.centurylinklabs.watchtower.stop-signal" + zodiacLabel = "com.centurylinklabs.zodiac.original-image" ) // NewContainer returns a new Container instance instantiated with the @@ -49,7 +50,11 @@ func (c Container) ImageID() string { // container. If the original image was specified without a particular tag, the // "latest" tag is assumed. func (c Container) ImageName() string { - imageName := c.containerInfo.Config.Image + // Compatibility w/ Zodiac deployments + imageName, ok := c.containerInfo.Config.Labels[zodiacLabel] + if !ok { + imageName = c.containerInfo.Config.Image + } if !strings.Contains(imageName, ":") { imageName = fmt.Sprintf("%s:latest", imageName) @@ -135,6 +140,7 @@ func (c Container) runtimeConfig() *dockerclient.ContainerConfig { config.ExposedPorts[p] = struct{}{} } + config.Image = c.ImageName() return config } diff --git a/container/container_test.go b/container/container_test.go index 8c91c1a..af30ab2 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -57,6 +57,19 @@ func TestImageName_Untagged(t *testing.T) { assert.Equal(t, "foo:latest", c.ImageName()) } +func TestImageName_Zodiac(t *testing.T) { + c := Container{ + containerInfo: &dockerclient.ContainerInfo{ + Config: &dockerclient.ContainerConfig{ + Labels: map[string]string{"com.centurylinklabs.zodiac.original-image": "foo"}, + Image: "1234567890", + }, + }, + } + + assert.Equal(t, "foo:latest", c.ImageName()) +} + func TestLinks(t *testing.T) { c := Container{ containerInfo: &dockerclient.ContainerInfo{