deploy

package
v0.88.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultReference = "refs/heads/main"

Variables

View Source
var (
	DefaultDeploymentConfigFileNames = []string{".doco-cd.yaml", ".doco-cd.yml"}
	CustomDeploymentConfigFileNames  = []string{".doco-cd.%s.yaml", ".doco-cd.%s.yml"}
	ErrConfigFileNotFound            = errors.New("configuration file not found in repository")
	ErrDuplicateProjectName          = errors.New("duplicate project/stack name found in configuration file")
	ErrInvalidConfig                 = errors.New("invalid deploy configuration")
	ErrKeyNotFound                   = errors.New("key not found")
	ErrInvalidFilePath               = errors.New("invalid file path")
	ErrMultipleYAMLDocuments         = errors.New("nested .doco-cd configuration file must contain only a single YAML document")
)

Functions

func LoadLocalDotEnv

func LoadLocalDotEnv(config *Config, basePath string) error

LoadLocalDotEnv processes local dotenv files and loads their variables into the Config.Internal Environment map. Remote dotenv files (prefixed with "remote:") are collected and left in Config.EnvFiles for later processing.

func ValidateUniqueProjectNames

func ValidateUniqueProjectNames(configs []*Config) error

ValidateUniqueProjectNames checks if the project names in the configs are unique.

Types

type AutoDiscoveryConfig

type AutoDiscoveryConfig struct {
	Enabled   bool `yaml:"enabled" json:"enabled" default:"false"` // Enabled enables autodiscovery of services to deploy in the working directory
	ScanDepth int  `yaml:"depth" json:"depth" default:"0"`         // ScanDepth is the maximum depth of subdirectories to scan for docker-compose files
	Delete    bool `yaml:"delete" json:"delete" default:"true"`    // Delete removes obsolete auto-discovered deployments that are no longer present in the repository
}

AutoDiscoveryConfig holds auto-discovery settings for a deployment.

func (*AutoDiscoveryConfig) UnmarshalJSON

func (c *AutoDiscoveryConfig) UnmarshalJSON(data []byte) error

func (*AutoDiscoveryConfig) UnmarshalYAML

func (c *AutoDiscoveryConfig) UnmarshalYAML(node *yaml.Node) error

type BuildConfig

type BuildConfig struct {
	ForceImagePull bool              `yaml:"force_image_pull" json:"force_image_pull" default:"false"` // ForceImagePull always attempt to pull a newer version of the image
	Quiet          bool              `yaml:"quiet" json:"quiet" default:"false"`                       // Quiet suppresses the build output
	Args           map[string]string `yaml:"args" json:"args"`                                         // BuildArgs is a map of build-time arguments to pass to the build process
	NoCache        bool              `yaml:"no_cache" json:"no_cache" default:"false"`                 // NoCache disables the use of the cache when building images
}

BuildConfig holds build options for a deployment.

type Config

type Config struct {
	Name               string         `yaml:"name" json:"name" doco:"allowOverride"`                                // Name of the docker-compose deployment / stack
	RepositoryUrl      config.HttpUrl `yaml:"repository_url" json:"repository_url" default:"" validate:"httpUrl"`   // RepositoryUrl is the http URL of the Git repository to deploy
	WebhookEventFilter string         `yaml:"webhook_filter" json:"webhook_filter" default:"" doco:"allowOverride"` // WebhookEventFilter is a regular expression to whitelist deployment triggers based on the webhook event payload (e.g., branch like "^refs/heads/main$" or "main", tag like "^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$" or "v[0-9]+\.[0-9]+\.[0-9]+")
	Reference          string         `yaml:"reference" json:"reference" default:""`                                // Reference is the Git reference to the deployment, e.g., refs/heads/main, main, refs/tags/v1.0.0 or v1.0.0
	WorkingDirectory   string         `yaml:"working_dir" json:"working_dir" default:"." doco:"allowOverride"`      // WorkingDirectory is the working directory for the deployment
	ComposeFiles       []string       ``                                                                            // ComposeFiles is the list of docker-compose files to use
	/* 157-byte string literal not displayed */
	Environment     map[string]string                        `yaml:"environment" json:"environment" doco:"allowOverride"`                           // Environment is a map of environment variables to use for variable interpolation in the compose files
	EnvFiles        []string                                 `yaml:"env_files" json:"env_files" default:"[\".env\"]" doco:"allowOverride"`          // EnvFiles is the list of dotenv files to use for variable interpolation
	RemoveOrphans   bool                                     `yaml:"remove_orphans" json:"remove_orphans" default:"true" doco:"allowOverride"`      // RemoveOrphans removes containers for services not defined in the Compose file
	PruneImages     bool                                     `yaml:"prune_images" json:"prune_images" default:"true" doco:"allowOverride"`          // PruneImages removes images that are no longer used by any service
	ForceRecreate   bool                                     `yaml:"force_recreate" json:"force_recreate" default:"false" doco:"allowOverride"`     // ForceRecreate forces the recreation/redeployment of containers even if the configuration has not changed
	ForceImagePull  bool                                     `yaml:"force_image_pull" json:"force_image_pull" default:"false" doco:"allowOverride"` // ForceImagePull always pulls the latest version of the image tags you've specified if a newer version is available
	Timeout         int                                      `yaml:"timeout" json:"timeout" default:"180" doco:"allowOverride"`                     // Timeout is the time in seconds to wait for the deployment to finish before timing out
	BuildOpts       BuildConfig                              `yaml:"build" json:"build" doco:"allowOverride"`                                       // BuildOpts is the build options for the deployment
	GitDepth        int                                      `yaml:"git_depth" json:"git_depth" default:"0"`                                        // GitDepth limits the number of commits to fetch. 0 means use global GIT_CLONE_DEPTH. A positive value overrides the global setting.
	Destroy         DestroyConfig                            `yaml:"destroy" json:"destroy" doco:"allowOverride"`                                   // Destroy configures destruction of the deployment and related resources
	Profiles        []string                                 `yaml:"profiles" json:"profiles" default:"[]" doco:"allowOverride"`                    // Profiles is a list of profiles to use for the deployment, e.g., ["dev", "prod"]. See https://docs.docker.com/compose/how-tos/profiles/
	ExternalSecrets map[string]secrettypes.ExternalSecretRef `yaml:"external_secrets" json:"external_secrets" doco:"allowOverride"`                 // ExternalSecrets maps env vars to legacy string references or structured references (e.g. webhook store_ref/remote_ref).
	AutoDiscovery   AutoDiscoveryConfig                      `yaml:"auto_discovery" json:"auto_discovery"`                                          // AutoDiscovery configures autodiscovery of services to deploy in the working directory
	Reconciliation  ReconciliationConfig                     `yaml:"reconciliation" json:"reconciliation" doco:"allowOverride"`                     // Reconciliation is the configuration for the reconciliation feature
	Internal        struct {
		File        string            `yaml:"-"` // File is the path to the deployment configuration file
		Environment map[string]string // Environment stores environment variables for variable interpolation in the compose project
		Hash        string            `yaml:"-"` // Hash is a hash of the Config struct
	} // Internal holds internal configuration values that are not set by the user
}

Config is the structure of the deployment configuration file.

func GetConfigFromYAML

func GetConfigFromYAML(f string, applyDefaults bool) ([]*Config, error)

GetConfigFromYAML reads a YAML file and unmarshals it into a slice of Config structs. When applyDefaults is true, default values are applied to each config (normal usage). When applyDefaults is false, omitted fields remain zero/nil — used for nested auto-discovery overrides so unset fields do not accidentally replace base/discovered values during merge.

func GetConfigs

func GetConfigs(repoRoot, configBaseDir, name, customTarget, reference string, gitOpts *GitOptions) ([]*Config, error)

GetConfigs returns either the deployment configuration from the repository or the default configuration. gitOpts is optional (may be nil) and is only required when AutoDiscovery with a remote RepositoryUrl is used.

func New

func New(name, reference string) *Config

New creates a Config with default values.

func ResolveConfigs

func ResolveConfigs(inlineDeployments []*Config, customTarget, reference, repoRoot, configBaseDir, name string, gitOpts *GitOptions) ([]*Config, error)

ResolveConfigs returns Deployment Config's for a poll run, preferring inline deployments defined on the PollConfig when provided. Falls back to repository configuration files or default values when no inline deployments are present. repoRoot is the absolute path to the repository root. configBaseDir is the relative path from repo root where config files are located. gitOpts is optional (may be nil) and is only required when AutoDiscovery with a remote RepositoryUrl is used.

func (*Config) Hash

func (c *Config) Hash() (string, error)

Hash returns a hash of the Config struct (without changing the order of its elements).

func (*Config) LogValue

func (c *Config) LogValue() slog.Value

LogValue implements the slog.LogValuer interface for Config.

func (*Config) ResolveGitDepth

func (c *Config) ResolveGitDepth(globalDepth int) int

ResolveGitDepth returns the effective git clone depth. If the deploy-level GitDepth is > 0, it overrides the global value. Otherwise, the global depth is used. 0 means full clone (no limit).

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(data []byte) error

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(any) error) error

func (*Config) Validate

func (c *Config) Validate() error

type DestroyConfig

type DestroyConfig struct {
	Enabled       bool `yaml:"enabled" json:"enabled" default:"false"`              // Enabled removes the deployment and all its resources from the Docker host
	RemoveVolumes bool `yaml:"remove_volumes" json:"remove_volumes" default:"true"` // RemoveVolumes removes the volumes used by the deployment (always enabled in docker swarm mode)
	RemoveImages  bool `yaml:"remove_images" json:"remove_images" default:"true"`   // RemoveImages removes the images used by the deployment (currently not supported in docker swarm mode)
	RemoveRepoDir bool `yaml:"remove_dir" json:"remove_dir" default:"true"`         // RemoveRepoDir removes the repository directory after the deployment is destroyed
}

DestroyConfig holds options for destroying a deployment.

func (*DestroyConfig) UnmarshalJSON

func (c *DestroyConfig) UnmarshalJSON(data []byte) error

func (*DestroyConfig) UnmarshalYAML

func (c *DestroyConfig) UnmarshalYAML(node *yaml.Node) error

type GitOptions

type GitOptions struct {
	SSHPrivateKey           string
	SSHPrivateKeyPassphrase string
	GitAccessToken          string
	SkipTLSVerification     bool
	HttpProxy               transport.ProxyOptions
	GitCloneSubmodules      bool
	GitCloneDepth           int
}

GitOptions holds git-related options for operations that require cloning or fetching remote repositories.

type ReconciliationConfig

type ReconciliationConfig struct {
	Enabled        bool     `yaml:"enabled" json:"enabled" default:"true"`               // Enabled enables the reconciliation feature
	Events         []string `yaml:"events" json:"events" default:"[\"unhealthy\"]"`      // Events is the list of Docker container actions that trigger reconciliation
	RestartTimeout int      `yaml:"restart_timeout" json:"restart_timeout" default:"10"` // RestartTimeout is the timeout in seconds to wait before killing a container during a restart
	RestartSignal  string   `yaml:"restart_signal" json:"restart_signal" default:""`     // RestartSignal is the signal sent to stop containers during a restart. If not set, the default of the Docker daemon is used (SIGTERM).
	RestartLimit   int      `yaml:"restart_limit" json:"restart_limit" default:"5"`      // RestartLimit suppresses further unhealthy-triggered restarts after this many restarts in the configured window. Set to 0 to disable suppression.
	RestartWindow  int      `yaml:"restart_window" json:"restart_window" default:"300"`  // RestartWindow is the time window in seconds used with RestartLimit.
}

ReconciliationConfig holds settings for the reconciliation feature.

func (*ReconciliationConfig) UnmarshalJSON

func (c *ReconciliationConfig) UnmarshalJSON(data []byte) error

func (*ReconciliationConfig) UnmarshalYAML

func (c *ReconciliationConfig) UnmarshalYAML(node *yaml.Node) error

Jump to

Keyboard shortcuts

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