refactor: extract code from the container package

This commit is contained in:
Simon Aronsson 2020-01-11 23:35:25 +01:00
parent 4130b110c6
commit d1abce889a
15 changed files with 253 additions and 185 deletions

View file

@ -3,6 +3,8 @@ package actions
import (
"errors"
"fmt"
"github.com/containrrr/watchtower/pkg/filters"
"github.com/containrrr/watchtower/pkg/sorter"
"sort"
"strings"
"time"
@ -19,7 +21,7 @@ import (
// will stop and remove all but the most recently started container.
func CheckForMultipleWatchtowerInstances(client container.Client, cleanup bool) error {
awaitDockerClient()
containers, err := client.ListContainers(container.WatchtowerContainersFilter)
containers, err := client.ListContainers(filters.WatchtowerContainersFilter)
if err != nil {
log.Fatal(err)
@ -39,7 +41,7 @@ func cleanupExcessWatchtowers(containers []container.Container, client container
var cleanupErrors int
var stopErrors int
sort.Sort(container.ByCreated(containers))
sort.Sort(sorter.ByCreated(containers))
allContainersExceptLast := containers[0 : len(containers)-1]
for _, c := range allContainersExceptLast {