Skip to content

Commit

Permalink
Merge branch 'master' into net
Browse files Browse the repository at this point in the history
  • Loading branch information
stffabi authored Jan 24, 2017
2 parents b45fc5a + eda5391 commit db47382
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 106 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
watchtower
vendor
.glide
22 changes: 5 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,9 @@ cd watchtower
## Building and testing
watchtower is a go application and is built with go commands. The following commands assume that you are at the root level of your repo.
```bash
go get ./... # analyzes and retrieves package dependencies
go build # compiles and packages an executable binary, watchtower
go test # runs tests
./watchtower # runs the application (outside of a container)
go get -u github.com/Masterminds/glide # installs glide for vendoring
glide install # retrieves package dependencies
go build # compiles and packages an executable binary, watchtower
go test # runs tests
./watchtower # runs the application (outside of a container)
```

### Building the docker image
watchtower is packaged and distributed as a docker image. A [golang-builder](https://github.com/CenturyLinkLabs/golang-builder) is used to package the go code and its
dependencies as a minimally-sized application. The application binary is then layered into to a minimal docker image (see `Dockerfile`), so that the entire image is <10MB.
See `circle.yml` for further details.The following commands assume that you are at the root level of your repo (i.e. `watchtower/`).

```bash
docker pull centurylink/golang-builder:latest # download the builder
docker run -v $(pwd):/src centurylink/golang-builder:latest # build the minimal binary
docker build -t <yourfork>/watchtower:latest . # build the docker image
docker run -v /var/run/docker.sock:/var/run/docker.sock <yourfork>/watchtower # run the application (inside of a container)
```

6 changes: 0 additions & 6 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015 CenturyLink
Copyright 2015 Watchtower contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +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;
[![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')
[![Circle CI](https://circleci.com/gh/v2tec/watchtower.svg?style=svg)](https://circleci.com/gh/v2tec/watchtower)&nbsp;
[![GoDoc](https://godoc.org/github.com/v2tec/watchtower?status.svg)](https://godoc.org/github.com/v2tec/watchtower)&nbsp;
[![](https://images.microbadger.com/badges/image/v2tec/watchtower.svg)](https://microbadger.com/images/v2tec/watchtower "Get your own image badge on microbadger.com")

A process for watching your Docker containers and automatically restarting them whenever their base image is refreshed.

Expand All @@ -19,14 +17,14 @@ For example, let's say you were running watchtower along with an instance of *ce
$ docker ps
CONTAINER ID IMAGE STATUS PORTS NAMES
967848166a45 centurylink/wetty-cli Up 10 minutes 0.0.0.0:8080->3000/tcp wetty
6cc4d2a9d1a5 centurylink/watchtower Up 15 minutes watchtower
6cc4d2a9d1a5 v2tec/watchtower Up 15 minutes watchtower
```

Every few mintutes watchtower will pull the latest *centurylink/wetty-cli* image and compare it to the one that was used to run the "wetty" container. If it sees that the image has changed it will stop/remove the "wetty" container and then restart it using the new image and the same `docker run` options that were used to start the container initially (in this case, that would include the `-p 8080:3000` port mapping).

## Usage

Watchtower is itself packaged as a Docker container so installation is a simple as pulling the `centurylink/watchtower` image.
Watchtower is itself packaged as a Docker container so installation is as simple as pulling the `v2tec/watchtower` image.

Since the watchtower code needs to interact with the Docker API in order to monitor the running containers, you need to mount */var/run/docker.sock* into the container with the -v flag when you run it.

Expand All @@ -36,7 +34,7 @@ Run the `watchtower` container with the following command:
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
centurylink/watchtower
v2tec/watchtower
```

If pulling images from private Docker registries, supply registry authentication credentials with the environment variables `REPO_USER` and `REPO_PASS`
Expand All @@ -58,7 +56,7 @@ By default, watchtower will monitor all containers running within the Docker dae
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
centurylink/watchtower nginx redis
v2tec/watchtower nginx redis
```

In the example above, watchtower will only monitor the containers named "nginx" and "redis" for updates -- all of the other running containers will be ignored.
Expand All @@ -70,11 +68,12 @@ When no arguments are specified, watchtower will monitor all running containers.
Any of the options described below can be passed to the watchtower process by setting them after the image name in the `docker run` string:

```
docker run --rm centurylink/watchtower --help
docker run --rm v2tec/watchtower --help
```

* `--host, -h` Docker daemon socket to connect to. Defaults to "unix:///var/run/docker.sock" but can be pointed at a remote Docker host by specifying a TCP endpoint as "tcp://hostname:port". The host value can also be provided by setting the `DOCKER_HOST` environment variable.
* `--interval, -i` Poll interval (in seconds). This value controls how frequently watchtower will poll for new images. Defaults to 300 seconds (5 minutes).
* `--schedule, -s` [Cron expression](https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format) which defines when and how often to check for new images. Either `--interval` or the schedule expression could be defined, but not both.
* `--no-pull` Do not pull new images. When this flag is specified, watchtower will not attempt to pull new images from the registry. Instead it will only monitor the local image cache for changes. Use this option if you are building new images directly on the Docker host without pushing them to a registry.
* `--cleanup` Remove old images after updating. When this flag is specified, watchtower will remove the old image after restarting a container with a new image. Use this option to prevent the accumulation of orphaned images on your system as containers are updated.
* `--tlsverify` Use TLS when connecting to the Docker socket and verify the server's certificate.
Expand Down Expand Up @@ -112,7 +111,7 @@ By default, watchtower is set-up to monitor the local Docker daemon (the same da
```
docker run -d \
--name watchtower \
centurylink/watchtower --host "tcp://10.0.1.2:2375"
v2tec/watchtower --host "tcp://10.0.1.2:2375"
```

or
Expand All @@ -121,7 +120,7 @@ or
docker run -d \
--name watchtower \
-e DOCKER_HOST="tcp://10.0.1.2:2375" \
centurylink/watchtower
v2tec/watchtower
```

Note in both of the examples above that it is unnecessary to mount the */var/run/docker.sock* into the watchtower container.
Expand All @@ -139,9 +138,9 @@ docker run -d \
--name watchtower \
-e DOCKER_HOST=$DOCKER_HOST \
-v $DOCKER_CERT_PATH:/etc/ssl/docker \
centurylink/watchtower --tlsverify
v2tec/watchtower --tlsverify
```

## Updating Watchtower

If watchtower is monitoring the same Docker daemon under which the watchtower container itself is running (i.e. if you volume-mounted */var/run/docker.sock* into the watchtower container) then it has the ability to update itself. If a new version of the *centurylink/watchtower* image is pushed to the Docker Hub, your watchtower will pull down the new image and restart itself automatically.
If watchtower is monitoring the same Docker daemon under which the watchtower container itself is running (i.e. if you volume-mounted */var/run/docker.sock* into the watchtower container) then it has the ability to update itself. If a new version of the *v2tec/watchtower* image is pushed to the Docker Hub, your watchtower will pull down the new image and restart itself automatically.
2 changes: 1 addition & 1 deletion actions/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package actions
import (
"sort"

"github.com/CenturyLinkLabs/watchtower/container"
"github.com/v2tec/watchtower/container"
)

func watchtowerContainersFilter(c container.Container) bool { return c.IsWatchtower() }
Expand Down
10 changes: 6 additions & 4 deletions actions/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"math/rand"
"time"

"github.com/CenturyLinkLabs/watchtower/container"
log "github.com/Sirupsen/logrus"
"github.com/v2tec/watchtower/container"
)

var (
Expand Down Expand Up @@ -34,7 +34,7 @@ func containerFilter(names []string) container.Filter {
// used to start those containers have been updated. If a change is detected in
// any of the images, the associated containers are stopped and restarted with
// the new image.
func Update(client container.Client, names []string, cleanup bool) error {
func Update(client container.Client, names []string, cleanup bool, noRestart bool) error {
log.Info("Checking containers for updated images")

containers, err := client.ListContainers(containerFilter(names))
Expand Down Expand Up @@ -88,8 +88,10 @@ func Update(client container.Client, names []string, cleanup bool) error {
}
}

if err := client.StartContainer(container); err != nil {
log.Error(err)
if !noRestart {
if err := client.StartContainer(container); err != nil {
log.Error(err)
}
}

if cleanup {
Expand Down
21 changes: 2 additions & 19 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
machine:
services:
- docker
environment:
IMAGE_NAME: centurylink/watchtower

dependencies:
override:
- docker pull centurylink/golang-builder:latest
- go get -u github.com/Masterminds/glide

test:
override:
- glide install
- docker run -v $(pwd):/src centurylink/golang-builder:latest --test

deployment:
hub:
branch: master
commands:
- docker run -v $(pwd):/src centurylink/golang-builder:latest
- docker build -t $IMAGE_NAME:latest .
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker push $IMAGE_NAME:latest
hub_mirror:
branch: [master, auth]
owner: rosscado
commands:
- docker run -v $(pwd):/src centurylink/golang-builder:latest
- docker build -t rosscado/watchtower:latest .
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker push rosscado/watchtower:latest
5 changes: 2 additions & 3 deletions container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ func (client dockerClient) StartContainer(c Container) error {
}

func (client dockerClient) RenameContainer(c Container, newName string) error {
bg := context.Background()
log.Debugf("Renaming container %s (%s) to %s", c.Name(), c.ID(), newName)
//return client.api.ContainerRename(c.ID(), newName)
// no op
return nil
return client.api.ContainerRename(bg, c.ID(), newName)
}

func (client dockerClient) IsContainerStale(c Container) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion container/mockclient/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package mockclient
import (
"time"

"github.com/CenturyLinkLabs/watchtower/container"
"github.com/stretchr/testify/mock"
"github.com/v2tec/watchtower/container"
)

type MockClient struct {
Expand Down
2 changes: 1 addition & 1 deletion container/mockclient/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/CenturyLinkLabs/watchtower/container"
"github.com/v2tec/watchtower/container"
)

func TestMockInterface(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions container/trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package container

import (
"errors"
"os"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/reference"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/cliconfig/configfile"
"github.com/docker/docker/cliconfig/credentials"
"os"
"strings"
)

/**
Expand Down Expand Up @@ -80,14 +81,13 @@ func ParseServerAddress(ref string) (string, error) {
}
parts := strings.Split(repository, "/")
return parts[0], nil

}

// CredentialsStore returns a new credentials store based
// on the settings provided in the configuration file.
func CredentialsStore(configFile configfile.ConfigFile) credentials.Store {
if configFile.CredentialsStore != "" {
return credentials.NewNativeStore(&configFile)
return credentials.NewNativeStore(&configFile, configFile.CredentialsStore)
}
return credentials.NewFileStore(&configFile)
}
Expand Down
Loading

0 comments on commit db47382

Please sign in to comment.