watchtower/actions/check.go

28 lines
568 B
Go
Raw Normal View History

2015-07-21 16:04:41 +00:00
package actions
import (
"sort"
"github.com/CenturyLinkLabs/watchtower/container"
)
func watchtowerContainersFilter(c container.Container) bool { return c.IsWatchtower() }
2015-07-21 19:37:18 +00:00
func CheckPrereqs(client container.Client) error {
2015-07-21 16:04:41 +00:00
containers, err := client.ListContainers(watchtowerContainersFilter)
if err != nil {
return err
}
if len(containers) > 1 {
sort.Sort(container.ByCreated(containers))
// Iterate over all containers execept the last one
for _, c := range containers[0 : len(containers)-1] {
2015-07-21 22:41:58 +00:00
client.StopContainer(c, 60)
2015-07-21 16:04:41 +00:00
}
}
return nil
}