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()
report := session.NewReport(progress)
notifier.SendNotification(report)
The package integrates with container, notifications, session, and registry packages, using logrus for logging where implemented.
Index ¶
- type AppSpec
- type CommandValue
- type Container
- type ContainerID
- type ContainerReport
- type ConvertibleNotifier
- type DelayNotifier
- type DependsOnSpec
- type Filter
- type FilterableContainer
- type HealthcheckSpec
- type ImageID
- type ImageInspector
- type MappingOrList
- type NamedVolumeOptions
- type NetworkSpec
- type Notifier
- type PortValue
- type RegistryCredentials
- type RemovedImageInfo
- type Report
- type RunConfig
- type ServiceBindOptions
- type ServiceDependency
- type ServiceNetworkAttachment
- type ServiceNetworks
- type ServicePortConfig
- type ServiceSpec
- type ServiceTarget
- type ServiceTmpfsOptions
- type ServiceVolumeConfig
- type StringList
- type TokenResponse
- type UpdateParams
- type VolumeSpec
- type VolumeValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppSpec ¶
type AppSpec struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Services map[string]ServiceSpec `json:"services" yaml:"services"`
Networks map[string]NetworkSpec `json:"networks,omitempty" yaml:"networks,omitempty"`
Volumes map[string]VolumeSpec `json:"volumes,omitempty" yaml:"volumes,omitempty"`
}
AppSpec defines a Compose-like application document.
type CommandValue ¶
CommandValue stores either shell-form or exec-form commands.
func (CommandValue) IsZero ¶
func (c CommandValue) IsZero() bool
IsZero reports whether the command is unset.
func (CommandValue) MarshalJSON ¶
func (c CommandValue) MarshalJSON() ([]byte, error)
func (*CommandValue) UnmarshalJSON ¶
func (c *CommandValue) UnmarshalJSON(data []byte) error
func (*CommandValue) UnmarshalYAML ¶
func (c *CommandValue) UnmarshalYAML(node *yaml.Node) error
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() []string // Dependency links.
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.
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.
GetCreateConfig() *dockerContainer.Config // Creation config.
GetCreateHostConfig() *dockerContainer.HostConfig // Host creation config.
GetContainerChain() (string, bool) // Container chain label value and presence.
}
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 ¶
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.
type DelayNotifier ¶
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.
type DependsOnSpec ¶
type DependsOnSpec struct {
Names []string `json:"-" yaml:"-"`
Values map[string]ServiceDependency `json:"-" yaml:"-"`
}
DependsOnSpec stores either list or map dependency syntax.
func (DependsOnSpec) IsZero ¶
func (d DependsOnSpec) IsZero() bool
IsZero reports whether the dependency set is unset.
func (*DependsOnSpec) UnmarshalJSON ¶
func (d *DependsOnSpec) UnmarshalJSON(data []byte) error
func (*DependsOnSpec) UnmarshalYAML ¶
func (d *DependsOnSpec) UnmarshalYAML(node *yaml.Node) error
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.
}
FilterableContainer defines an interface for container filtering.
type HealthcheckSpec ¶
type HealthcheckSpec struct {
Test CommandValue `json:"test,omitempty" yaml:"test,omitempty"`
Interval string `json:"interval,omitempty" yaml:"interval,omitempty"`
Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"`
StartPeriod string `json:"start_period,omitempty" yaml:"start_period,omitempty"`
StartIntvl string `json:"start_interval,omitempty" yaml:"start_interval,omitempty"`
Retries uint `json:"retries,omitempty" yaml:"retries,omitempty"`
Disable bool `json:"disable,omitempty" yaml:"disable,omitempty"`
}
HealthcheckSpec defines a Compose-compatible healthcheck subset.
type ImageInspector ¶
type ImageInspector interface {
ImageInspectWithRaw(
ctx context.Context,
image string,
) (dockerImage.InspectResponse, []byte, error)
}
ImageInspector defines the interface for inspecting Docker images.
type MappingOrList ¶
type MappingOrList struct {
Mapping map[string]*string `json:"-" yaml:"-"`
List []string `json:"-" yaml:"-"`
}
MappingOrList stores either a key/value mapping or a list representation.
func (MappingOrList) IsZero ¶
func (m MappingOrList) IsZero() bool
IsZero reports whether the value is unset.
func (*MappingOrList) UnmarshalJSON ¶
func (m *MappingOrList) UnmarshalJSON(data []byte) error
func (*MappingOrList) UnmarshalYAML ¶
func (m *MappingOrList) UnmarshalYAML(node *yaml.Node) error
type NamedVolumeOptions ¶
type NamedVolumeOptions struct {
NoCopy bool `json:"nocopy,omitempty" yaml:"nocopy,omitempty"`
SubPath string `json:"subpath,omitempty" yaml:"subpath,omitempty"`
}
NamedVolumeOptions defines long-form named volume options.
type NetworkSpec ¶
type NetworkSpec struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Driver string `json:"driver,omitempty" yaml:"driver,omitempty"`
External bool `json:"external,omitempty" yaml:"external,omitempty"`
Internal bool `json:"internal,omitempty" yaml:"internal,omitempty"`
Attachable bool `json:"attachable,omitempty" yaml:"attachable,omitempty"`
Labels MappingOrList `json:"labels,omitempty" yaml:"labels,omitempty"`
DriverOpts map[string]string `json:"driver_opts,omitempty" yaml:"driver_opts,omitempty"`
}
NetworkSpec defines a top-level network entry.
type Notifier ¶
type Notifier interface {
StartNotification(suppressSummary bool) // Begin queuing messages.
SendNotification(reportType Report) // Send queued messages with report.
AddLogHook() // Add as logrus hook.
GetNames() []string // Service names.
GetURLs() []string // Service URLs.
Close() // Stop and flush notifications.
// GetEntries returns all queued logrus entries that have been captured during the session.
// This is used for notification splitting by container in log mode, allowing notifiers
// to filter and send entries specific to individual containers rather than all entries together.
GetEntries() []*logrus.Entry
// SendFilteredEntries sends a subset of log entries with an optional report.
// This method enables fine-grained notifications where only entries relevant to specific
// containers are sent, supporting the --notification-split-by-container feature in log mode.
// The report parameter may be nil when sending filtered log entries without session context.
SendFilteredEntries(
entries []*logrus.Entry,
report Report,
)
// 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.
type PortValue ¶
type PortValue struct {
Short string `json:"-" yaml:"-"`
Config *ServicePortConfig `json:"-" yaml:"-"`
}
PortValue stores either short-form or long-form port syntax.
func (*PortValue) UnmarshalJSON ¶
type RegistryCredentials ¶
type RegistryCredentials struct {
Username string // Registry username.
Password string // Registry token or password.
}
RegistryCredentials holds basic auth credentials.
type RemovedImageInfo ¶
type RemovedImageInfo struct {
// ImageID is the ID of the image that was cleaned up.
ImageID ImageID
// ContainerID is the ID of the container that was using this image.
ContainerID ContainerID
// ImageName is the name/tag of the image that was cleaned up.
ImageName string
// ContainerName is the name of the container that was using this image before the update.
ContainerName string
}
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, set via the --run-once flag.
RunOnce bool
// UpdateOnStart enables an immediate update check on startup, then continues with periodic updates, set via the --update-on-start flag.
UpdateOnStart bool
// EnableUpdateAPI enables the HTTP update API endpoint, set via the --http-api-update flag.
EnableUpdateAPI bool
// EnableMetricsAPI enables the HTTP metrics API endpoint, set via the --http-api-metrics flag.
EnableMetricsAPI bool
// UnblockHTTPAPI allows periodic polling alongside the HTTP API, set via the --http-api-periodic-polls flag.
UnblockHTTPAPI bool
// APIToken is the authentication token for HTTP API access, set via the --http-api-token flag.
APIToken string
// APIHost is the host to bind the HTTP API to, set via the --http-api-host flag (defaults to empty string).
APIHost string
// APIPort is the port for the HTTP API server, set via the --http-api-port flag (defaults to "8080").
APIPort string
// NoStartupMessage suppresses startup messages if true, set via the --no-startup-message flag.
NoStartupMessage bool
}
RunConfig encapsulates the configuration parameters for the runMain function.
It aggregates command-line flags and derived settings into a single structure, providing a cohesive way to pass configuration data through the CLI execution flow, ensuring all necessary parameters are accessible for update operations, API setup, and scheduling.
type ServiceBindOptions ¶
type ServiceBindOptions struct {
CreateHostPath bool `json:"create_host_path,omitempty" yaml:"create_host_path,omitempty"`
Propagation string `json:"propagation,omitempty" yaml:"propagation,omitempty"`
Selinux string `json:"selinux,omitempty" yaml:"selinux,omitempty"`
}
ServiceBindOptions defines long-form bind mount options.
type ServiceDependency ¶
type ServiceDependency struct {
Condition string `json:"condition,omitempty" yaml:"condition,omitempty"`
Restart bool `json:"restart,omitempty" yaml:"restart,omitempty"`
Required *bool `json:"required,omitempty" yaml:"required,omitempty"`
}
ServiceDependency defines long-form depends_on options.
type ServiceNetworkAttachment ¶
type ServiceNetworkAttachment struct {
Aliases []string `json:"aliases,omitempty" yaml:"aliases,omitempty"`
IPv4Address string `json:"ipv4_address,omitempty" yaml:"ipv4_address,omitempty"`
IPv6Address string `json:"ipv6_address,omitempty" yaml:"ipv6_address,omitempty"`
LinkLocalIPs []string `json:"link_local_ips,omitempty" yaml:"link_local_ips,omitempty"`
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
}
ServiceNetworkAttachment defines per-service network attachment options.
type ServiceNetworks ¶
type ServiceNetworks struct {
Names []string `json:"-" yaml:"-"`
Values map[string]ServiceNetworkAttachment `json:"-" yaml:"-"`
}
ServiceNetworks stores either list or map network attachment syntax.
func (ServiceNetworks) IsZero ¶
func (s ServiceNetworks) IsZero() bool
IsZero reports whether the network attachment set is unset.
func (*ServiceNetworks) UnmarshalJSON ¶
func (s *ServiceNetworks) UnmarshalJSON(data []byte) error
func (*ServiceNetworks) UnmarshalYAML ¶
func (s *ServiceNetworks) UnmarshalYAML(node *yaml.Node) error
type ServicePortConfig ¶
type ServicePortConfig struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Mode string `json:"mode,omitempty" yaml:"mode,omitempty"`
HostIP string `json:"host_ip,omitempty" yaml:"host_ip,omitempty"`
Target uint32 `json:"target,omitempty" yaml:"target,omitempty"`
Published string `json:"published,omitempty" yaml:"published,omitempty"`
Protocol string `json:"protocol,omitempty" yaml:"protocol,omitempty"`
AppProtocol string `json:"app_protocol,omitempty" yaml:"app_protocol,omitempty"`
}
ServicePortConfig defines long-form Compose port syntax.
type ServiceSpec ¶
type ServiceSpec struct {
ContainerName string `json:"container_name,omitempty" yaml:"container_name,omitempty"`
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Command CommandValue `json:"command,omitempty" yaml:"command,omitempty"`
Entrypoint CommandValue `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
Environment MappingOrList `json:"environment,omitempty" yaml:"environment,omitempty"`
EnvFile StringList `json:"env_file,omitempty" yaml:"env_file,omitempty"`
Volumes []VolumeValue `json:"volumes,omitempty" yaml:"volumes,omitempty"`
Ports []PortValue `json:"ports,omitempty" yaml:"ports,omitempty"`
Restart string `json:"restart,omitempty" yaml:"restart,omitempty"`
NetworkMode string `json:"network_mode,omitempty" yaml:"network_mode,omitempty"`
Networks ServiceNetworks `json:"networks,omitempty" yaml:"networks,omitempty"`
DependsOn DependsOnSpec `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`
Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"`
TTY bool `json:"tty,omitempty" yaml:"tty,omitempty"`
StdinOpen bool `json:"stdin_open,omitempty" yaml:"stdin_open,omitempty"`
WorkingDir string `json:"working_dir,omitempty" yaml:"working_dir,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Devices StringList `json:"devices,omitempty" yaml:"devices,omitempty"`
CapAdd StringList `json:"cap_add,omitempty" yaml:"cap_add,omitempty"`
CapDrop StringList `json:"cap_drop,omitempty" yaml:"cap_drop,omitempty"`
DNS StringList `json:"dns,omitempty" yaml:"dns,omitempty"`
ExtraHosts StringList `json:"extra_hosts,omitempty" yaml:"extra_hosts,omitempty"`
Labels MappingOrList `json:"labels,omitempty" yaml:"labels,omitempty"`
Healthcheck *HealthcheckSpec `json:"healthcheck,omitempty" yaml:"healthcheck,omitempty"`
Extensions map[string]interface{} `json:"-" yaml:",inline"`
}
ServiceSpec defines a Compose-like service document for the Tier 1 fields.
type ServiceTarget ¶
type ServiceTarget struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Service string `json:"service,omitempty" yaml:"service,omitempty"`
}
ServiceTarget identifies an app or a specific service within an app.
type ServiceTmpfsOptions ¶
type ServiceTmpfsOptions struct {
Mode uint32 `json:"mode,omitempty" yaml:"mode,omitempty"`
Size int64 `json:"size,omitempty" yaml:"size,omitempty"`
}
ServiceTmpfsOptions defines long-form tmpfs options.
type ServiceVolumeConfig ¶
type ServiceVolumeConfig struct {
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
ReadOnly bool `json:"read_only,omitempty" yaml:"read_only,omitempty"`
Bind *ServiceBindOptions `json:"bind,omitempty" yaml:"bind,omitempty"`
Volume *NamedVolumeOptions `json:"volume,omitempty" yaml:"volume,omitempty"`
Tmpfs *ServiceTmpfsOptions `json:"tmpfs,omitempty" yaml:"tmpfs,omitempty"`
}
ServiceVolumeConfig defines long-form Compose volume syntax.
type StringList ¶
type StringList struct {
Values []string `json:"-" yaml:"-"`
}
StringList stores either a single string or a list of strings.
func (StringList) IsZero ¶
func (s StringList) IsZero() bool
IsZero reports whether the list is unset.
func (*StringList) UnmarshalJSON ¶
func (s *StringList) UnmarshalJSON(data []byte) error
func (*StringList) UnmarshalYAML ¶
func (s *StringList) UnmarshalYAML(node *yaml.Node) error
type TokenResponse ¶
type TokenResponse struct {
Token string `json:"token"` // Authentication token.
}
TokenResponse holds a registry authentication token.
type UpdateParams ¶
type UpdateParams struct {
Filter Filter // Container filter.
Cleanup bool // Remove old images if true.
NoRestart bool // Skip restarts if true.
Timeout time.Duration // Update timeout.
MonitorOnly bool // Monitor without updating if true.
NoPull bool // Skip image pulls if true.
LifecycleHooks bool // Enable lifecycle hooks if true.
RollingRestart bool // Use rolling restart if true.
LabelPrecedence bool // Prioritize labels if true.
PullFailureDelay time.Duration // Delay after failed self-update pull.
LifecycleUID int // Default UID for lifecycle hooks.
LifecycleGID int // Default GID for lifecycle hooks.
CPUCopyMode string // CPU copy mode for container recreation.
RunOnce bool // Run once mode if true.
SkipSelfUpdate bool // Skip Watchtower self-update if true.
CurrentContainerID ContainerID // ID of the current container being updated.
}
UpdateParams defines options for the Update function.
type VolumeSpec ¶
type VolumeSpec struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Driver string `json:"driver,omitempty" yaml:"driver,omitempty"`
External bool `json:"external,omitempty" yaml:"external,omitempty"`
DriverOpts map[string]string `json:"driver_opts,omitempty" yaml:"driver_opts,omitempty"`
Labels MappingOrList `json:"labels,omitempty" yaml:"labels,omitempty"`
}
VolumeSpec defines a top-level volume entry.
type VolumeValue ¶
type VolumeValue struct {
Short string `json:"-" yaml:"-"`
Config *ServiceVolumeConfig `json:"-" yaml:"-"`
}
VolumeValue stores either short-form or long-form volume syntax.
func (*VolumeValue) UnmarshalJSON ¶
func (v *VolumeValue) UnmarshalJSON(data []byte) error
func (*VolumeValue) UnmarshalYAML ¶
func (v *VolumeValue) UnmarshalYAML(node *yaml.Node) error