config

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AppName = "doco-cd" // Name of the application

Variables

View Source
var (
	DefaultDeploymentConfigFileNames    = []string{".doco-cd.yaml", ".doco-cd.yml"}
	CustomDeploymentConfigFileNames     = []string{".doco-cd.%s.yaml", ".doco-cd.%s.yml"}
	DeprecatedDeploymentConfigFileNames = []string{".compose-deploy.yaml", ".compose-deploy.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")
	ErrDeprecatedConfig                 = errors.New("configuration file name is deprecated, please use .doco-cd.y(a)ml instead")
	ErrInvalidFilePath                  = errors.New("invalid file path")
)
View Source
var (
	ErrInvalidLogLevel   = validator.TextErr{Err: errors.New("invalid log level, must be one of debug, info, warn, error")}
	ErrBothSecretsSet    = errors.New("both secrets are set, please use one or the other")
	ErrBothSecretsNotSet = errors.New("neither secrets are set, please use one or the other")
	ErrInvalidHttpUrl    = errors.New("invalid HTTP URL")
)
View Source
var (
	ErrInvalidPollConfig = errors.New("invalid poll configuration")
	ErrBothPollConfigSet = errors.New("both POLL_CONFIG and POLL_CONFIG_FILE are set, please use one or the other")
)

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	LogLevel            string                 `env:"LOG_LEVEL,notEmpty" envDefault:"info"`                          // LogLevel is the log level for the application
	HttpPort            uint16                 `env:"HTTP_PORT,notEmpty" envDefault:"80" validate:"min=1,max=65535"` // HttpPort is the port the HTTP server will listen on
	HttpProxyString     string                 `env:"HTTP_PROXY"`                                                    // HttpProxyString is the HTTP proxy URL as a string
	HttpProxy           transport.ProxyOptions // HttpProxy is the HTTP proxy configuration parsed from the HttpProxyString
	WebhookSecret       string                 `env:"WEBHOOK_SECRET"`                                    // WebhookSecret is the secret used to authenticate the webhook
	WebhookSecretFile   string                 `env:"WEBHOOK_SECRET_FILE,file"`                          // WebhookSecretFile is the file containing the WebhookSecret
	GitAccessToken      string                 `env:"GIT_ACCESS_TOKEN"`                                  // GitAccessToken is the access token used to authenticate with the Git server (e.g. GitHub) for private repositories
	GitAccessTokenFile  string                 `env:"GIT_ACCESS_TOKEN_FILE,file"`                        // GitAccessTokenFile is the file containing the GitAccessToken
	AuthType            string                 `env:"AUTH_TYPE,notEmpty" envDefault:"oauth2"`            // AuthType is the type of authentication to use when cloning repositories
	SkipTLSVerification bool                   `env:"SKIP_TLS_VERIFICATION,notEmpty" envDefault:"false"` // SkipTLSVerification skips the TLS verification when cloning repositories.
	DockerQuietDeploy   bool                   `env:"DOCKER_QUIET_DEPLOY,notEmpty" envDefault:"true"`    // DockerQuietDeploy suppresses the status output of dockerCli in deployments (e.g. pull, create, start)
	PollConfigYAML      string                 `env:"POLL_CONFIG"`                                       // PollConfigYAML is the unparsed string containing the PollConfig in YAML format
	PollConfigFile      string                 `env:"POLL_CONFIG_FILE,file"`                             // PollConfigFile is the file containing the PollConfig in YAML format
	PollConfig          []PollConfig           `yaml:"-"`                                                // PollConfig is the YAML configuration for polling Git repositories for changes
}

AppConfig is used to configure this application https://github.com/caarlos0/env?tab=readme-ov-file#env-tag-options

func GetAppConfig

func GetAppConfig() (*AppConfig, error)

GetAppConfig returns the configuration

func (*AppConfig) ParsePollConfig added in v0.22.0

func (cfg *AppConfig) ParsePollConfig() error

ParsePollConfig parses the PollConfig from either the PollConfigYAML string or the PollConfigFile.

type DeployConfig

type DeployConfig struct {
	Name             string   `yaml:"name"`                                                                                                         // Name is the name of the docker-compose deployment / stack
	RepositoryUrl    HttpUrl  `yaml:"repository_url" default:"" validate:"httpUrl"`                                                                 // RepositoryUrl is the http URL of the Git repository to deploy
	Reference        string   `yaml:"reference" default:"refs/heads/main"`                                                                          // 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" default:"."`                                                                                      // WorkingDirectory is the working directory for the deployment
	ComposeFiles     []string `yaml:"compose_files" default:"[\"compose.yaml\", \"compose.yml\", \"docker-compose.yml\", \"docker-compose.yaml\"]"` // ComposeFiles is the list of docker-compose files to use
	RemoveOrphans    bool     `yaml:"remove_orphans" default:"true"`                                                                                // RemoveOrphans removes containers for services not defined in the Compose file
	ForceRecreate    bool     `yaml:"force_recreate" default:"false"`                                                                               // ForceRecreate forces the recreation/redeployment of containers even if the configuration has not changed
	ForceImagePull   bool     `yaml:"force_image_pull" default:"false"`                                                                             // ForceImagePull always pulls the latest version of the image tags you've specified if a newer version is available
	Timeout          int      `yaml:"timeout" default:"180"`                                                                                        // Timeout is the time in seconds to wait for the deployment to finish in seconds before timing out
	BuildOpts        struct {
		ForceImagePull bool              `yaml:"force_image_pull" default:"false"` // ForceImagePull always attempt to pull a newer version of the image
		Quiet          bool              `yaml:"quiet" default:"false"`            // Quiet suppresses the build output
		Args           map[string]string `yaml:"args"`                             // BuildArgs is a map of build-time arguments to pass to the build process
		NoCache        bool              `yaml:"no_cache" default:"false"`         // NoCache disables the use of the cache when building images
	} `yaml:"build_opts"` // BuildOpts is the build options for the deployment
	Destroy     bool `yaml:"destroy" default:"false"` // Destroy removes the deployment and all its resources from the Docker host
	DestroyOpts struct {
		RemoveVolumes bool `yaml:"remove_volumes" default:"true"` // RemoveVolumes removes the volumes used by the deployment
		RemoveImages  bool `yaml:"remove_images" default:"true"`  // RemoveImages removes the images used by the deployment
		RemoveRepoDir bool `yaml:"remove_dir" default:"true"`     // RemoveRepoDir removes the repository directory after the deployment is destroyed
	} `yaml:"destroy_opts"` // DestroyOpts is the destroy options for the deployment
}

DeployConfig is the structure of the deployment configuration file

func DefaultDeployConfig

func DefaultDeployConfig(name string) *DeployConfig

DefaultDeployConfig creates a DeployConfig with default values

func GetDeployConfigFromYAML added in v0.22.0

func GetDeployConfigFromYAML(f string) ([]*DeployConfig, error)

func GetDeployConfigs added in v0.11.0

func GetDeployConfigs(repoDir, name, customTarget string) ([]*DeployConfig, error)

GetDeployConfigs returns either the deployment configuration from the repository or the default configuration

func (*DeployConfig) UnmarshalYAML

func (c *DeployConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

type HttpUrl added in v0.17.0

type HttpUrl string // HttpUrl is a type for strings that represent HTTP URLs

type PollConfig added in v0.22.0

type PollConfig struct {
	CloneUrl     HttpUrl `yaml:"url" validate:"httpUrl"`   // CloneUrl is the URL to clone the Git repository that is used to poll for changes
	Reference    string  `yaml:"reference" default:"main"` // Reference is the Git reference to the deployment, e.g., refs/heads/main, main, refs/tags/v1.0.0 or v1.0.0
	Interval     int     `yaml:"interval" default:"180"`   // Interval is the interval in seconds to poll for changes
	CustomTarget string  `yaml:"target" default:""`        // CustomTarget is the name of an optional custom deployment config file, e.g. ".doco-cd.custom-name.yaml"
	Private      bool    `yaml:"private" default:"false"`  // Private indicates if the repository is private, which requires authentication
}

func (*PollConfig) String added in v0.22.0

func (c *PollConfig) String() string

String returns a string representation of the PollConfig

func (*PollConfig) UnmarshalYAML added in v0.22.0

func (c *PollConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*PollConfig) Validate added in v0.22.0

func (c *PollConfig) Validate() error

Validate checks if the PollConfig is valid

type PollJob added in v0.22.0

type PollJob struct {
	Config  PollConfig // config is the PollConfig for this instance
	LastRun int64      // LastRun is the last time this instance ran
	NextRun int64      // NextRun is the next time this instance should run
}

Jump to

Keyboard shortcuts

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