docker

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: GPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PodmanDaemonHostDefault = "unix:///run/podman/podman.sock"
	PodmanDaemonHostEnv     = "DAGU_PODMAN_HOST"
	ContainerRuntimeEnv     = "DAGU_CONTAINER_RUNTIME"
)

Container runtime selection is a SERVICE-LEVEL setting, not a per-step or per-DAG YAML field. DAGU_CONTAINER_RUNTIME chooses docker (default) or podman for every containerized step in this engine: harness.run CLI steps, step-level container jobs, and the DAG-level container. DAGU_PODMAN_HOST optionally overrides podman's Docker-compatible socket path.

Variables

View Source
var (
	ErrImageOrContainerShouldNotBeEmpty = errors.New("container_name or image must be specified")
	ErrImageRequired                    = errors.New("image is required")
	ErrInvalidVolumeFormat              = errors.New("invalid volume format")
	ErrInvalidPortFormat                = errors.New("invalid port format")
	ErrContainerIsNotRunning            = errors.New("container is not running")
	// Validation errors for docker executor map config
	ErrExecOnlyWithContainerName       = errors.New("'exec' options require 'container_name' (exec-in-existing mode)")
	ErrInvalidOptionsWithContainerName = errors.New("'container', 'host', 'network', 'pull', 'platform', or 'auto_remove' not supported with 'container_name'")
)

Errors for container

View Source
var (
	ErrExecutorConfigRequired = errors.New("docker step configuration is required")
)

Functions

func ApplyResourceLimits

func ApplyResourceLimits(host *container.HostConfig, limits *core.ResourceLimits) bool

ApplyResourceLimits maps DAG resource limits to Docker host resources.

func ApplyResourceLimitsToConfig

func ApplyResourceLimitsToConfig(cfg *Config, limits *core.ResourceLimits) bool

ApplyResourceLimitsToConfig applies limits only to configurations that create a new container. Existing-container exec mode cannot change host resources.

func ContainerDaemonHost

func ContainerDaemonHost(rt core.ContainerRuntime, envs map[string]string) (string, error)

ContainerDaemonHost maps the resolved container runtime to the daemon API host the Moby SDK client should drive. docker (or empty) returns "" so the client keeps upstream client.FromEnv behavior (honoring DOCKER_HOST). podman returns its Docker-compatible socket, overridable via DAGU_PODMAN_HOST.

func EncodeBasicAuth

func EncodeBasicAuth(username, password string) string

EncodeBasicAuth encodes username and password as base64(username:password)

func EvalContainerFields

func EvalContainerFields(ctx context.Context, ct core.Container) (core.Container, error)

EvalContainerFields evaluates environment variables in container fields at runtime. Only fields that commonly use variables are evaluated: - Exec, Image, Name, User, WorkingDir, Network (string fields) - Volumes, Ports, Env, Command, Shell (slice fields) Fields like PullPolicy, Startup, WaitFor, KeepContainer are NOT evaluated as they have specific enum/boolean values.

func GetKeepaliveFile

func GetKeepaliveFile(platform specs.Platform) (string, error)

GetKeepaliveFile copies the embedded keepalive binary to a temp file and returns its path

func RegistryAuthFromContext

func RegistryAuthFromContext(ctx context.Context) map[string]*core.AuthConfig

RegistryAuthFromContext exposes the context registry auth to other executors (the harness executor reuses it so containerized harness steps pull private images with the same auth as the docker executor).

func ResolveContainerRuntime

func ResolveContainerRuntime(envs map[string]string) (core.ContainerRuntime, error)

ResolveContainerRuntime reads the deployment's DAGU_CONTAINER_RUNTIME setting and parses it into the runtime enum, defaulting to docker when unset. This is the single place that decides docker vs podman; there is no per-step field.

func ResolveDaemonHost

func ResolveDaemonHost(envs map[string]string) (string, error)

ResolveDaemonHost is the production call site: it resolves DAGU_CONTAINER_RUNTIME from the given env map and returns the daemon API host to drive ("" for docker, the podman socket for podman). Callers pass ServiceRuntimeEnv() so the selection comes only from the engine process environment.

func ServiceRuntimeEnv

func ServiceRuntimeEnv() map[string]string

ServiceRuntimeEnv returns the runtime-selection variables read from the engine PROCESS environment only (os.LookupEnv), never from the DAG/step runtime scope. Runtime selection is a service-level decision, so it must not be overridable by a DAG- or step-level env: entry (the runtime scope precedence is StepEnv > Outputs > Secrets > DAGEnv > OS, which would let a workflow redirect the daemon socket). Only the two selection keys are surfaced.

func WithContainerClient

func WithContainerClient(ctx context.Context, cli *Client) context.Context

WithContainerClient creates a new context with a client for container

func WithRegistryAuth

func WithRegistryAuth(ctx context.Context, auths map[string]*core.AuthConfig) context.Context

WithRegistryAuth creates a new context with registry authentication.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func GetContainerClient

func GetContainerClient(ctx context.Context) *Client

GetContainerClient retrieves the container client from the context.

func InitializeClient

func InitializeClient(ctx context.Context, cfg *Config) (*Client, error)

InitializeClient creates a new container client

func (*Client) Close

func (c *Client) Close(ctx context.Context)

Close closes the container client and cleans up resources

func (*Client) CreateContainerKeepAlive

func (c *Client) CreateContainerKeepAlive(ctx context.Context) error

CreateContainerKeepAlive creates the container that lives while the DAG running

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, cmd []string, stdout, stderr io.Writer, opts ExecOptions) (int, error)

Exec executes the command in the running container

func (*Client) Run

func (c *Client) Run(ctx context.Context, cmd []string, stdout, stderr io.Writer) (int, error)

Run executes the command in the container and returns exit code

func (*Client) StartBackground

func (c *Client) StartBackground(ctx context.Context) error

StartBackground starts a container in the background without waiting for it to exit. This is useful for starting containers that should stay running while multiple commands are executed via Exec. The container uses the configured startup command (StartCmd) when startup mode is "command", or the default keepalive when in "keepalive" mode. This delegates to CreateContainerKeepAlive which handles all startup modes properly.

func (*Client) Stop

func (c *Client) Stop(sig os.Signal) error

Stop stops the running container

func (*Client) StopContainerKeepAlive

func (c *Client) StopContainerKeepAlive(ctx context.Context)

StopContainerKeepAlive stops the container running keep alive command

type Config

type Config struct {
	// DaemonHost optionally overrides the Docker-compatible daemon API host the
	// Moby SDK client connects to (e.g. "unix:///run/podman/podman.sock"). Empty
	// preserves the upstream client.FromEnv behavior (DOCKER_HOST or the default
	// docker socket). Set from the DAGU_CONTAINER_RUNTIME service setting for all
	// container forms: DAG-level container, step-level container jobs, and
	// harness.run container steps (see ResolveDaemonHost in runtime.go).
	DaemonHost string
	// Image is the Docker image to use for creating a new container.
	Image string
	// Platform is the target platform for the container (e.g., linux/amd64).
	Platform string
	// ContainerName is the name or ID of an existing container to exec into.
	ContainerName string
	// Pull is the image pull policy for new containers.
	Pull core.PullPolicy
	// Container is the container configuration for new containers.
	// See https://pkg.go.dev/github.com/moby/moby/api/types/container#Config
	Container *container.Config
	// Host is the host configuration for new containers.
	// See https://pkg.go.dev/github.com/moby/moby/api/types/container#HostConfig
	Host *container.HostConfig
	// Network is the network configuration for new containers.
	// See https://pkg.go.dev/github.com/moby/moby/api/types/network#NetworkingConfig
	Network *network.NetworkingConfig
	// ExecOptions are the options for executing a command in the container.
	// See https://pkg.go.dev/github.com/moby/moby/client#ExecCreateOptions
	ExecOptions *client.ExecCreateOptions
	// AutoRemove indicates whether to automatically remove the container after it exits.
	AutoRemove bool
	// AuthManager is responsible for managing registry authentication.
	AuthManager *RegistryAuthManager

	// Startup mode for DAG-level container: "keepalive" (default) | "entrypoint" | "command"
	Startup string
	// WaitFor readiness gate: "running" (default) | "healthy"
	WaitFor string
	// StartCmd command for startup when startup == "command"
	StartCmd []string
	// LogPattern optional regex to wait for in logs before proceeding (if empty, no wait)
	LogPattern string
	// ShouldStart indicates whether the container should be started (for DAG-level containers)
	ShouldStart bool
	// Shell specifies the shell wrapper for executing step commands.
	Shell []string
}

Config holds the configuration for creating or using a container.

func LoadConfig

func LoadConfig(workDir string, ct core.Container, registryAuths map[string]*core.AuthConfig) (*Config, error)

NewFromContainerConfigWithAuth parses core.Container into Container struct with registry auth

func LoadConfigFromMap

func LoadConfigFromMap(data map[string]any, registryAuths map[string]*core.AuthConfig) (*Config, error)

LoadConfigFromMap parses executorConfig into Container struct with registry auth.

func LoadConfigFromMapWithWorkDir

func LoadConfigFromMapWithWorkDir(workDir string, data map[string]any, registryAuths map[string]*core.AuthConfig) (*Config, error)

LoadConfigFromMapWithWorkDir parses executorConfig and resolves shortcut volume sources relative to workDir.

type ExecOptions

type ExecOptions struct {
	// WorkingDir overrides the working directory for the exec command.
	WorkingDir string
	// Env adds or overrides environment variables for this exec command.
	Env []string
	// Direct executes cmd as argv without applying the configured shell wrapper.
	Direct bool
	// PIDFile records the container-local process ID for targeted cancellation.
	PIDFile string
	// TerminateOnCancel attempts to terminate only the exec process when ctx is canceled.
	TerminateOnCancel bool
}

ExecOptions specifies options to execute commands in the container.

type RegistryAuthManager

type RegistryAuthManager struct {
	// contains filtered or unexported fields
}

RegistryAuthManager handles authentication for container registries

func NewRegistryAuthManager

func NewRegistryAuthManager(auths map[string]*core.AuthConfig) *RegistryAuthManager

NewRegistryAuthManager creates a new registry authentication manager

func (*RegistryAuthManager) GetAuthHeader

func (r *RegistryAuthManager) GetAuthHeader(imageName string) (string, error)

GetAuthHeader returns the X-Registry-Auth header value for the given image

func (*RegistryAuthManager) GetPullOptions

func (r *RegistryAuthManager) GetPullOptions(imageName string, platform specs.Platform) (client.ImagePullOptions, error)

GetPullOptions returns ImagePullOptions with authentication for the given image.

Jump to

Keyboard shortcuts

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