mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
feat: add no-pull label for containers (#1574)
Co-authored-by: Nedžad Alibegović <nedzad@nedzad.dev> Co-authored-by: nils måsén <nils@piksel.se>
This commit is contained in:
parent
6ace7bd0dd
commit
bbbe04119c
5 changed files with 66 additions and 13 deletions
|
@ -234,6 +234,9 @@ Environment Variable: WATCHTOWER_NO_PULL
|
||||||
Default: false
|
Default: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that no-pull can also be specified on a per-container basis with the
|
||||||
|
`com.centurylinklabs.watchtower.no-pull` label set on those containers.
|
||||||
|
|
||||||
## Without sending a startup message
|
## Without sending a startup message
|
||||||
Do not send a message after watchtower started. Otherwise there will be an info-level notification.
|
Do not send a message after watchtower started. Otherwise there will be an info-level notification.
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -207,6 +207,39 @@ var _ = Describe("the container", func() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
When("checking no-pull label", func() {
|
||||||
|
When("no-pull label is true", func() {
|
||||||
|
c := MockContainer(WithLabels(map[string]string{
|
||||||
|
"com.centurylinklabs.watchtower.no-pull": "true",
|
||||||
|
}))
|
||||||
|
It("should return true", func() {
|
||||||
|
Expect(c.IsNoPull()).To(Equal(true))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("no-pull label is false", func() {
|
||||||
|
c := MockContainer(WithLabels(map[string]string{
|
||||||
|
"com.centurylinklabs.watchtower.no-pull": "false",
|
||||||
|
}))
|
||||||
|
It("should return false", func() {
|
||||||
|
Expect(c.IsNoPull()).To(Equal(false))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("no-pull label is set to an invalid value", func() {
|
||||||
|
c := MockContainer(WithLabels(map[string]string{
|
||||||
|
"com.centurylinklabs.watchtower.no-pull": "maybe",
|
||||||
|
}))
|
||||||
|
It("should return false", func() {
|
||||||
|
Expect(c.IsNoPull()).To(Equal(false))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
When("no-pull label is unset", func() {
|
||||||
|
c = MockContainer(WithLabels(map[string]string{}))
|
||||||
|
It("should return false", func() {
|
||||||
|
Expect(c.IsNoPull()).To(Equal(false))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
When("there is a pre or post update timeout", func() {
|
When("there is a pre or post update timeout", func() {
|
||||||
It("should return minute values", func() {
|
It("should return minute values", func() {
|
||||||
c = MockContainer(WithLabels(map[string]string{
|
c = MockContainer(WithLabels(map[string]string{
|
||||||
|
|
|
@ -5,6 +5,7 @@ const (
|
||||||
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"
|
||||||
|
noPullLabel = "com.centurylinklabs.watchtower.no-pull"
|
||||||
dependsOnLabel = "com.centurylinklabs.watchtower.depends-on"
|
dependsOnLabel = "com.centurylinklabs.watchtower.depends-on"
|
||||||
zodiacLabel = "com.centurylinklabs.zodiac.original-image"
|
zodiacLabel = "com.centurylinklabs.zodiac.original-image"
|
||||||
scope = "com.centurylinklabs.watchtower.scope"
|
scope = "com.centurylinklabs.watchtower.scope"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue