Fix aggressive image pulling

In cases where a container's image was specified without an explicit tag
watchtower was pulling ALL of the images. Fixed so that a ":latest" tag
is assumed if one hasn't been explicitly set.
pull/1/head
Brian DeHamer 9 years ago
parent 31b6a30686
commit 13ec7ac94e

@ -1,7 +1,9 @@
package docker
import (
"fmt"
"log"
"strings"
"github.com/samalba/dockerclient"
)
@ -66,6 +68,10 @@ func (client DockerClient) RefreshImage(c *Container) error {
imageName := containerInfo.Config.Image
if pullImages {
if !strings.Contains(imageName, ":") {
imageName = fmt.Sprintf("%s:latest", imageName)
}
log.Printf("Pulling %s for %s\n", imageName, c.Name())
if err := client.api.PullImage(imageName, nil); err != nil {
return err

@ -80,8 +80,8 @@ func TestRefreshImage_NotStaleSuccess(t *testing.T) {
newImageInfo := &dockerclient.ImageInfo{Id: "abc123"}
api := mockclient.NewMockClient()
api.On("PullImage", "bar", mock.Anything).Return(nil)
api.On("InspectImage", "bar").Return(newImageInfo, nil)
api.On("PullImage", "bar:latest", mock.Anything).Return(nil)
api.On("InspectImage", "bar:latest").Return(newImageInfo, nil)
client := DockerClient{api: api}
err := client.RefreshImage(c)
@ -95,15 +95,15 @@ func TestRefreshImage_StaleSuccess(t *testing.T) {
c := &Container{
containerInfo: &dockerclient.ContainerInfo{
Name: "foo",
Config: &dockerclient.ContainerConfig{Image: "bar"},
Config: &dockerclient.ContainerConfig{Image: "bar:1.0"},
},
imageInfo: &dockerclient.ImageInfo{Id: "abc123"},
}
newImageInfo := &dockerclient.ImageInfo{Id: "xyz789"}
api := mockclient.NewMockClient()
api.On("PullImage", "bar", mock.Anything).Return(nil)
api.On("InspectImage", "bar").Return(newImageInfo, nil)
api.On("PullImage", "bar:1.0", mock.Anything).Return(nil)
api.On("InspectImage", "bar:1.0").Return(newImageInfo, nil)
client := DockerClient{api: api}
err := client.RefreshImage(c)
@ -117,13 +117,13 @@ func TestRefreshImage_PullImageError(t *testing.T) {
c := &Container{
containerInfo: &dockerclient.ContainerInfo{
Name: "foo",
Config: &dockerclient.ContainerConfig{Image: "bar"},
Config: &dockerclient.ContainerConfig{Image: "bar:latest"},
},
imageInfo: &dockerclient.ImageInfo{Id: "abc123"},
}
api := mockclient.NewMockClient()
api.On("PullImage", "bar", mock.Anything).Return(errors.New("oops"))
api.On("PullImage", "bar:latest", mock.Anything).Return(errors.New("oops"))
client := DockerClient{api: api}
err := client.RefreshImage(c)
@ -137,15 +137,15 @@ func TestRefreshImage_InspectImageError(t *testing.T) {
c := &Container{
containerInfo: &dockerclient.ContainerInfo{
Name: "foo",
Config: &dockerclient.ContainerConfig{Image: "bar"},
Config: &dockerclient.ContainerConfig{Image: "bar:latest"},
},
imageInfo: &dockerclient.ImageInfo{Id: "abc123"},
}
newImageInfo := &dockerclient.ImageInfo{}
api := mockclient.NewMockClient()
api.On("PullImage", "bar", mock.Anything).Return(nil)
api.On("InspectImage", "bar").Return(newImageInfo, errors.New("uh-oh"))
api.On("PullImage", "bar:latest", mock.Anything).Return(nil)
api.On("InspectImage", "bar:latest").Return(newImageInfo, errors.New("uh-oh"))
client := DockerClient{api: api}
err := client.RefreshImage(c)

Loading…
Cancel
Save