docker

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocketPath = "/var/run/docker.sock"
)

Variables

View Source
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
)
View Source
var (
	ErrNotAJobService                = errors.New("service is not a job-mode service")
	ErrJobServiceRestartNotSupported = errors.New("restart not supported for job services")
)
View Source
var (
	ErrMountPointNotFound     = errors.New("mount point not found")
	ErrMountPointNotWriteable = errors.New("mount point is not writeable")
	ErrContainerIDNotFound    = errors.New("container ID not found")
	ErrBuildInfoUnavailable   = errors.New("build info unavailable")
	ErrModuleNotFound         = errors.New("module not found in build info")
)
View Source
var (
	ErrDockerSocketConnectionFailed = errors.New("failed to connect to docker socket")
	ErrDockerHostConnectionFailed   = errors.New("failed to connect to docker host")
)
View Source
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",
		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",
		ExternalSecretsHash: "cd.doco.deployment.external_secrets.sha",
		AutoDiscover:        "cd.doco.deployment.auto_discover",
		AutoDiscoverDelete:  "cd.doco.deployment.auto_discover.delete",
	},
	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.

Functions

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 ConnectToSocket

func ConnectToSocket() (net.Conn, error)

ConnectToSocket connects to the docker socket.

func CreateDockerCli

func CreateDockerCli(quiet, verifyTLS bool) (command.Cli, error)

func DeployStack added in v0.14.0

func DeployStack(
	jobLog *slog.Logger, internalRepoPath, externalRepoPath string, ctx *context.Context,
	dockerCli *command.Cli, dockerClient *client.Client, payload *webhook.ParsedPayload, deployConfig *config.DeployConfig,
	changedFiles []gitInternal.ChangedFile, latestCommit, appVersion, triggerEvent string, forceDeploy bool,
	resolvedSecrets secrettypes.ResolvedSecrets, secretsChanged bool,
) 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, project *types.Project, deployConfig *config.DeployConfig,
	payload webhook.ParsedPayload, externalWorkingDir, latestCommit, appVersion, secretHash string, resolvedSecrets secrettypes.ResolvedSecrets,
) 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 *config.DeployConfig,
) error

DestroyStack destroys the stack using the provided deployment configuration.

func Exec added in v0.13.0

func Exec(client client.APIClient, containerID string, cmd ...string) (out string, err error)

func GetContainerID added in v0.13.0

func GetContainerID(client client.APIClient, name string) (id string, err error)

GetContainerID retrieves the container ID for a given service name.

func GetImages added in v0.55.0

func GetImages(ctx context.Context, dockerCli command.Cli, projectName string) (set.Set[string], error)

GetImages retrieves all image IDs used by the services in the compose project.

func GetLabeledConfigs added in v0.31.0

func GetLabeledConfigs(ctx context.Context, cli *client.Client, 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.Client, key, value string) (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.Client, 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.Client, 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.Client, key, value string) (volumes []*volume.Volume, err error)

GetLabeledVolumes retrieves all volumes with a specific label key and value.

func GetModuleVersion added in v0.30.0

func GetModuleVersion(module string) (string, error)

GetModuleVersion retrieves the version of a specified module from the build info.

func GetMountPointByDestination added in v0.13.0

func GetMountPointByDestination(cli *client.Client, 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 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.Client, stackName string) (map[Service]Labels, error)

GetServiceLabels retrieves the labels for all services in a given stack.

func HasChangedBindMounts added in v0.29.0

func HasChangedBindMounts(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

HasChangedBindMounts checks if any files used in docker compose `volumes:` definitions with type `bind` have changed using the Git status.

func HasChangedComposeFiles added in v0.31.1

func HasChangedComposeFiles(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

HasChangedComposeFiles checks if any of the compose files have changed using the Git status.

func HasChangedConfigs added in v0.29.0

func HasChangedConfigs(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

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(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

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(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

HasChangedSecrets checks if any files used in docker compose `secrets:` definitions have changed using the Git status.

func LoadCompose

func LoadCompose(ctx context.Context, 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 NewHttpClient

func NewHttpClient() *http.Client

func ProjectFilesHaveChanges added in v0.31.1

func ProjectFilesHaveChanges(changedFiles []gitInternal.ChangedFile, project *types.Project) (bool, error)

ProjectFilesHaveChanges checks if any files related to the compose project have changed.

func PruneStackConfigs added in v0.31.0

func PruneStackConfigs(ctx context.Context, client *client.Client, namespace string) error

func PruneStackSecrets added in v0.31.0

func PruneStackSecrets(ctx context.Context, client *client.Client, namespace string) error

func PullImages added in v0.55.0

func PullImages(ctx context.Context, dockerCli command.Cli, projectName string) error

PullImages pulls all images defined in the compose project.

func RemoveLabeledVolumes added in v0.31.0

func RemoveLabeledVolumes(ctx context.Context, dockerClient *client.Client, stackName string) error

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

func RemoveSwarmStack(ctx context.Context, dockerCli command.Cli, namespace string) error

RemoveSwarmStack removes a Docker Swarm stack using the provided deploy configuration.

func RerunJobService added in v0.62.0

func RerunJobService(ctx context.Context, cli *client.Client, serviceName string) error

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

func RestartService(ctx context.Context, cli *client.Client, serviceName string) error

RestartService restarts long-running Swarm services by bumping ForceUpdate. For job-mode services (replicated-job/global-job), it returns ErrJobServiceRestartNotSupported.

func RunImagePruneJob added in v0.54.0

func RunImagePruneJob(ctx context.Context, dockerCLI command.Cli) error

RunImagePruneJob runs a Docker Swarm global job to prune unused images on all nodes.

func RunImageRemoveJob added in v0.54.0

func RunImageRemoveJob(ctx context.Context, dockerCLI command.Cli, images []string) error

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 JobMode, 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 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

func VerifyDockerAPIAccess() (error, error)

VerifyDockerAPIAccess verifies access to the Docker API either via DOCKER_HOST or the default socket.

func VerifyDockerHostConnection added in v0.58.0

func VerifyDockerHostConnection(dockerHost string) error

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

func VerifySocketRead(httpClient *http.Client) error

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 *client.Client, serviceName string, timeout time.Duration) (swarmTypes.Service, error)

WaitForSwarmService waits until a swarm service exists (and optionally has published ports).

Types

type JobMode added in v0.54.0

type JobMode string

JobMode represents the mode of a Docker Swarm job.

const (
	JobModeGlobal     JobMode = "global-job"
	JobModeReplicated JobMode = "replicated-job"
)

type Labels added in v0.54.0

type Labels map[string]string

type Service added in v0.54.0

type Service string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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