mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 06:06:38 +01:00
implemented enableLabel by a Filter
This commit is contained in:
parent
f5fb4ed6a2
commit
026a04b59b
6 changed files with 79 additions and 46 deletions
|
|
@ -6,14 +6,12 @@ import (
|
|||
"github.com/v2tec/watchtower/container"
|
||||
)
|
||||
|
||||
func watchtowerContainersFilter(c container.Container) bool { return c.IsWatchtower() }
|
||||
|
||||
// CheckPrereqs will ensure that there are not multiple instances of the
|
||||
// watchtower running simultaneously. If multiple watchtower containers are
|
||||
// detected, this function will stop and remove all but the most recently
|
||||
// started container.
|
||||
func CheckPrereqs(client container.Client, cleanup bool) error {
|
||||
containers, err := client.ListContainers(watchtowerContainersFilter)
|
||||
containers, err := client.ListContainers(container.WatchtowerContainersFilter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,31 +12,14 @@ var (
|
|||
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
)
|
||||
|
||||
func allContainersFilter(container.Container) bool { return true }
|
||||
|
||||
func containerFilter(names []string) container.Filter {
|
||||
if len(names) == 0 {
|
||||
return allContainersFilter
|
||||
}
|
||||
|
||||
return func(c container.Container) bool {
|
||||
for _, name := range names {
|
||||
if (name == c.Name()) || (name == c.Name()[1:]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Update looks at the running Docker containers to see if any of the images
|
||||
// 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, timeout time.Duration) error {
|
||||
func Update(client container.Client, filter container.Filter, cleanup bool, noRestart bool, timeout time.Duration) error {
|
||||
log.Debug("Checking containers for updated images")
|
||||
|
||||
containers, err := client.ListContainers(containerFilter(names))
|
||||
containers, err := client.ListContainers(filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue