Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyResourceLimits(host *container.HostConfig, limits *core.ResourceLimits) bool
- func ApplyResourceLimitsToConfig(cfg *Config, limits *core.ResourceLimits) bool
- func ContainerDaemonHost(rt core.ContainerRuntime, envs map[string]string) (string, error)
- func EncodeBasicAuth(username, password string) string
- func EvalContainerFields(ctx context.Context, ct core.Container) (core.Container, error)
- func GetKeepaliveFile(platform specs.Platform) (string, error)
- func RegistryAuthFromContext(ctx context.Context) map[string]*core.AuthConfig
- func ResolveContainerRuntime(envs map[string]string) (core.ContainerRuntime, error)
- func ResolveDaemonHost(envs map[string]string) (string, error)
- func ServiceRuntimeEnv() map[string]string
- func WithContainerClient(ctx context.Context, cli *Client) context.Context
- func WithRegistryAuth(ctx context.Context, auths map[string]*core.AuthConfig) context.Context
- type Client
- func (c *Client) Close(ctx context.Context)
- func (c *Client) CreateContainerKeepAlive(ctx context.Context) error
- func (c *Client) Exec(ctx context.Context, cmd []string, stdout, stderr io.Writer, opts ExecOptions) (int, error)
- func (c *Client) Run(ctx context.Context, cmd []string, stdout, stderr io.Writer) (int, error)
- func (c *Client) StartBackground(ctx context.Context) error
- func (c *Client) Stop(sig os.Signal) error
- func (c *Client) StopContainerKeepAlive(ctx context.Context)
- type Config
- func LoadConfig(workDir string, ct core.Container, registryAuths map[string]*core.AuthConfig) (*Config, error)
- func LoadConfigFromMap(data map[string]any, registryAuths map[string]*core.AuthConfig) (*Config, error)
- func LoadConfigFromMapWithWorkDir(workDir string, data map[string]any, registryAuths map[string]*core.AuthConfig) (*Config, error)
- type ExecOptions
- type RegistryAuthManager
Constants ¶
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 ¶
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
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 ¶
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 ¶
EncodeBasicAuth encodes username and password as base64(username:password)
func EvalContainerFields ¶
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 ¶
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 ¶
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 ¶
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 ¶
WithContainerClient creates a new context with a client for container
func WithRegistryAuth ¶
WithRegistryAuth creates a new context with registry authentication.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func GetContainerClient ¶
GetContainerClient retrieves the container client from the context.
func InitializeClient ¶
InitializeClient creates a new container client
func (*Client) CreateContainerKeepAlive ¶
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) StartBackground ¶
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) StopContainerKeepAlive ¶
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.