remove unwanted changes from merge delta

This commit is contained in:
Simon Aronsson 2019-04-04 20:35:19 +02:00
parent 385b6db472
commit ec98f52182
13 changed files with 144 additions and 295 deletions

View file

@ -1,32 +0,0 @@
##
# Build
##
FROM golang:alpine as build-env
RUN apk add --no-cache openssh-client git curl
RUN curl https://glide.sh/get | sh
WORKDIR /go/src/github.com/kopfkrieg/watchtower
COPY . .
# RUN set -x && \
# go get github.com/golang/dep/cmd/dep && \
# dep ensure -v
RUN glide install
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o watchtower .
# RUN go build -o watchtower .
##
# Watchtower
##
FROM alpine
LABEL "com.centurylinklabs.watchtower"="true"
RUN apk add --no-cache \
ca-certificates \
tzdata
COPY --from=build-env /go/src/github.com/kopfkrieg/watchtower/watchtower /
ENTRYPOINT ["/watchtower"]

View file

@ -1,9 +1,11 @@
# Note
This is a fork of the popular (but unfortunately unmaintained) project [v2tec/watchtower](https://github.com/v2tec/watchtower). This fork also includes a few of the unmerged pull requests. The goal is to revive the development of the project and make sure - in the long run - that it's maintained well through multiple maintainers.
# Watchtower
[![Circle CI](https://circleci.com/gh/containrrr/watchtower.svg?style=shield)](https://circleci.com/gh/containrrr/watchtower)
[![GoDoc](https://godoc.org/github.com/containrrr/watchtower?status.svg)](https://godoc.org/github.com/containrrr/watchtower)
[![](https://images.microbadger.com/badges/image/containrrr/watchtower.svg)](https://microbadger.com/images/containrrr/watchtower "Get your own image badge on microbadger.com")
[![Go Report Card](https://goreportcard.com/badge/github.com/containrrr/watchtower)](https://goreportcard.com/report/github.com/containrrr/watchtower)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
A process for watching your Docker containers and automatically restarting them whenever their base image is refreshed.
## Overview
@ -18,14 +20,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 kopfkrieg/watchtower Up 15 minutes watchtower
6cc4d2a9d1a5 containrrr/watchtower Up 15 minutes watchtower
```
Every few minutes 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 as simple as pulling the `kopfkrieg/watchtower` image.
Watchtower is itself packaged as a Docker container so installation is as simple as pulling the `containrrr/watchtower` image. If you are using ARM based architecture, pull the appropriate `containrrr/watchtower:armhf-<tag>` image from the [v2tec Docker Hub](https://hub.docker.com/r/containrrr/watchtower/tags/).
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.
@ -35,21 +37,33 @@ Run the `watchtower` container with the following command:
docker run -d \
--name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
kopfkrieg/watchtower
containrrr/watchtower
```
If pulling images from private Docker registries, supply registry authentication credentials with the environment variables `REPO_USER` and `REPO_PASS`
or by mounting the host's docker config file into the container (at the root of the container filesystem `/`).
Passing environment variables:
```bash
docker run -d \
--name watchtower \
-e REPO_USER=username \
-e REPO_PASS=password \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower container_to_watch --debug
```
Also check out [this Stack Overflow answer](https://stackoverflow.com/a/30494145/7872793) for more options on how to pass environment variables.
Mounting the host's docker config file:
```bash
docker run -d \
--name watchtower \
-v /home/<user>/.docker/config.json:/config.json \
-v /var/run/docker.sock:/var/run/docker.sock \
kopfkrieg/watchtower container_to_watch --debug
containrrr/watchtower container_to_watch --debug
```
If you mount the config file as described below, be sure to also prepend the url for the registry when starting up your watched image (you can omit the https://). Here is a complete docker-compose.yml file that starts up a docker container from a private repo at dockerhub and monitors it with watchtower. Note the command argument changing the interval to 30s rather than the default 5 minutes.
If you mount the config file as described above, be sure to also prepend the url for the registry when starting up your watched image (you can omit the https://). Here is a complete docker-compose.yml file that starts up a docker container from a private repo at dockerhub and monitors it with watchtower. Note the command argument changing the interval to 30s rather than the default 5 minutes.
```json
version: "3"
@ -60,7 +74,7 @@ services:
- "443:3443"
- "80:3080"
watchtower:
image: kopfkrieg/watchtower
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.docker/config.json:/config.json
@ -75,7 +89,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 \
kopfkrieg/watchtower nginx redis
containrrr/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.
@ -87,12 +101,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:
```bash
docker run --rm kopfkrieg/watchtower --help
docker run --rm containrrr/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) in 6 fields (rather than the traditional 5) which defines when and how often to check for new images. Either `--interval` or the schedule expression could be defined, but not both. An example: `--schedule "0 0 4 * * *" `
* `--schedule, -s` [Cron expression](https://godoc.org/github.com/robfig/cron#hdr-CRON_Expression_Format) in 6 fields (rather than the traditional 5) which defines when and how often to check for new images. Either `--interval` or the schedule expression could be defined, but not both. An example: `--schedule "0 0 4 * * *" `
* `--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.
* `--stop-timeout` Timeout before the container is forcefully stopped. When set, this option will change the default (`10s`) wait time to the given value. An example: `--stop-timeout 30s` will set the timeout to 30 seconds.
* `--label-enable` Watch containers where the `com.centurylinklabs.watchtower.enable` label is set to true.
@ -161,7 +175,7 @@ By default, watchtower is set-up to monitor the local Docker daemon (the same da
```bash
docker run -d \
--name watchtower \
kopfkrieg/watchtower --host "tcp://10.0.1.2:2375"
containrrr/watchtower --host "tcp://10.0.1.2:2375"
```
or
@ -170,7 +184,7 @@ or
docker run -d \
--name watchtower \
-e DOCKER_HOST="tcp://10.0.1.2:2375" \
kopfkrieg/watchtower
containrrr/watchtower
```
Note in both of the examples above that it is unnecessary to mount the */var/run/docker.sock* into the watchtower container.
@ -188,12 +202,12 @@ docker run -d \
--name watchtower \
-e DOCKER_HOST=$DOCKER_HOST \
-v $DOCKER_CERT_PATH:/etc/ssl/docker \
kopfkrieg/watchtower --tlsverify
containrrr/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 *kopfkrieg/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 *containrrr/watchtower* image is pushed to the Docker Hub, your watchtower will pull down the new image and restart itself automatically.
## Notifications
@ -232,7 +246,7 @@ docker run -d \
-e WATCHTOWER_NOTIFICATION_EMAIL_SERVER=smtp.gmail.com \
-e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER=fromaddress@gmail.com \
-e WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD=app_password \
kopfkrieg/watchtower
containrrr/watchtower
```
### Notifications through Slack webhook
@ -252,7 +266,7 @@ docker run -d \
-e WATCHTOWER_NOTIFICATIONS=slack \
-e WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL="https://hooks.slack.com/services/xxx/yyyyyyyyyyyyyyy" \
-e WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER=watchtower-server-1 \
kopfkrieg/watchtower
containrrr/watchtower
```
### Notifications via MSTeams incoming webhook
@ -272,5 +286,5 @@ docker run -d \
-e WATCHTOWER_NOTIFICATIONS=msteams \
-e WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL="https://outlook.office.com/webhook/xxxxxxxx@xxxxxxx/IncomingWebhook/yyyyyyyy/zzzzzzzzzz" \
-e WATCHTOWER_NOTIFICATION_MSTEAMS_USE_LOG_DATA=true \
kopfkrieg/watchtower
containrrr/watchtower
```

View file

@ -3,7 +3,7 @@ package actions
import (
"sort"
"github.com/kopfkrieg/watchtower/container"
"github.com/containrrr/watchtower/container"
)
// CheckPrereqs will ensure that there are not multiple instances of the

View file

@ -4,12 +4,12 @@ import (
"math/rand"
"time"
"github.com/kopfkrieg/watchtower/container"
log "github.com/sirupsen/logrus"
"github.com/containrrr/watchtower/container"
)
var (
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
)
// Update looks at the running Docker containers to see if any of the images

View file

@ -3,8 +3,8 @@ package container
import (
"testing"
"github.com/kopfkrieg/watchtower/container/mocks"
"github.com/stretchr/testify/assert"
"github.com/containrrr/watchtower/container/mocks"
)
func TestWatchtowerContainersFilter(t *testing.T) {

View file

@ -0,0 +1,20 @@
#
# Alpine image to get some needed data
#
FROM alpine:latest as alpine
RUN apk add --no-cache \
ca-certificates \
tzdata
#
# Image
#
FROM scratch
LABEL "com.centurylinklabs.watchtower"="true"
# copy files from other containers
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=alpine /usr/share/zoneinfo /usr/share/zoneinfo
COPY watchtower /
ENTRYPOINT ["/watchtower"]

View file

@ -0,0 +1,20 @@
#
# Alpine image to get some needed data
#
FROM alpine:latest as alpine
RUN apk add --no-cache \
ca-certificates \
tzdata
#
# Image
#
FROM scratch
LABEL "com.centurylinklabs.watchtower"="true"
# copy files from other containers
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=alpine /usr/share/zoneinfo /usr/share/zoneinfo
COPY watchtower /
ENTRYPOINT ["/watchtower"]

View file

@ -0,0 +1,53 @@
#!/bin/bash
PROGNAME=$(basename $0)
VERSION_BUILD=$1
function error_exit
{
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit 1
}
if [ "$1" = "" ]; then
error_exit "Please provide version as first argument."
fi
SEMVER=${VERSION_BUILD#*v}
VERSION=`echo $SEMVER | awk '{split($0,a,"."); print a[1]}'`
BUILD=`echo $SEMVER | awk '{split($0,a,"."); print a[2]}'`
PATCH=`echo $SEMVER | awk '{split($0,a,"."); print a[3]}'`
if [ "${VERSION}" = "" ]; then
echo "Please provide a semantic version."
exit 1
fi
if [ "${BUILD}" = "" ]; then
BUILD='0'
fi
if [ "${PATCH}" = "" ]; then
PATCH='0'
fi
push_docker() {
echo " -> push $1 $2"
docker tag $1 $2 || exit 1
docker push $2 || exit 1
}
push_all() {
IMAGE_NAME_VERSION=${1}${VERSION}.${BUILD}.${PATCH}
echo "Pulling $IMAGE_NAME_VERSION..."
docker pull ${IMAGE_NAME_VERSION} || exit 1
echo "Pushing $IMAGE_NAME_VERSION..."
push_docker ${IMAGE_NAME_VERSION} ${1}${VERSION}.${BUILD}
push_docker ${IMAGE_NAME_VERSION} ${1}${VERSION}
push_docker ${IMAGE_NAME_VERSION} ${1}latest
}
IMAGE_NAME=containrrr/watchtower
push_all ${IMAGE_NAME}:
push_all ${IMAGE_NAME}:armhf-
push_all ${IMAGE_NAME}:arm64v8-

193
glide.lock generated
View file

@ -1,193 +0,0 @@
hash: 23bcd62f9352c61d3aebc85a59f7ebbfaf80bc0201f45037cdea65820673ddeb
updated: 2018-03-01T13:21:55.8472118+01:00
imports:
- name: github.com/Azure/go-ansiterm
version: 388960b655244e76e24c75f48631564eaefade62
subpackages:
- winterm
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/docker/distribution
version: 28602af35aceda2f8d571bad7ca37a54cf0250bc
subpackages:
- context
- digest
- reference
- registry/api/errcode
- registry/api/v2
- registry/client
- registry/client/auth
- registry/client/auth/challenge
- registry/client/transport
- registry/storage/cache
- registry/storage/cache/memory
- uuid
- name: github.com/docker/docker
version: 092cba3727bb9b4a2f0e922cd6c0f93ea270e363
subpackages:
- api
- api/server/httputils
- api/types
- api/types/blkiodev
- api/types/container
- api/types/events
- api/types/filters
- api/types/mount
- api/types/network
- api/types/reference
- api/types/registry
- api/types/strslice
- api/types/swarm
- api/types/time
- api/types/versions
- api/types/volume
- cli/command
- cli/flags
- cliconfig
- cliconfig/configfile
- cliconfig/credentials
- client
- daemon/graphdriver
- dockerversion
- image
- image/v1
- layer
- oci
- opts
- pkg/archive
- pkg/chrootarchive
- pkg/fileutils
- pkg/homedir
- pkg/httputils
- pkg/idtools
- pkg/ioutils
- pkg/jsonlog
- pkg/jsonmessage
- pkg/longpath
- pkg/mount
- pkg/parsers/kernel
- pkg/plugingetter
- pkg/plugins
- pkg/plugins/transport
- pkg/pools
- pkg/promise
- pkg/random
- pkg/reexec
- pkg/stringid
- pkg/system
- pkg/tarsum
- pkg/term
- pkg/term/windows
- pkg/tlsconfig
- pkg/useragent
- plugin/v2
- reference
- registry
- name: github.com/docker/docker-credential-helpers
version: f72c04f1d8e71959a6d103f808c50ccbad79b9fd
subpackages:
- client
- credentials
- name: github.com/docker/go-connections
version: ecb4cb2dd420ada7df7f2593d6c25441f65f69f2
subpackages:
- nat
- sockets
- tlsconfig
- name: github.com/docker/go-units
version: 8a7beacffa3009a9ac66bad506b18ffdd110cf97
- name: github.com/docker/libtrust
version: 9cbd2a1374f46905c68a4eb3694a130610adc62a
- name: github.com/golang/protobuf
version: 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a
subpackages:
- proto
- name: github.com/gorilla/context
version: 1ea25387ff6f684839d82767c1733ff4d4d15d0a
- name: github.com/gorilla/mux
version: 0eeaf8392f5b04950925b8a69fe70f110fa7cbfc
- name: github.com/inconshreveable/mousetrap
version: 76626ae9c91c4f2a10f34cad8ce83ea42c93bb75
- name: github.com/johntdyer/slack-go
version: 95fac1160b220c5abcf8b0ef88e9c3cb213c09f4
- name: github.com/johntdyer/slackrus
version: 3992f319fd0ac349483279ef74742cd787841cba
- name: github.com/mattn/go-shellwords
version: f4e566c536cf69158e808ec28ef4182a37fdc981
- name: github.com/Microsoft/go-winio
version: fff283ad5116362ca252298cfc9b95828956d85d
- name: github.com/opencontainers/runc
version: 9df8b306d01f59d3a8029be411de015b7304dd8f
repo: https://github.com/docker/runc.git
subpackages:
- libcontainer/configs
- libcontainer/devices
- libcontainer/system
- libcontainer/user
- name: github.com/opencontainers/runtime-spec
version: 1c7c27d043c2a5e513a44084d2b10d77d1402b8c
subpackages:
- specs-go
- name: github.com/pkg/errors
version: 839d9e913e063e28dfd0e6c7b7512793e0a48be9
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/robfig/cron
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
- name: github.com/Sirupsen/logrus
version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f
repo: https://github.com/sirupsen/logrus.git
- name: github.com/sirupsen/logrus
version: ba1b36c82c5e05c4f912a88eab0dcd91a171688f
- name: github.com/spf13/cobra
version: a3c09249f1a24a9d951f2738fb9b9256b8b42fa5
repo: https://github.com/dnephin/cobra.git
- name: github.com/spf13/pflag
version: dabebe21bf790f782ea4c7bbd2efc430de182afd
- name: github.com/stretchr/objx
version: cbeaeb16a013161a98496fad62933b1d21786672
- name: github.com/stretchr/testify
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
subpackages:
- assert
- mock
- name: github.com/urfave/cli
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
- name: github.com/vbatts/tar-split
version: d3f1b54304d656376e58f9406a9cb4775799a357
subpackages:
- archive/tar
- tar/asm
- tar/storage
- name: golang.org/x/net
version: 2beffdc2e92c8a3027590f898fe88f69af48a3f8
repo: https://github.com/tonistiigi/net.git
subpackages:
- context
- context/ctxhttp
- http2
- http2/hpack
- internal/timeseries
- proxy
- trace
- name: golang.org/x/sys
version: 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
subpackages:
- unix
- windows
- name: google.golang.org/grpc
version: b1a2821ca5a4fd6b6e48ddfbb7d6d7584d839d21
subpackages:
- codes
- credentials
- grpclog
- internal
- metadata
- naming
- peer
- transport
testImports: []

View file

@ -1,33 +0,0 @@
package: github.com/kopfkrieg/watchtower
import:
- package: github.com/sirupsen/logrus
version: ~0.11.x
- package: github.com/Sirupsen/logrus
repo: https://github.com/sirupsen/logrus.git
version: ~0.11.x
- package: github.com/docker/docker
version: ~1.13.x
subpackages:
- api/types
- api/types/container
- api/types/network
- api/types/reference
- cli/command
- cliconfig
- cliconfig/configfile
- cliconfig/credentials
- client
- package: github.com/stretchr/testify
version: ~1.1.4
subpackages:
- mock
- package: github.com/urfave/cli
version: ~1.19.1
- package: golang.org/x/net
repo: https://github.com/tonistiigi/net.git
subpackages:
- context
- package: github.com/robfig/cron
version: 9585fd555638e77bba25f25db5c44b41f264aeb7
- package: github.com/johntdyer/slackrus
version: 3992f31

View file

@ -58,7 +58,7 @@ dockers:
goarch: amd64
goarm: ''
binary: watchtower
image: kopfkrieg/watchtower
image: containrrr/watchtower
dockerfile: dockerfile/amd64/Dockerfile
tag_templates:
- '{{ .Version }}'
@ -67,7 +67,7 @@ dockers:
goarch: arm
goarm: 6
binary: watchtower
image: kopfkrieg/watchtower
image: containrrr/watchtower
dockerfile: dockerfile/armhf/Dockerfile
tag_templates:
- 'armhf-{{ .Version }}'
@ -76,7 +76,7 @@ dockers:
goarch: arm64
goarm: ''
binary: watchtower
image: kopfkrieg/watchtower
image: containrrr/watchtower
dockerfile: dockerfile/arm64v8/Dockerfile
tag_templates:
- 'arm64v8-{{ .Version }}'

18
main.go
View file

@ -1,4 +1,4 @@
package main // import "github.com/kopfkrieg/watchtower"
package main // import "github.com/containrrr/watchtower"
import (
"os"
@ -8,12 +8,12 @@ import (
"strconv"
"github.com/kopfkrieg/watchtower/actions"
"github.com/kopfkrieg/watchtower/container"
"github.com/kopfkrieg/watchtower/notifications"
"github.com/robfig/cron"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/containrrr/watchtower/actions"
"github.com/containrrr/watchtower/container"
"github.com/containrrr/watchtower/notifications"
)
// DockerAPIMinVersion is the version of the docker API, which is minimally required by
@ -31,7 +31,7 @@ var (
noRestart bool
enableLabel bool
notifier *notifications.Notifier
timeout time.Duration
timeout time.Duration
)
func init() {
@ -84,10 +84,10 @@ func main() {
EnvVar: "DOCKER_TLS_VERIFY",
},
cli.DurationFlag{
Name: "stop-timeout",
Usage: "timeout before container is forcefully stopped",
Value: time.Second * 10,
EnvVar: "WATCHTOWER_TIMEOUT",
Name: "stop-timeout",
Usage: "timeout before container is forcefully stopped",
Value: time.Second * 10,
EnvVar: "WATCHTOWER_TIMEOUT",
},
cli.BoolFlag{
Name: "label-enable",

View file

@ -60,7 +60,7 @@ func (e *emailTypeNotifier) buildMessage(entries []*log.Entry) []byte {
}
t := time.Now()
header := make(map[string]string)
header["From"] = e.From
header["To"] = e.To