Skip to content

Commit a2158c2

Browse files
committed
fix merge conflicts and do some refactoring
2 parents 61d1ab1 + d748151 commit a2158c2

File tree

5 files changed

+239
-180
lines changed

5 files changed

+239
-180
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ watchtower
22
vendor
33
.glide
44
dist
5-
.idea
5+
.idea
6+
.DS_Store

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ docker run -d \
117117

118118
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.
119119

120+
If you do not want watchtower to run as a daemon you can pass a oneshot flag and remove the watchtower container after it's execution.
121+
122+
```bash
123+
docker run --rm \
124+
-v /var/run/docker.sock:/var/run/docker.sock \
125+
v2tec/watchtower --oneshot nginx redis
126+
```
127+
128+
In the example above, watchtower will execute an upgrade attempt on the containers named "nginx" and "redis". Using this mode will enable debugging output showing all actions performed as usage is intended for interactive users. Once the attempt is completed, the container will exit and remove itself due to the "--rm" flag.
129+
120130
When no arguments are specified, watchtower will monitor all running containers.
121131

122132
### Options
@@ -128,6 +138,7 @@ docker run --rm containrrr/watchtower --help
128138
```
129139

130140
* `--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.
141+
* `--oneshot` Run an update attempt against a container name list one time immediately and exit.
131142
* `--interval, -i` Poll interval (in seconds). This value controls how frequently watchtower will poll for new images. Defaults to 300 seconds (5 minutes).
132143
* `--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 * * *" `
133144
* `--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.

app/app.go

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package app
2+
3+
import (
4+
"time"
5+
6+
"github.com/urfave/cli"
7+
)
8+
9+
// SetupCliFlags registers flags on the supplied urfave app
10+
func SetupCliFlags(app *cli.App) {
11+
app.Flags = []cli.Flag{
12+
cli.StringFlag{
13+
Name: "host, H",
14+
Usage: "daemon socket to connect to",
15+
Value: "unix:///var/run/docker.sock",
16+
EnvVar: "DOCKER_HOST",
17+
},
18+
cli.IntFlag{
19+
Name: "interval, i",
20+
Usage: "poll interval (in seconds)",
21+
Value: 300,
22+
EnvVar: "WATCHTOWER_POLL_INTERVAL",
23+
},
24+
cli.StringFlag{
25+
Name: "schedule, s",
26+
Usage: "the cron expression which defines when to update",
27+
EnvVar: "WATCHTOWER_SCHEDULE",
28+
},
29+
cli.BoolFlag{
30+
Name: "no-pull",
31+
Usage: "do not pull new images",
32+
EnvVar: "WATCHTOWER_NO_PULL",
33+
},
34+
cli.BoolFlag{
35+
Name: "no-restart",
36+
Usage: "do not restart containers",
37+
EnvVar: "WATCHTOWER_NO_RESTART",
38+
},
39+
cli.BoolFlag{
40+
Name: "cleanup",
41+
Usage: "remove old images after updating",
42+
EnvVar: "WATCHTOWER_CLEANUP",
43+
},
44+
cli.BoolFlag{
45+
Name: "tlsverify",
46+
Usage: "use TLS and verify the remote",
47+
EnvVar: "DOCKER_TLS_VERIFY",
48+
},
49+
cli.DurationFlag{
50+
Name: "stop-timeout",
51+
Usage: "timeout before container is forcefully stopped",
52+
Value: time.Second * 10,
53+
EnvVar: "WATCHTOWER_TIMEOUT",
54+
},
55+
cli.BoolFlag{
56+
Name: "label-enable",
57+
Usage: "watch containers where the com.centurylinklabs.watchtower.enable label is true",
58+
EnvVar: "WATCHTOWER_LABEL_ENABLE",
59+
},
60+
cli.BoolFlag{
61+
Name: "debug",
62+
Usage: "enable debug mode with verbose logging",
63+
},
64+
cli.StringSliceFlag{
65+
Name: "notifications",
66+
Value: &cli.StringSlice{},
67+
Usage: "notification types to send (valid: email, slack, msteams)",
68+
EnvVar: "WATCHTOWER_NOTIFICATIONS",
69+
},
70+
cli.StringFlag{
71+
Name: "notifications-level",
72+
Usage: "The log level used for sending notifications. Possible values: \"panic\", \"fatal\", \"error\", \"warn\", \"info\" or \"debug\"",
73+
EnvVar: "WATCHTOWER_NOTIFICATIONS_LEVEL",
74+
Value: "info",
75+
},
76+
cli.StringFlag{
77+
Name: "notification-email-from",
78+
Usage: "Address to send notification e-mails from",
79+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_FROM",
80+
},
81+
cli.StringFlag{
82+
Name: "notification-email-to",
83+
Usage: "Address to send notification e-mails to",
84+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_TO",
85+
},
86+
cli.StringFlag{
87+
Name: "notification-email-server",
88+
Usage: "SMTP server to send notification e-mails through",
89+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER",
90+
},
91+
cli.IntFlag{
92+
Name: "notification-email-server-port",
93+
Usage: "SMTP server port to send notification e-mails through",
94+
Value: 25,
95+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT",
96+
},
97+
cli.BoolFlag{
98+
Name: "notification-email-server-tls-skip-verify",
99+
Usage: "Controls whether watchtower verifies the SMTP server's certificate chain and host name. " +
100+
"If set, TLS accepts any certificate " +
101+
"presented by the server and any host name in that certificate. " +
102+
"In this mode, TLS is susceptible to man-in-the-middle attacks. " +
103+
"This should be used only for testing.",
104+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_TLS_SKIP_VERIFY",
105+
},
106+
cli.StringFlag{
107+
Name: "notification-email-server-user",
108+
Usage: "SMTP server user for sending notifications",
109+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER",
110+
},
111+
cli.StringFlag{
112+
Name: "notification-email-server-password",
113+
Usage: "SMTP server password for sending notifications",
114+
EnvVar: "WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD",
115+
},
116+
cli.StringFlag{
117+
Name: "notification-slack-hook-url",
118+
Usage: "The Slack Hook URL to send notifications to",
119+
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL",
120+
},
121+
cli.StringFlag{
122+
Name: "notification-slack-identifier",
123+
Usage: "A string which will be used to identify the messages coming from this watchtower instance. Default if omitted is \"watchtower\"",
124+
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER",
125+
Value: "watchtower",
126+
},
127+
cli.StringFlag{
128+
Name: "notification-slack-channel",
129+
Usage: "A string which overrides the webhook's default channel. Example: #my-custom-channel",
130+
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_CHANNEL",
131+
},
132+
cli.StringFlag{
133+
Name: "notification-slack-icon-emoji",
134+
Usage: "An emoji code string to use in place of the default icon",
135+
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_EMOJI",
136+
},
137+
cli.StringFlag{
138+
Name: "notification-slack-icon-url",
139+
Usage: "An icon image URL string to use in place of the default icon",
140+
EnvVar: "WATCHTOWER_NOTIFICATION_SLACK_ICON_URL",
141+
},
142+
cli.StringFlag{
143+
Name: "notification-msteams-hook",
144+
Usage: "The MSTeams WebHook URL to send notifications to",
145+
EnvVar: "WATCHTOWER_NOTIFICATION_MSTEAMS_HOOK_URL",
146+
},
147+
cli.BoolFlag{
148+
Name: "notification-msteams-data",
149+
Usage: "The MSTeams notifier will try to extract log entry fields as MSTeams message facts",
150+
EnvVar: "WATCHTOWER_NOTIFICATION_MSTEAMS_USE_LOG_DATA",
151+
},
152+
cli.BoolFlag{
153+
Name: "monitor-only",
154+
Usage: "Will only monitor for new images, not update the containers",
155+
EnvVar: "WATCHTOWER_MONITOR_ONLY",
156+
},
157+
cli.BoolFlag{
158+
Name: "run-once",
159+
Usage: "Run once now and exit",
160+
},
161+
}
162+
}

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
1414
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 h1:4BX8f882bXEDKfWIf0wa8HRvpnBoPszJJXL+TVbBw4M=
1515
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
1616
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
17+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1718
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1819
github.com/docker/cli v0.0.0-20190327152802-57b27434ea29 h1:ciaXDHaWQda0nvevWqcjtXX/buQY3e0lga1vq8Batq0=
1920
github.com/docker/cli v0.0.0-20190327152802-57b27434ea29/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
@@ -74,6 +75,7 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P
7475
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7576
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
7677
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
78+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7779
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7880
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
7981
github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740=
@@ -98,8 +100,10 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
98100
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
99101
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
100102
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
103+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
101104
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
102105
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
106+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
103107
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
104108
github.com/theupdateframework/notary v0.6.1 h1:7wshjstgS9x9F5LuB1L5mBI2xNMObWqjz+cjWoom6l0=
105109
github.com/theupdateframework/notary v0.6.1/go.mod h1:MOfgIfmox8s7/7fduvB2xyPPMJCrjRLRizA8OFwpnKY=

0 commit comments

Comments
 (0)