Documentation
¶
Overview ¶
Package types defines core interfaces and structs for Watchtower. It provides abstractions for containers, notifications, session reporting, and registry interactions.
Key components:
- Container: Interface for container lifecycle and metadata operations.
- Notifier: Interface for notification services with templating and batching.
- Report: Interface for session results (scanned, updated, etc.).
- UpdateParams: Struct for configuring update behavior.
- Filter: Function type for container filtering.
- ContainerReport: Interface for individual container session status.
- RegistryCredentials: Struct for registry authentication.
Usage example:
var c types.Container
params := types.UpdateParams{Filter: someFilter, Cleanup: true}
notifier := someNotifierImpl{}
notifier.StartNotification(false)
log := logging.New(os.Stderr, logging.InfoLevel)
progress := session.NewReport(log, progressMap)
notifier.SendNotification(report)
The package integrates with container, notifications, session, and registry packages. Logging is provided by callers via github.com/rs/zerolog where implemented.
Index ¶
- Constants
- type Container
- type ContainerID
- type ContainerReport
- type ConvertibleNotifierdeprecated
- type DelayNotifierdeprecated
- type Filter
- type FilterableContainer
- type ImageID
- type Notifier
- type RegistryCredentials
- type RemovedImageInfo
- type Report
- type RunConfig
- type TokenResponse
- type UpdateParams
Constants ¶
const WatchtowerOldPrefix = "watchtower-old-"
WatchtowerOldPrefix is the prefix used when renaming Watchtower containers during self-update. It is the single source of truth for both rename generation and old-name detection to prevent cross-file protocol drift.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container interface {
ContainerInfo() *dockerContainer.InspectResponse // Container metadata.
ID() ContainerID // Container ID.
IsRunning() bool // Check if running.
Name() string // Container name.
ImageID() ImageID // Current image ID.
ImageName() string // Image name with tag.
Enabled() (bool, bool) // Enabled status and presence.
IsMonitorOnly(params UpdateParams) bool // Monitor-only check.
Scope() (string, bool) // Scope value and presence.
Links(useComposeDependsOn bool) []string // Dependency links.
GetLabel(key string) (string, bool) // Arbitrary label value lookup.
ToRestart() bool // Needs restart check.
IsWatchtower() bool // Watchtower instance check.
StopSignal() string // Custom stop signal.
StopTimeout() *int // Custom stop timeout in seconds.
HasImageInfo() bool // Image metadata presence.
ImageInfo() *dockerImage.InspectResponse // Image metadata.
GetLifecyclePreCheckCommand() string // Pre-check command.
GetLifecyclePostCheckCommand() string // Post-check command.
GetLifecyclePreUpdateCommand() string // Pre-update command.
GetLifecyclePostUpdateCommand() string // Post-update command.
GetLifecycleUID() (int, bool) // UID for lifecycle hooks, with presence.
GetLifecycleGID() (int, bool) // GID for lifecycle hooks, with presence.
VerifyConfiguration() error // Config validation.
SetStale(status bool) // Set stale status.
IsStale() bool // Stale status check.
IsNoPull(params UpdateParams) bool // No-pull check.
CooldownDelay(params UpdateParams) time.Duration // Effective cooldown delay.
SetLinkedToRestarting(status bool) // Set linked-to-restarting status.
IsLinkedToRestarting() bool // Linked-to-restarting check.
PreUpdateTimeout() int // Pre-update timeout.
PostUpdateTimeout() int // Post-update timeout.
IsRestarting() bool // Restarting status check.
IsCreated() bool // Created-state check.
GetCreateConfig() *dockerContainer.Config // Creation config.
GetCreateHostConfig() *dockerContainer.HostConfig // Host creation config.
GetContainerChain() (string, bool) // Container chain label value and presence.
HasExposedPorts() bool // Exposed ports presence check.
}
Container defines a docker container's interface in Watchtower.
type ContainerID ¶
type ContainerID string
ContainerID is a hash string for a container instance.
func (ContainerID) ShortID ¶
func (id ContainerID) ShortID() string
ShortID returns the 12-character short version of a container ID.
Returns:
- string: Shortened ID without "sha256:" prefix.
type ContainerReport ¶
type ContainerReport interface {
ID() ContainerID // Container ID.
Name() string // Container name.
CurrentImageID() ImageID // Original image ID.
LatestImageID() ImageID // Latest image ID.
ImageName() string // Image name with tag.
Error() string // Error message, if any.
State() string // Human-readable state.
IsMonitorOnly() bool // Monitor-only status.
NewContainerID() ContainerID // New container ID after update.
}
ContainerReport defines a container's session status.
type ConvertibleNotifier
deprecated
type ConvertibleNotifier interface {
// GetURL creates a shoutrrr URL from configuration.
//
// Parameters:
// - c: Cobra command with flags.
//
// Returns:
// - string: Generated URL.
// - error: Non-nil if URL creation fails, nil on success.
GetURL(c *cobra.Command) (string, error)
}
ConvertibleNotifier defines a notifier that generates a shoutrrr URL.
Deprecated: This interface is part of the legacy notification system. Use --notification-url with shoutrrr URLs instead.
TODO: Remove ConvertibleNotifier interface for the v2 release.
type DelayNotifier
deprecated
type DelayNotifier interface {
// GetDelay returns the delay duration for notifications.
//
// Returns:
// - time.Duration: Delay before sending.
GetDelay() time.Duration
}
DelayNotifier defines a notifier with a delay before sending.
Deprecated: This interface is part of the legacy notification system. Use --notifications-delay instead.
TODO: Remove DelayNotifier interface for the v2 release.
type Filter ¶
type Filter func(FilterableContainer) bool
Filter defines a function to filter containers.
Parameters:
- c: Container to evaluate.
Returns:
- bool: True if container passes filter, false otherwise.
type FilterableContainer ¶
type FilterableContainer interface {
Name() string // Container name.
IsWatchtower() bool // Check if Watchtower instance.
Enabled() (bool, bool) // Enabled status and presence.
Scope() (string, bool) // Scope value and presence.
ImageName() string // Image name with tag.
GetLabel(key string) (string, bool) // Arbitrary label value lookup.
}
FilterableContainer defines an interface for container filtering.
type Notifier ¶
type Notifier interface {
StartNotification(suppressSummary bool) // Begin queuing messages.
SendNotification(report Report) // Send queued messages with report.
// RegisterHook attaches this notifier as a zerolog.Hook on the given logger.
// Implementations update *log in place to the hooked logger so the composition
// root continues using the same pointer for subsequent application logging.
RegisterHook(log *zerolog.Logger)
GetNames() []string // Service names.
GetURLs() []string // Service URLs.
Close() // Stop and flush notifications.
// ShouldSendNotification checks if a notification should be sent for the given
// report based on the notifier's configuration.
ShouldSendNotification(report Report) bool
}
Notifier defines the common interface for notification services.
Log events are received via a zerolog hook registered with RegisterHook. The notifier does not expose queued entry state. Batching, filtering, and deduplication happen inside the implementation driven by the hook callback.
type RegistryCredentials ¶
type RegistryCredentials struct {
Username string `json:"username"` // Registry username.
Password string `json:"password"` // Registry token or password.
IdentityToken string `json:"identitytoken,omitempty"` // OAuth/identity token from a credential helper.
}
RegistryCredentials holds registry authentication material.
Username/Password cover classic Basic auth. IdentityToken covers cloud helpers (for example ECR) that store a short-lived token without a password.
type RemovedImageInfo ¶
type RemovedImageInfo struct {
// ImageID is the ID of the image that was cleaned up.
ImageID ImageID `json:"image_id"`
// ContainerID is the ID of the container that was using this image.
ContainerID ContainerID `json:"container_id"`
// ImageName is the name/tag of the image that was cleaned up.
ImageName string `json:"image_name"`
// ContainerName is the name of the container that was using this image before the update.
ContainerName string `json:"container_name"`
}
RemovedImageInfo represents information about an image that was cleaned up during update operations. It tracks the image ID, container ID, image name, and the container that was using the old image before cleanup.
type Report ¶
type Report interface {
Scanned() []ContainerReport // Scanned containers.
Updated() []ContainerReport // Updated containers.
Failed() []ContainerReport // Failed containers.
Skipped() []ContainerReport // Skipped containers.
Stale() []ContainerReport // Stale containers.
Fresh() []ContainerReport // Fresh containers.
Restarted() []ContainerReport // Restarted containers (linked dependencies).
All() []ContainerReport // All unique containers.
}
Report defines container session results.
type RunConfig ¶
type RunConfig struct {
// Command is the cobra.Command instance representing the executed command, providing access to parsed flags.
Command *cobra.Command
// Names is a slice of container names explicitly provided as positional arguments, used for filtering.
Names []string
// Filter is the types.Filter function determining which containers are processed during updates.
Filter Filter
// FilterDesc is a human-readable description of the applied filter, used in logging and notifications.
FilterDesc string
// RunOnce indicates whether to perform a single update and exit.
RunOnce bool
// UpdateOnStart enables an immediate update check on startup, then continues with periodic updates.
UpdateOnStart bool
// EnableCheckAPI enables the check API endpoint.
EnableCheckAPI bool
// EnableConfigAPI enables the config API endpoint.
EnableConfigAPI bool
// EnableContainersAPI enables the containers API endpoint.
EnableContainersAPI bool
// EnableEventsAPI enables the events API endpoint.
EnableEventsAPI bool
// EnableHealthAPI enables the HTTP API health probes.
EnableHealthAPI bool
// EnableHistoryAPI enables the history API endpoint.
EnableHistoryAPI bool
// EnableImagesAPI enables the images API endpoint.
EnableImagesAPI bool
// EnableMetricsAPI enables the metrics API endpoint.
EnableMetricsAPI bool
// EnableSwaggerAPI enables Swagger UI endpoint.
EnableSwaggerAPI bool
// EnableUpdateAPI enables the update API endpoint.
EnableUpdateAPI bool
// UnblockHTTPAPI allows periodic polling alongside the HTTP API.
UnblockHTTPAPI bool
// APIToken is the authentication token for HTTP API access.
APIToken string
// APIEventsToken is the authentication token for the events SSE endpoint.
APIEventsToken string
// APIHost is the host interface to bind the HTTP API to (default: empty string).
APIHost string
// APIPort is the port for the HTTP API server (defaults to "8080").
APIPort string
// APIRateLimit is the maximum authentication requests per minute per IP address (default: 60).
APIRateLimit int
// NoStartupMessage suppresses startup messages if true.
NoStartupMessage bool
// TLSCertPath is the path to the TLS certificate file.
TLSCertPath string
// TLSKeyPath is the path to the TLS key file.
TLSKeyPath string
// CORSAllowedOrigins is a list of allowed CORS origins for cross-origin requests.
CORSAllowedOrigins []string
// TrustedProxies is a list of trusted proxy IPs/CIDRs for reverse proxy support.
TrustedProxies []string
// ProxyHeader is the header to use for real client IP behind a reverse proxy.
ProxyHeader string
// APIHostChanged reports whether http-api-host was explicitly configured.
APIHostChanged bool
// APIPortChanged reports whether http-api-port was explicitly configured.
APIPortChanged bool
// APIRateLimitChanged reports whether http-api-rate-limit was explicitly configured.
APIRateLimitChanged bool
// CheckAPITimeout is the maximum duration for the /v1/check API endpoint.
CheckAPITimeout time.Duration
// CheckAPITimeoutChanged reports whether http-api-check-timeout was explicitly configured.
CheckAPITimeoutChanged bool
// UpdateAPITimeout is the maximum duration for the /v1/update API endpoint.
UpdateAPITimeout time.Duration
// UpdateAPITimeoutChanged reports whether http-api-update-timeout was explicitly configured.
UpdateAPITimeoutChanged bool
}
RunConfig encapsulates the configuration parameters for the runMain function.
type TokenResponse ¶
type TokenResponse struct {
Token string `json:"token"` // Authentication token.
AccessToken string `json:"access_token"` // Alternative authentication token.
ExpiresIn int `json:"expires_in"` // Token lifetime in seconds.
IssuedAt string `json:"issued_at"` // Token issuance time in RFC3339 format.
}
TokenResponse holds a registry authentication token response.
type UpdateParams ¶
type UpdateParams struct {
Filter Filter `json:"-"` // Container filter.
Cleanup bool `json:"cleanup"` // Remove old images if true.
NoRestart bool `json:"no_restart"` // Skip restarts if true.
ReviveStopped bool `json:"revive_stopped"` // Start stopped containers after update if true.
Timeout time.Duration `json:"timeout"` // Update timeout.
MonitorOnly bool `json:"monitor_only"` // Monitor without updating if true.
NoPull bool `json:"no_pull"` // Skip image pulls if true.
LifecycleHooks bool `json:"lifecycle_hooks"` // Enable lifecycle hooks if true.
RollingRestart bool `json:"rolling_restart"` // Use rolling restart if true.
LabelPrecedence bool `json:"label_precedence"` // Prioritize labels if true.
PullFailureDelay time.Duration `json:"pull_failure_delay"` // Delay after failed self-update pull.
LifecycleUID int `json:"lifecycle_uid"` // Default UID for lifecycle hooks.
LifecycleGID int `json:"lifecycle_gid"` // Default GID for lifecycle hooks.
CPUCopyMode string `json:"cpu_copy_mode"` // CPU copy mode for container recreation.
RunOnce bool `json:"run_once"` // Run once mode if true.
CurrentContainerID ContainerID `json:"current_container_id"` // ID of the current container being updated.
UseComposeDependsOn bool `json:"use_compose_depends_on"` // Enable Docker Compose depends_on label processing.
SkipSelfUpdate bool `json:"skip_self_update"` // Skip Watchtower self-update if true.
EphemeralSelfUpdate bool `json:"ephemeral_self_update"` // Use ephemeral container for self-update if true.
CooldownDelay time.Duration `json:"cooldown_delay"` // Minimum time since image creation before allowing updates.
LabelEnable bool `json:"label_enable"` // Require enable label for monitoring.
}
UpdateParams defines options for the Update function.