docker

package
v1.30.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrImageOrContainerShouldNotBeEmpty = errors.New("containerName 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 'containerName' (exec-in-existing mode)")
	ErrInvalidOptionsWithContainerName = errors.New("'container', 'host', 'network', 'pull', 'platform', or 'autoRemove' not supported with 'containerName'")
)

Errors for container

View Source
var (
	ErrExecutorConfigRequired = errors.New("executor config is required")
)

Functions

func EncodeBasicAuth

func EncodeBasicAuth(username, password string) string

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

func EvalContainerFields added in v1.30.0

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 (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 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 added in v1.29.0

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 {
	// 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/docker/docker/api/types/container#Config
	Container *container.Config
	// Host is the host configuration for new containers.
	// See https://pkg.go.dev/github.com/docker/docker/api/types/container#HostConfig
	Host *container.HostConfig
	// Network is the network configuration for new containers.
	// See https://pkg.go.dev/github.com/docker/docker@v27.5.1+incompatible/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/docker/docker/api/types/container#ExecOptions
	ExecOptions *container.ExecOptions
	// 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
}

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)

LoadConfig parses executorConfig into Container struct with registry auth

type ExecOptions

type ExecOptions struct {
	// WorkingDir overrides the working directory for the exec command.
	WorkingDir string
}

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 string) (image.PullOptions, 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