diff --git a/actions/update.go b/actions/update.go index b41d34c..ab6eb3a 100644 --- a/actions/update.go +++ b/actions/update.go @@ -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, noRestart bool) error { +func Update(client container.Client, names []string, cleanup bool, noRestart bool, noUpdate bool) error { log.Debug("Checking containers for updated images") containers, err := client.ListContainers(containerFilter(names)) @@ -59,43 +59,45 @@ func Update(client container.Client, names []string, cleanup bool, noRestart boo checkDependencies(containers) - // Stop stale containers in reverse order - for i := len(containers) - 1; i >= 0; i-- { - container := containers[i] + if !noUpdate { + // Stop stale containers in reverse order + for i := len(containers) - 1; i >= 0; i-- { + container := containers[i] - if container.IsWatchtower() { - continue - } - - if container.Stale { - if err := client.StopContainer(container, waitTime); err != nil { - log.Error(err) - } - } - } - - // Restart stale containers in sorted order - for _, container := range containers { - if container.Stale { - // Since we can't shutdown a watchtower container immediately, we need to - // start the new one while the old one is still running. This prevents us - // from re-using the same container name so we first rename the current - // instance so that the new one can adopt the old name. if container.IsWatchtower() { - if err := client.RenameContainer(container, randName()); err != nil { - log.Error(err) - continue - } + continue } - if !noRestart { - if err := client.StartContainer(container); err != nil { + if container.Stale { + if err := client.StopContainer(container, waitTime); err != nil { log.Error(err) } } + } - if cleanup { - client.RemoveImage(container) + // Restart stale containers in sorted order + for _, container := range containers { + if container.Stale { + // Since we can't shutdown a watchtower container immediately, we need to + // start the new one while the old one is still running. This prevents us + // from re-using the same container name so we first rename the current + // instance so that the new one can adopt the old name. + if container.IsWatchtower() { + if err := client.RenameContainer(container, randName()); err != nil { + log.Error(err) + continue + } + } + + if !noRestart { + if err := client.StartContainer(container); err != nil { + log.Error(err) + } + } + + if cleanup { + client.RemoveImage(container) + } } } } diff --git a/main.go b/main.go index 89a7f5f..42d592a 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ var ( scheduleSpec string cleanup bool noRestart bool + noUpdate bool notifier *notifications.Notifier ) @@ -76,6 +77,11 @@ func main() { Usage: "remove old images after updating", EnvVar: "WATCHTOWER_CLEANUP", }, + cli.BoolFlag{ + Name: "no-update", + Usage: "do not update container", + EnvVar: "WATCHTOWER_NO_UPDATE", + }, cli.BoolFlag{ Name: "tlsverify", Usage: "use TLS and verify the remote", @@ -146,6 +152,7 @@ func before(c *cli.Context) error { cleanup = c.GlobalBool("cleanup") noRestart = c.GlobalBool("no-restart") + noUpdate = c.GlobalBool("no-update") // configure environment vars for client err := envConfig(c) @@ -177,7 +184,7 @@ func start(c *cli.Context) error { case v := <- tryLockSem: defer func() { tryLockSem <- v }() notifier.StartNotification() - if err := actions.Update(client, names, cleanup, noRestart); err != nil { + if err := actions.Update(client, names, cleanup, noRestart, noUpdate); err != nil { log.Println(err) } notifier.SendNotification()