Documentation
¶
Index ¶
- Constants
- Variables
- func CheckDefaultComposeFiles(composeFiles []string, workingDir string) ([]string, error)
- func CheckMountPointWriteable(mountPoint container.MountPoint) error
- func ComposeSignal(ctx context.Context, dockerCli command.Cli, project *types.Project, ...) error
- func ConnectToSocket() (net.Conn, error)
- func CreateDockerCli(quiet bool) (command.Cli, error)
- func DecryptProjectFiles(repoPath string, p *types.Project) ([]string, error)
- func DeployStack(jobLog *slog.Logger, externalRepoPath string, ctx *context.Context, ...) error
- func DeploySwarmStack(ctx context.Context, dockerCli command.Cli, cfg *composetypes.Config, ...) error
- func DestroyStack(jobLog *slog.Logger, ctx *context.Context, dockerCli *command.Cli, ...) error
- func Exec(apiClient client.APIClient, containerID string, cmd ...string) (out string, err error)
- func GetContainerID(apiClient client.APIClient, name string) (id string, err error)
- func GetLabeledConfigs(ctx context.Context, cli client.APIClient, key, value string) (configs []swarm.Config, err error)
- func GetLabeledContainers(ctx context.Context, cli client.APIClient, key, value string, all bool) (containers []container.Summary, err error)
- func GetLabeledSecrets(ctx context.Context, cli client.APIClient, key, value string) (secrets []swarm.Secret, err error)
- func GetLabeledServices(ctx context.Context, cli client.APIClient, key, value string) (map[Service]map[string]string, error)
- func GetLabeledVolumes(ctx context.Context, cli client.APIClient, key, value string) (volumes []volume.Volume, err error)
- func GetMountPointByDestination(cli client.APIClient, containerID, destination string) (container.MountPoint, error)
- func GetPathsFromGitChangedFiles(changedFiles []gitInternal.ChangedFile, basePath string) []string
- func GetProjectContainers(ctx context.Context, dockerCli command.Cli, projectName string) ([]api.ContainerSummary, error)
- func GetProjects(ctx context.Context, dockerCli command.Cli, showDisabled bool) ([]api.Stack, error)
- func GetServiceLabels(ctx context.Context, cli client.APIClient, stackName string) (map[Service]Labels, error)
- func HasChangedBindMounts(repoPathExternal string, paths []string, project *types.Project, ...) ([]string, []string)
- func HasChangedBuildFiles(repoPathExternal string, paths []string, project *types.Project, ...) ([]string, []string)
- func HasChangedConfigs(repoPathExternal string, paths []string, project *types.Project, ...) ([]string, []string)
- func HasChangedEnvFiles(repoPathExternal string, paths []string, project *types.Project, ...) ([]string, []string)
- func HasChangedSecrets(repoPathExternal string, paths []string, project *types.Project, ...) ([]string, []string)
- func HaveDeployedServiceImageDigestsChanged(ctx context.Context, dockerCli command.Cli, project *types.Project, ...) (bool, error)
- func LoadCompose(ctx context.Context, repoPath, workingDir, projectName string, ...) (*types.Project, error)
- func LoadSwarmStack(dockerCli command.Cli, project *types.Project, deployConfig *deploy.Config, ...) (*composetypes.Config, *options.Deploy, error)
- func NewHttpClient() *http.Client
- func NewJobScheduleParser() cron.Parser
- func ParseJobScheduleExpression(spec string) (cron.Schedule, error)
- func ProjectFilesHaveChanges(repoPathExternal string, changePaths []string, project *types.Project) ([]Change, IgnoredInfo, error)
- func ProjectHash(p *types.Project) (string, error)
- func PruneStackConfigs(ctx context.Context, client dockerClient.APIClient, namespace string) error
- func PruneStackSecrets(ctx context.Context, client dockerClient.APIClient, namespace string) error
- func PullImages(ctx context.Context, dockerCli command.Cli, projectName string) error
- func RemoveLabeledVolumes(ctx context.Context, dockerClient client.APIClient, stackName string) error
- func RemoveProject(ctx context.Context, dockerCli command.Cli, projectName string, ...) error
- func RemoveSwarmStack(ctx context.Context, dockerCli command.Cli, namespace string) error
- func RerunJobService(ctx context.Context, cli dockerClient.APIClient, serviceName string) error
- func RestartContainer(ctx context.Context, apiClient client.APIClient, containerID string) error
- func RestartProject(ctx context.Context, dockerCli command.Cli, projectName string, ...) error
- func RestartService(ctx context.Context, cli dockerClient.APIClient, serviceName string) error
- func RunContainerOneOffFromExisting(ctx context.Context, apiClient client.APIClient, containerID string) error
- func RunImagePruneJob(ctx context.Context, dockerCLI command.Cli) error
- func RunImageRemoveJob(ctx context.Context, dockerCLI command.Cli, images []string) error
- func RunSwarmJob(ctx context.Context, dockerCLI command.Cli, mode swarm.DeployMode, ...) error
- func RunSwarmOneOffFromService(ctx context.Context, dockerCLI command.Cli, serviceName string, ...) error
- func SetConfigHashPrefixes(stack *composetypes.Config, namespace string) error
- func SetSecretHashPrefixes(stack *composetypes.Config, namespace string) error
- func StartProject(ctx context.Context, dockerCli command.Cli, projectName string, ...) error
- func StopProject(ctx context.Context, dockerCli command.Cli, projectName string, ...) error
- func VerifyDockerAPIAccess() (error, error)
- func VerifyDockerHostConnection(dockerHost string) error
- func VerifySocketConnection() error
- func VerifySocketRead(httpClient *http.Client) error
- func WaitForSwarmService(ctx context.Context, t *testing.T, cli dockerClient.APIClient, ...) (swarmTypes.Service, error)
- type Change
- type IgnoredInfo
- type JobExecutionMode
- type JobNotifyOn
- type JobScheduleConfig
- type Labels
- type LatestServiceStatus
- type Service
- type ServiceMismatch
- type ServiceMismatchReason
- type ServiceStatus
- type SignalService
- type SwarmOneOffFromServiceOptions
Constants ¶
const ( DeprecatedAutoDiscoverLabel = "cd.doco.deployment.auto_discover" DeprecatedAutoDiscoverDeleteLabel = "cd.doco.deployment.auto_discover.delete" )
DeprecatedAutoDiscoverLabel and DeprecatedAutoDiscoverDeleteLabel are the old label names kept for backwards-compatible reads. New deployments only write the new labels.
Deprecated: Use DocoCDLabels.Deployment.AutoDiscovery and DocoCDLabels.Deployment.AutoDiscoveryDelete instead.
TODO: Remove in a future release.
const ( ServiceMismatchReasonNotDeployed = "service not deployed" ServiceMismatchReasonUnnecessary = "service is unnecessary" ServiceMismatchReasonSwarmMode = "swarm mode mismatch" ServiceMismatchReasonReplicas = "replicas mismatch" )
const (
SocketPath = "/var/run/docker.sock"
)
Variables ¶
var ( ErrNoContainerToStart = errors.New("no container to start") ErrIsInUse = errors.New("is in use") ComposeVersion string // Version of the docker compose module, will be set at runtime )
var ( ErrNotAJobService = errors.New("service is not a job-mode service") ErrJobServiceRestartNotSupported = errors.New("restart not supported for job services") )
var ( ErrMountPointNotFound = errors.New("mount point not found") ErrMountPointNotWriteable = errors.New("mount point is not writeable") ErrContainerIDNotFound = errors.New("container ID not found") )
var ( ErrDockerSocketConnectionFailed = errors.New("failed to connect to docker socket") ErrDockerHostConnectionFailed = errors.New("failed to connect to docker host") )
var DocoCDJobLabels = docoCDJobLabelNames
DocoCDJobLabels exposes the scheduler/job labels for consumers outside this package.
var DocoCDLabels = docoCdLabelNames{
Metadata: docoCDLabelNamesMetadata{
Manager: "cd.doco.metadata.manager",
Version: "cd.doco.metadata.version",
},
Deployment: docoCdLabelNamesDeployment{
Name: "cd.doco.deployment.name",
Timestamp: "cd.doco.deployment.timestamp",
ComposeHash: "cd.doco.deployment.compose.sha",
WorkingDir: "cd.doco.deployment.working_dir",
TargetRef: "cd.doco.deployment.target.ref",
CommitSHA: "cd.doco.deployment.target.sha",
Trigger: "cd.doco.deployment.trigger",
ConfigHash: "cd.doco.deployment.config.sha",
AutoDiscovery: "cd.doco.deployment.auto_discovery",
AutoDiscoveryDelete: "cd.doco.deployment.auto_discovery.delete",
RecreateIgnore: "cd.doco.deployment.recreate.ignore",
RecreateIgnoreSignal: "cd.doco.deployment.recreate.ignore.signal",
},
Repository: docoCdLabelNamesRepository{
Name: "cd.doco.repository.name",
URL: "cd.doco.repository.url",
},
}
DocoCDLabels contains the label key names used by DocoCD to identify deployed containers and their metadata.
var ErrIgnoreCfgInvalid = errors.New("ignore config is invalid")
var ErrNoSuchImage = errors.New("no such image") // Image does not exist
Functions ¶
func CheckDefaultComposeFiles ¶ added in v0.73.0
CheckDefaultComposeFiles checks if the default compose files are used and returns them if true.
func CheckMountPointWriteable ¶ added in v0.13.0
func CheckMountPointWriteable(mountPoint container.MountPoint) error
CheckMountPointWriteable checks if a mount point is writable by attempting to create a file in it.
func ComposeSignal ¶ added in v0.77.0
func ComposeSignal(ctx context.Context, dockerCli command.Cli, project *types.Project, signal []SignalService) error
ComposeSignal will send signal to service.
func ConnectToSocket ¶
ConnectToSocket connects to the docker socket.
func DecryptProjectFiles ¶ added in v0.74.0
DecryptProjectFiles decrypts all files used in the compose project that are encrypted using doco-cd's encryption mechanism. This includes configs, secrets, bind mounts, env files and build contexts. Since absolute file paths in types.Project are paths on the docker host, repoPath also needs to be the external path to the repository. We use the symlink inside the container to follow the external path to the correct internal path.
func DeployStack ¶ added in v0.14.0
func DeployStack( jobLog *slog.Logger, externalRepoPath string, ctx *context.Context, dockerCli command.Cli, payload *webhook.ParsedPayload, deployConfig *deploy.Config, detectedChanges []Change, needSignal []SignalService, latestCommit, appVersion string, ) error
DeployStack deploys the stack using the provided deployment configuration.
func DeploySwarmStack ¶ added in v0.31.0
func DeploySwarmStack(ctx context.Context, dockerCli command.Cli, cfg *composetypes.Config, opts *options.Deploy) error
DeploySwarmStack deploys a Docker Swarm stack using the provided project and deploy configuration.
func DestroyStack ¶ added in v0.14.0
func DestroyStack( jobLog *slog.Logger, ctx *context.Context, dockerCli *command.Cli, deployConfig *deploy.Config, ) error
DestroyStack destroys the stack using the provided deployment configuration.
func GetContainerID ¶ added in v0.13.0
GetContainerID retrieves the container ID for a given service name.
func GetLabeledConfigs ¶ added in v0.31.0
func GetLabeledConfigs(ctx context.Context, cli client.APIClient, key, value string) (configs []swarm.Config, err error)
GetLabeledConfigs retrieves all configs with a specific label key and value.
func GetLabeledContainers ¶ added in v0.13.0
func GetLabeledContainers(ctx context.Context, cli client.APIClient, key, value string, all bool) (containers []container.Summary, err error)
GetLabeledContainers retrieves all containers with a specific label key and value.
func GetLabeledSecrets ¶ added in v0.31.0
func GetLabeledSecrets(ctx context.Context, cli client.APIClient, key, value string) (secrets []swarm.Secret, err error)
GetLabeledSecrets retrieves all secrets with a specific label key and value.
func GetLabeledServices ¶ added in v0.54.0
func GetLabeledServices(ctx context.Context, cli client.APIClient, key, value string) (map[Service]map[string]string, error)
GetLabeledServices retrieves all services with a specific label key and value, along with their labels.
func GetLabeledVolumes ¶ added in v0.31.0
func GetLabeledVolumes(ctx context.Context, cli client.APIClient, key, value string) (volumes []volume.Volume, err error)
GetLabeledVolumes retrieves all volumes with a specific label key and value.
func GetMountPointByDestination ¶ added in v0.13.0
func GetMountPointByDestination(cli client.APIClient, containerID, destination string) (container.MountPoint, error)
GetMountPointByDestination retrieves the mount point of a container volume/bind mount by its destination (mount point inside the container).
func GetPathsFromGitChangedFiles ¶ added in v0.77.0
func GetPathsFromGitChangedFiles(changedFiles []gitInternal.ChangedFile, basePath string) []string
func GetProjectContainers ¶ added in v0.55.0
func GetProjectContainers(ctx context.Context, dockerCli command.Cli, projectName string) ([]api.ContainerSummary, error)
GetProjectContainers returns the status of all services in the specified project.
func GetProjects ¶ added in v0.33.0
func GetProjects(ctx context.Context, dockerCli command.Cli, showDisabled bool) ([]api.Stack, error)
GetProjects returns a list of all projects.
func GetServiceLabels ¶ added in v0.54.0
func GetServiceLabels(ctx context.Context, cli client.APIClient, stackName string) (map[Service]Labels, error)
GetServiceLabels retrieves the Labels for each Service in a given stack.
func HasChangedBindMounts ¶ added in v0.29.0
func HasChangedBindMounts(repoPathExternal string, paths []string, project *types.Project, ignoreCfg projectIgnoreCfg) ([]string, []string)
HasChangedBindMounts checks if any files used in docker compose `volumes:` definitions with type `bind` have changed using the Git status.
func HasChangedBuildFiles ¶ added in v0.73.0
func HasChangedBuildFiles(repoPathExternal string, paths []string, project *types.Project, _ projectIgnoreCfg) ([]string, []string)
HasChangedBuildFiles checks if any files used as build context in docker compose `build:` definitions have changed using the Git status. This includes any file within the build context directory for each service. If a changed file is within a build context, it returns true.
func HasChangedConfigs ¶ added in v0.29.0
func HasChangedConfigs(repoPathExternal string, paths []string, project *types.Project, ignoreCfg projectIgnoreCfg) ([]string, []string)
HasChangedConfigs checks if any files used in docker compose `configs:` definitions have changed using the Git status.
func HasChangedEnvFiles ¶ added in v0.31.1
func HasChangedEnvFiles(repoPathExternal string, paths []string, project *types.Project, _ projectIgnoreCfg) ([]string, []string)
HasChangedEnvFiles checks if any files used in docker compose `env_file:` definitions have changed using the Git status.
func HasChangedSecrets ¶ added in v0.29.0
func HasChangedSecrets(repoPathExternal string, paths []string, project *types.Project, ignoreCfg projectIgnoreCfg) ([]string, []string)
HasChangedSecrets checks if any files used in docker compose `secrets:` definitions have changed using the Git status.
func HaveDeployedServiceImageDigestsChanged ¶ added in v0.82.2
func HaveDeployedServiceImageDigestsChanged(ctx context.Context, dockerCli command.Cli, project *types.Project, logger *slog.Logger) (bool, error)
HaveDeployedServiceImageDigestsChanged checks if any currently deployed service image digest differs from the registry digest of the configured image ref.
This compares:
- deployed service image digest (currently running/deployed)
- registry digest of configured service image reference (DistributionInspect)
Returns true as soon as one service differs.
func LoadCompose ¶
func LoadCompose(ctx context.Context, repoPath, workingDir, projectName string, composeFiles, envFiles, profiles []string, environment map[string]string, ) (*types.Project, error)
LoadCompose parses and loads Compose files as specified by the Docker Compose specification.
func LoadSwarmStack ¶ added in v0.73.0
func LoadSwarmStack(dockerCli command.Cli, project *types.Project, deployConfig *deploy.Config, externalWorkingDir string, ) (*composetypes.Config, *options.Deploy, error)
LoadSwarmStack loads a Docker Swarm stack using the provided project and deploy configuration.
func NewHttpClient ¶
func NewJobScheduleParser ¶ added in v0.86.0
func ParseJobScheduleExpression ¶ added in v0.86.0
func ProjectFilesHaveChanges ¶ added in v0.31.1
func ProjectFilesHaveChanges(repoPathExternal string, changePaths []string, project *types.Project) ([]Change, IgnoredInfo, error)
ProjectFilesHaveChanges checks if any files related to the compose project have changed.
func ProjectHash ¶ added in v0.73.0
ProjectHash generates a SHA256 hash of the project configuration to be used for detecting changes in the project that may require a redeployment.
func PruneStackConfigs ¶ added in v0.31.0
func PruneStackSecrets ¶ added in v0.31.0
func PullImages ¶ added in v0.55.0
PullImages pulls all images defined in the named compose project.
func RemoveLabeledVolumes ¶ added in v0.31.0
func RemoveProject ¶ added in v0.33.0
func RemoveProject(ctx context.Context, dockerCli command.Cli, projectName string, timeout time.Duration, removeVolumes, removeImages bool) error
RemoveProject removes the entire project including containers, networks, volumes and images.
func RemoveSwarmStack ¶ added in v0.31.0
RemoveSwarmStack removes a Docker Swarm stack using the provided deploy configuration.
func RerunJobService ¶ added in v0.62.0
RerunJobService attempts to retrigger a Swarm job service (`replicated-job` or `global-job`) by updating the service spec (bumping a dummy label), causing Swarm to create new job tasks.
Note: Swarm does not allow UpdateConfig / RollbackConfig on job-mode services, so we must strip those fields before calling ServiceUpdate.
func RestartContainer ¶ added in v0.86.0
func RestartProject ¶ added in v0.33.0
func RestartProject(ctx context.Context, dockerCli command.Cli, projectName string, timeout time.Duration) error
RestartProject restarts all services in the specified project.
func RestartService ¶ added in v0.62.0
RestartService restarts long-running Swarm services by bumping ForceUpdate. For job-mode services (replicated-job/global-job), it returns ErrJobServiceRestartNotSupported.
func RunContainerOneOffFromExisting ¶ added in v0.88.0
func RunImagePruneJob ¶ added in v0.54.0
RunImagePruneJob runs a Docker Swarm global job to prune unused images on all nodes.
func RunImageRemoveJob ¶ added in v0.54.0
RunImageRemoveJob runs a Docker Swarm global job to remove specified images.
func RunSwarmJob ¶ added in v0.54.0
func RunSwarmJob(ctx context.Context, dockerCLI command.Cli, mode swarm.DeployMode, command []string, title string) error
RunSwarmJob runs a Docker Swarm job container with the specified mode and command. https://docs.docker.com/reference/cli/docker/service/create/#running-as-a-job
func RunSwarmOneOffFromService ¶ added in v0.88.0
func RunSwarmOneOffFromService(ctx context.Context, dockerCLI command.Cli, serviceName string, opts SwarmOneOffFromServiceOptions) error
RunSwarmOneOffFromService creates a temporary job service from an existing service spec and waits for completion.
func SetConfigHashPrefixes ¶ added in v0.31.0
func SetConfigHashPrefixes(stack *composetypes.Config, namespace string) error
SetConfigHashPrefixes generates hashes for the config definitions in the stack config and adds them to the config names as suffixes to trigger a redeployment when they change (Only works in Docker Swarm mode).
func SetSecretHashPrefixes ¶ added in v0.31.0
func SetSecretHashPrefixes(stack *composetypes.Config, namespace string) error
SetSecretHashPrefixes generates hashes for the secret definitions in the stack config and adds them to the secret names as suffixes to trigger a redeployment when they change (Only works in Docker Swarm mode).
func StartProject ¶ added in v0.33.0
func StartProject(ctx context.Context, dockerCli command.Cli, projectName string, timeout time.Duration) error
StartProject starts all services in the specified project.
func StopProject ¶ added in v0.33.0
func StopProject(ctx context.Context, dockerCli command.Cli, projectName string, timeout time.Duration) error
StopProject stops all services in the specified project.
func VerifyDockerAPIAccess ¶ added in v0.58.0
VerifyDockerAPIAccess verifies access to the Docker API either via DOCKER_HOST or the default socket.
func VerifyDockerHostConnection ¶ added in v0.58.0
VerifyDockerHostConnection verifies the connection to the specified DOCKER_HOST.
func VerifySocketConnection ¶
func VerifySocketConnection() error
VerifySocketConnection verifies whether the application can connect to the docker socket.
func VerifySocketRead ¶
VerifySocketRead verifies whether the application can read from the docker socket.
func WaitForSwarmService ¶ added in v0.62.0
func WaitForSwarmService(ctx context.Context, t *testing.T, cli dockerClient.APIClient, serviceName string, timeout time.Duration) (swarmTypes.Service, error)
WaitForSwarmService waits until a swarm service exists (and optionally has published ports).
Types ¶
type IgnoredInfo ¶ added in v0.77.0
type IgnoredInfo struct {
// Ignored services name
Ignored []string `json:"ignored"`
// Ignored services need to send signal
NeedSendSignal []SignalService `json:"need_signal"`
}
func (IgnoredInfo) IsEmpty ¶ added in v0.77.0
func (i IgnoredInfo) IsEmpty() bool
func (IgnoredInfo) IsNeedSignal ¶ added in v0.78.0
func (i IgnoredInfo) IsNeedSignal() bool
type JobExecutionMode ¶ added in v0.86.0
type JobExecutionMode string
const ( JobExecutionModeRestart JobExecutionMode = "restart" JobExecutionModeOneOff JobExecutionMode = "one_off" // JobExecutionModeOneShotDeprecated is the deprecated alias for JobExecutionModeOneOff. // // Deprecated: still accepted for backward compatibility but will log a warning // TODO: Remove in a future release. JobExecutionModeOneShotDeprecated JobExecutionMode = "one_shot" )
type JobNotifyOn ¶ added in v0.86.0
type JobNotifyOn string
const ( JobNotifyNone JobNotifyOn = "none" JobNotifySuccess JobNotifyOn = "success" JobNotifyFailure JobNotifyOn = "failure" JobNotifyAll JobNotifyOn = "all" )
type JobScheduleConfig ¶ added in v0.86.0
type JobScheduleConfig struct {
Enabled bool
Schedule string
SkipRunning bool
ExecutionMode JobExecutionMode
NotifyOn JobNotifyOn
SwarmReplicas uint64
}
func ParseJobScheduleLabels ¶ added in v0.86.0
func (JobScheduleConfig) ShouldNotifyFailure ¶ added in v0.86.0
func (c JobScheduleConfig) ShouldNotifyFailure() bool
func (JobScheduleConfig) ShouldNotifySuccess ¶ added in v0.86.0
func (c JobScheduleConfig) ShouldNotifySuccess() bool
type LatestServiceStatus ¶ added in v0.78.0
type LatestServiceStatus struct {
DeployedStatus map[Service]ServiceStatus
// contains filtered or unexported fields
}
func GetLatestDeployStatus ¶ added in v0.78.0
func GetLatestDeployStatus(ctx context.Context, client client.APIClient, cloneURL string, deployName string) (LatestServiceStatus, error)
GetLatestDeployStatus retrieves the deployed status for a given repository and deploy name.
func (LatestServiceStatus) GetDeploymentCommitSHA ¶ added in v0.83.0
func (l LatestServiceStatus) GetDeploymentCommitSHA() string
func (LatestServiceStatus) GetDeploymentComposeHash ¶ added in v0.83.0
func (l LatestServiceStatus) GetDeploymentComposeHash() string
type ServiceMismatch ¶ added in v0.78.0
type ServiceMismatch struct {
ServiceName string `json:"service_name"`
Reasons []ServiceMismatchReason `json:"reasons"`
}
func CheckServiceMismatch ¶ added in v0.78.0
func CheckServiceMismatch(swarmModeEnabled bool, deployed map[Service]ServiceStatus, services types.Services) []ServiceMismatch
CheckServiceMismatch checks if the deployed services match the services in the compose file. now only check replicas, swarm mode, missing and unnecessary services.
type ServiceMismatchReason ¶ added in v0.78.0
type ServiceStatus ¶ added in v0.78.0
type ServiceStatus struct {
// In non-Swarm mode:
// Labels may differ between containers within a service, but most of them should be identical for the same service,
// except for com.docker.compose.container-number, com.docker.compose.replace, and potentially others.
Labels Labels
// swarm deploy mode.
// Empty if not in swarm mode.
SwarmMode swarmInternal.DeployMode
// Non-swarm mode: number of running containers
// Swarm mode: number of service replicas
Replicas uint64
}