Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
FROM centurylink/ca-certs
MAINTAINER CenturyLink Labs <[email protected]>
LABEL "com.centurylinklabs.watchtower"="true"
FROM ubuntu:14.04

COPY watchtower /
ENTRYPOINT ["/watchtower"]
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)&nbsp;
[![Circle CI](https://circleci.com/gh/CenturyLinkLabs/watchtower.svg?style=svg)](https://circleci.com/gh/CenturyLinkLabs/watchtower)&nbsp;
[![GoDoc](https://godoc.org/github.com/CenturyLinkLabs/watchtower?status.svg)](https://godoc.org/github.com/CenturyLinkLabs/watchtower)&nbsp;
[![](https://badge.imagelayers.io/centurylink/watchtower:latest.svg)](https://imagelayers.io/?images=centurylink/watchtower:latest 'Get your own badge on imagelayers.io')

Expand Down Expand Up @@ -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.
Expand Down
38 changes: 34 additions & 4 deletions container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package container
import (
"crypto/tls"
"fmt"
"os"
"time"

log "github.com/Sirupsen/logrus"
Expand All @@ -13,6 +14,10 @@ const (
defaultStopSignal = "SIGTERM"
)

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.
type Filter func(Container) bool
Expand Down Expand Up @@ -111,7 +116,19 @@ func (client dockerClient) StartContainer(c Container) error {

log.Infof("Starting %s", name)

newContainerID, err := client.api.CreateContainer(config, name)
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set dockerclient.URL manually to os.Getenv("REPO_REGISTRY"), if not empty, or something?

} else {
newContainerID, err = client.api.CreateContainer(config, name, nil)
}

if err != nil {
return err
}
Expand All @@ -132,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, nil); 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)
Expand All @@ -153,7 +183,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
}

Expand Down