mirror of
https://github.com/containrrr/watchtower.git
synced 2024-12-12 09:04:17 +02:00
Merge pull request #9 from haswalt/master
Configure with ENV vars and allow skipping of restart
This commit is contained in:
commit
04220147e2
@ -34,7 +34,7 @@ func containerFilter(names []string) container.Filter {
|
|||||||
// used to start those containers have been updated. If a change is detected in
|
// 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
|
// any of the images, the associated containers are stopped and restarted with
|
||||||
// the new image.
|
// 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")
|
log.Info("Checking containers for updated images")
|
||||||
|
|
||||||
containers, err := client.ListContainers(containerFilter(names))
|
containers, err := client.ListContainers(containerFilter(names))
|
||||||
@ -86,8 +86,10 @@ func Update(client container.Client, names []string, cleanup bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.StartContainer(container); err != nil {
|
if !noRestart {
|
||||||
log.Error(err)
|
if err := client.StartContainer(container); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cleanup {
|
if cleanup {
|
||||||
|
26
main.go
26
main.go
@ -23,6 +23,7 @@ var (
|
|||||||
client container.Client
|
client container.Client
|
||||||
pollInterval time.Duration
|
pollInterval time.Duration
|
||||||
cleanup bool
|
cleanup bool
|
||||||
|
noRestart bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -49,17 +50,25 @@ func main() {
|
|||||||
EnvVar: "DOCKER_HOST",
|
EnvVar: "DOCKER_HOST",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "interval, i",
|
Name: "interval, i",
|
||||||
Usage: "poll interval (in seconds)",
|
Usage: "poll interval (in seconds)",
|
||||||
Value: 300,
|
Value: 300,
|
||||||
|
EnvVar: "WATCHTOWER_POLL_INTERVAL",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "no-pull",
|
Name: "no-pull",
|
||||||
Usage: "do not pull new images",
|
Usage: "do not pull new images",
|
||||||
|
EnvVar: "WATCHTOWER_NO_PULL",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "cleanup",
|
Name: "no-restart",
|
||||||
Usage: "remove old images after updating",
|
Usage: "do not restart containers",
|
||||||
|
EnvVar: "WATCHTOWER_NO_RESTART",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "cleanup",
|
||||||
|
Usage: "remove old images after updating",
|
||||||
|
EnvVar: "WATCHTOWER_CLEANUP",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "tls",
|
Name: "tls",
|
||||||
@ -103,6 +112,7 @@ func before(c *cli.Context) error {
|
|||||||
|
|
||||||
pollInterval = time.Duration(c.Int("interval")) * time.Second
|
pollInterval = time.Duration(c.Int("interval")) * time.Second
|
||||||
cleanup = c.GlobalBool("cleanup")
|
cleanup = c.GlobalBool("cleanup")
|
||||||
|
noRestart = c.GlobalBool("no-restart")
|
||||||
|
|
||||||
// Set-up container client
|
// Set-up container client
|
||||||
tls, err := tlsConfig(c)
|
tls, err := tlsConfig(c)
|
||||||
@ -125,7 +135,7 @@ func start(c *cli.Context) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
if err := actions.Update(client, names, cleanup); err != nil {
|
if err := actions.Update(client, names, cleanup, noRestart); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
|
Loading…
Reference in New Issue
Block a user