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.
pull/1/head
Brian DeHamer 9 years ago
parent a238521fc4
commit 7cf2d7f1d8

@ -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
}

@ -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{

Loading…
Cancel
Save