From b1e70f494eda22f77085c3f9bd881eb0ca3b03ff Mon Sep 17 00:00:00 2001 From: Erin Corson Date: Tue, 23 Feb 2016 14:03:28 -0700 Subject: [PATCH 1/4] will not compile without these updates due to change in docker lib --- container/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container/client.go b/container/client.go index 2196784..3c92637 100644 --- a/container/client.go +++ b/container/client.go @@ -111,7 +111,7 @@ func (client dockerClient) StartContainer(c Container) error { log.Infof("Starting %s", name) - newContainerID, err := client.api.CreateContainer(config, name) + newContainerID, err := client.api.CreateContainer(config, name, nil) if err != nil { return err } @@ -153,7 +153,7 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) { func (client dockerClient) RemoveImage(c Container) error { imageID := c.ImageID() log.Infof("Removing image %s", imageID) - _, err := client.api.RemoveImage(imageID) + _, err := client.api.RemoveImage(imageID, true) return err } From f5801669abba693fabd625191741d867b064127f Mon Sep 17 00:00:00 2001 From: Erin Corson Date: Tue, 23 Feb 2016 18:33:29 -0700 Subject: [PATCH 2/4] updates --- Dockerfile | 4 +--- container/client.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 075b956..551f13a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ -FROM centurylink/ca-certs -MAINTAINER CenturyLink Labs -LABEL "com.centurylinklabs.watchtower"="true" +FROM ubuntu:14.04 COPY watchtower / ENTRYPOINT ["/watchtower"] diff --git a/container/client.go b/container/client.go index 2196784..8f50629 100644 --- a/container/client.go +++ b/container/client.go @@ -13,6 +13,12 @@ const ( defaultStopSignal = "SIGTERM" ) +var auth = dockerclient.AuthConfig{ + Username: "", + Password: "", + Email: "", +} + // A Filter is a prototype for a function that can be used to filter the // results from a call to the ListContainers() method on the Client. type Filter func(Container) bool @@ -111,7 +117,7 @@ func (client dockerClient) StartContainer(c Container) error { log.Infof("Starting %s", name) - newContainerID, err := client.api.CreateContainer(config, name) + newContainerID, err := client.api.CreateContainer(config, name, &auth) if err != nil { return err } @@ -132,7 +138,7 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) { if client.pullImages { log.Debugf("Pulling %s for %s", imageName, c.Name()) - if err := client.api.PullImage(imageName, nil); err != nil { + if err := client.api.PullImage(imageName, &auth); err != nil { return false, err } } @@ -153,7 +159,7 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) { func (client dockerClient) RemoveImage(c Container) error { imageID := c.ImageID() log.Infof("Removing image %s", imageID) - _, err := client.api.RemoveImage(imageID) + _, err := client.api.RemoveImage(imageID, true) return err } From d36899dd7c33cef6eb7bd73681c114008e08a647 Mon Sep 17 00:00:00 2001 From: Erin Corson Date: Tue, 23 Feb 2016 19:40:35 -0700 Subject: [PATCH 3/4] parameterize repo auth --- container/client.go | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/container/client.go b/container/client.go index 9f7d7b7..8e1605f 100644 --- a/container/client.go +++ b/container/client.go @@ -3,6 +3,7 @@ package container import ( "crypto/tls" "fmt" + "os" "time" log "github.com/Sirupsen/logrus" @@ -13,11 +14,9 @@ const ( defaultStopSignal = "SIGTERM" ) -var auth = dockerclient.AuthConfig{ - Username: "", - Password: "", - Email: "", -} +var username = os.Getenv("REPO_USER") +var password = os.Getenv("REPO_PASS") +var email = os.Getenv("REPO_EMAIL") // A Filter is a prototype for a function that can be used to filter the // results from a call to the ListContainers() method on the Client. @@ -117,7 +116,18 @@ func (client dockerClient) StartContainer(c Container) error { log.Infof("Starting %s", name) - newContainerID, err := client.api.CreateContainer(config, name, &auth) + var err error + var newContainerID string + if username != "" && password != "" && email != "" { + auth := dockerclient.AuthConfig{ + Username: username, + Password: password, + Email: email, + } + newContainerID, err = client.api.CreateContainer(config, name, &auth) + } else { + newContainerID, err = client.api.CreateContainer(config, name, nil) + } if err != nil { return err @@ -139,9 +149,22 @@ func (client dockerClient) IsContainerStale(c Container) (bool, error) { if client.pullImages { log.Debugf("Pulling %s for %s", imageName, c.Name()) - if err := client.api.PullImage(imageName, &auth); err != nil { - return false, err + + if username != "" && password != "" && email != "" { + auth := dockerclient.AuthConfig{ + Username: username, + Password: password, + Email: email, + } + if err := client.api.PullImage(imageName, &auth); err != nil { + return false, err + } + } else { + if err := client.api.PullImage(imageName, nil); err != nil { + return false, err + } } + } newImageInfo, err := client.api.InspectImage(imageName) From c8bb6c349dd95cd04f05c7b21787036445ecaea2 Mon Sep 17 00:00:00 2001 From: Erin Corson Date: Tue, 23 Feb 2016 19:44:19 -0700 Subject: [PATCH 4/4] readme update --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c77ed4f..f17f826 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Watchtower ![Watchtower](http://panamax.ca.tier3.io/zodiac/logo-watchtower_thumb.png) -[![Circle CI](https://circleci.com/gh/CenturyLinkLabs/watchtower.svg?style=svg)](https://circleci.com/gh/CenturyLinkLabs/watchtower)  +[![Circle CI](https://circleci.com/gh/CenturyLinkLabs/watchtower.svg?style=svg)](https://circleci.com/gh/CenturyLinkLabs/watchtower)  [![GoDoc](https://godoc.org/github.com/CenturyLinkLabs/watchtower?status.svg)](https://godoc.org/github.com/CenturyLinkLabs/watchtower)  [![](https://badge.imagelayers.io/centurylink/watchtower:latest.svg)](https://imagelayers.io/?images=centurylink/watchtower:latest 'Get your own badge on imagelayers.io') @@ -39,6 +39,16 @@ docker run -d \ centurylink/watchtower ``` +For private images: + +``` +docker run -d \ + --name watchtower \ + -e REPO_USER="username" -e REPO_PASS="pass" -e REPO_EMAIL="email" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + drud/watchtower container_to_watch --debug +``` + ### Arguments By default, watchtower will monitor all containers running within the Docker daemon to which it is pointed (in most cases this will be the local Docker daemon, but you can override it with the `--host` option described in the next section). However, you can restrict watchtower to monitoring a subset of the running containers by specifying the container names as arguments when launching watchtower.