mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
Feat/lifecycle hooks (#351)
* feat(update): add lifecycle hooks to the update action * fix(ci): add bash tests for lifecycle-hooks to the ci workflow * fix(ci): move integration tests to an isolated step * fix(ci): fix malformed all-contributors json * fix(ci): disable automatic bash test until we figure out a reasonable way to run it in circleci
This commit is contained in:
parent
874180a518
commit
bfae38dbf8
12 changed files with 499 additions and 73 deletions
|
|
@ -10,13 +10,6 @@ import (
|
|||
dockercontainer "github.com/docker/docker/api/types/container"
|
||||
)
|
||||
|
||||
const (
|
||||
watchtowerLabel = "com.centurylinklabs.watchtower"
|
||||
signalLabel = "com.centurylinklabs.watchtower.stop-signal"
|
||||
enableLabel = "com.centurylinklabs.watchtower.enable"
|
||||
zodiacLabel = "com.centurylinklabs.zodiac.original-image"
|
||||
)
|
||||
|
||||
// NewContainer returns a new Container instance instantiated with the
|
||||
// specified ContainerInfo and ImageInfo structs.
|
||||
func NewContainer(containerInfo *types.ContainerJSON, imageInfo *types.ImageInspect) *Container {
|
||||
|
|
@ -28,7 +21,8 @@ func NewContainer(containerInfo *types.ContainerJSON, imageInfo *types.ImageInsp
|
|||
|
||||
// Container represents a running Docker container.
|
||||
type Container struct {
|
||||
Stale bool
|
||||
Linked bool
|
||||
Stale bool
|
||||
|
||||
containerInfo *types.ContainerJSON
|
||||
imageInfo *types.ImageInspect
|
||||
|
|
@ -62,7 +56,7 @@ func (c Container) ImageID() string {
|
|||
// "latest" tag is assumed.
|
||||
func (c Container) ImageName() string {
|
||||
// Compatibility w/ Zodiac deployments
|
||||
imageName, ok := c.containerInfo.Config.Labels[zodiacLabel]
|
||||
imageName, ok := c.getLabelValue(zodiacLabel)
|
||||
if !ok {
|
||||
imageName = c.containerInfo.Config.Image
|
||||
}
|
||||
|
|
@ -77,7 +71,7 @@ func (c Container) ImageName() string {
|
|||
// 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]
|
||||
rawBool, ok := c.getLabelValue(enableLabel)
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
|
|
@ -105,6 +99,12 @@ func (c Container) Links() []string {
|
|||
return links
|
||||
}
|
||||
|
||||
// ToRestart return whether the container should be restarted, either because
|
||||
// is stale or linked to another stale container.
|
||||
func (c Container) ToRestart() bool {
|
||||
return c.Stale || c.Linked
|
||||
}
|
||||
|
||||
// IsWatchtower returns a boolean flag indicating whether or not the current
|
||||
// container is the watchtower container itself. The watchtower container is
|
||||
// identified by the presence of the "com.centurylinklabs.watchtower" label in
|
||||
|
|
@ -117,11 +117,7 @@ func (c Container) IsWatchtower() bool {
|
|||
// container's metadata. If the container has not specified a custom stop
|
||||
// signal, the empty string "" is returned.
|
||||
func (c Container) StopSignal() string {
|
||||
if val, ok := c.containerInfo.Config.Labels[signalLabel]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
return ""
|
||||
return c.getLabelValueOrEmpty(signalLabel)
|
||||
}
|
||||
|
||||
// Ideally, we'd just be able to take the ContainerConfig from the old container
|
||||
|
|
@ -189,10 +185,3 @@ func (c Container) hostConfig() *dockercontainer.HostConfig {
|
|||
|
||||
return hostConfig
|
||||
}
|
||||
|
||||
// ContainsWatchtowerLabel takes a map of labels and values and tells
|
||||
// the consumer whether it contains a valid watchtower instance label
|
||||
func ContainsWatchtowerLabel(labels map[string]string) bool {
|
||||
val, ok := labels[watchtowerLabel]
|
||||
return ok && val == "true"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue