types

package
v1.14.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

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() []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 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 ImageID

type ImageID string

ImageID is a hash string for a container image.

func (ImageID) ShortID

func (id ImageID) ShortID() string

ShortID returns the 12-character short version of an image ID.

Returns:

  • string: Shortened ID without "sha256:" prefix.

type ImageInspector added in v1.14.0

type ImageInspector interface {
	ImageInspectWithRaw(
		ctx context.Context,
		image string,
	) (dockerImage.InspectResponse, []byte, error)
}

ImageInspector defines the interface for inspecting Docker images.

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 RegistryCredentials

type RegistryCredentials struct {
	Username string // Registry username.
	Password string // Registry token or password.
}

RegistryCredentials holds basic auth credentials.

type RemovedImageInfo added in v1.14.0

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 added in v1.14.0

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 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL