feat: add no-pull label for containers

This commit is contained in:
Nedžad Alibegović 2022-10-07 21:30:46 +02:00 committed by Gilbert Gilb's
parent 6ace7bd0dd
commit 75cc6b8c65
3 changed files with 30 additions and 13 deletions

View file

@ -280,7 +280,7 @@ func (client dockerClient) RenameContainer(c Container, newName string) error {
func (client dockerClient) IsContainerStale(container Container) (stale bool, latestImage t.ImageID, err error) { func (client dockerClient) IsContainerStale(container Container) (stale bool, latestImage t.ImageID, err error) {
ctx := context.Background() ctx := context.Background()
if !client.PullImages { if !client.PullImages || container.IsNoPull() {
log.Debugf("Skipping image pull.") log.Debugf("Skipping image pull.")
} else if err := client.PullImage(ctx, container); err != nil { } else if err := client.PullImage(ctx, container); err != nil {
return false, container.SafeImageID(), err return false, container.SafeImageID(), err

View file

@ -125,6 +125,22 @@ func (c Container) IsMonitorOnly() bool {
return parsedBool return parsedBool
} }
// IsNoPull returns the value of the no-pull label. If the label is not set
// then false is returned.
func (c Container) IsNoPull() bool {
rawBool, ok := c.getLabelValue(noPullLabel)
if !ok {
return false
}
parsedBool, err := strconv.ParseBool(rawBool)
if err != nil {
return false
}
return parsedBool
}
// Scope returns the value of the scope UID label and if the label // Scope returns the value of the scope UID label and if the label
// was set. // was set.
func (c Container) Scope() (string, bool) { func (c Container) Scope() (string, bool) {

View file

@ -1,18 +1,19 @@
package container package container
const ( const (
watchtowerLabel = "com.centurylinklabs.watchtower" watchtowerLabel = "com.centurylinklabs.watchtower"
signalLabel = "com.centurylinklabs.watchtower.stop-signal" signalLabel = "com.centurylinklabs.watchtower.stop-signal"
enableLabel = "com.centurylinklabs.watchtower.enable" enableLabel = "com.centurylinklabs.watchtower.enable"
monitorOnlyLabel = "com.centurylinklabs.watchtower.monitor-only" monitorOnlyLabel = "com.centurylinklabs.watchtower.monitor-only"
dependsOnLabel = "com.centurylinklabs.watchtower.depends-on" noPullLabel = "com.centurylinklabs.watchtower.no-pull"
zodiacLabel = "com.centurylinklabs.zodiac.original-image" dependsOnLabel = "com.centurylinklabs.watchtower.depends-on"
scope = "com.centurylinklabs.watchtower.scope" zodiacLabel = "com.centurylinklabs.zodiac.original-image"
preCheckLabel = "com.centurylinklabs.watchtower.lifecycle.pre-check" scope = "com.centurylinklabs.watchtower.scope"
postCheckLabel = "com.centurylinklabs.watchtower.lifecycle.post-check" preCheckLabel = "com.centurylinklabs.watchtower.lifecycle.pre-check"
preUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update" postCheckLabel = "com.centurylinklabs.watchtower.lifecycle.post-check"
postUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.post-update" preUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update"
preUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update-timeout" postUpdateLabel = "com.centurylinklabs.watchtower.lifecycle.post-update"
preUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.pre-update-timeout"
postUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.post-update-timeout" postUpdateTimeoutLabel = "com.centurylinklabs.watchtower.lifecycle.post-update-timeout"
) )