Add a method of enabling or disabling containers using labels

Switch command line flag from no-enable to label-enable and simplify logic

Add basic documentation for the --label-enable flag
This commit is contained in:
Kaleb Elwert 2017-10-17 06:53:30 +02:00 committed by Fabrizio Steiner
parent f365014b8f
commit de2ac9341d
4 changed files with 56 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package container
import (
"fmt"
"strconv"
"strings"
"github.com/docker/docker/api/types"
@ -11,6 +12,7 @@ import (
const (
watchtowerLabel = "com.centurylinklabs.watchtower"
signalLabel = "com.centurylinklabs.watchtower.stop-signal"
enableLabel = "com.centurylinklabs.watchtower.enable"
zodiacLabel = "com.centurylinklabs.zodiac.original-image"
)
@ -64,6 +66,22 @@ func (c Container) ImageName() string {
return imageName
}
// Enabled returns the value of the container enabled label and if the label
// was set.
func (c Container) Enabled() (bool, bool) {
rawBool, ok := c.containerInfo.Config.Labels[enableLabel]
if !ok {
return false, false
}
parsedBool, err := strconv.ParseBool(rawBool)
if err != nil {
return false, false
}
return parsedBool, true
}
// Links returns a list containing the names of all the containers to which
// this container is linked.
func (c Container) Links() []string {