Documentation
¶
Overview ¶
Package core provides core interfaces and types for container backends This package is separate from the main containers package to avoid import cycles
Index ¶
- Variables
- func RegisterBackend(backendType BackendType, factory BackendFactory)
- type Backend
- type BackendCapabilities
- type BackendConfig
- type BackendFactory
- type BackendType
- type BuildInput
- type ContainerConfig
- type ContainerID
- type ContainerInfo
- type ContainerdConfig
- type DockerConfig
- type FirecrackerConfig
- type IPConfig
- type IPv4Config
- type IPv6Config
- type Image
- type NanosConfig
- type NetworkConfig
- type PortMapping
- type ResourceLimits
- type RootlessMode
- type VolumeMount
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBuildNotSupported is returned when a backend doesn't support building images ErrBuildNotSupported = errors.New("build not supported by this backend") )
Functions ¶
func RegisterBackend ¶
func RegisterBackend(backendType BackendType, factory BackendFactory)
RegisterBackend registers a backend factory This is called by backend init() functions
Types ¶
type Backend ¶
type Backend interface {
// BackendType returns which backend this is (docker, containerd, etc.)
BackendType() BackendType
// Image operations - returns an Image interface for image management
Image(name string) Image
// Container operations
Create(ctx context.Context, config *ContainerConfig) (ContainerID, error)
Start(ctx context.Context, id ContainerID) error
Stop(ctx context.Context, id ContainerID) error
Remove(ctx context.Context, id ContainerID) error
Wait(ctx context.Context, id ContainerID) error
Logs(ctx context.Context, id ContainerID) (io.ReadCloser, error)
Inspect(ctx context.Context, id ContainerID) (*ContainerInfo, error)
// Backend-specific operations
HealthCheck(ctx context.Context) error
Capabilities() BackendCapabilities
}
Backend defines the interface for container runtime backends
type BackendCapabilities ¶
type BackendCapabilities struct {
// Supported resource limits
SupportsMemory bool
SupportsCPU bool
SupportsStorage bool
SupportsPIDs bool
SupportsMemorySwap bool
// Supported features
SupportsBuild bool
SupportsOCI bool
SupportsNetworking bool
SupportsVolumes bool
}
BackendCapabilities describes what a backend supports
type BackendConfig ¶
type BackendConfig interface {
BackendType() BackendType
}
BackendConfig is the interface that all backend configs must implement
type BackendFactory ¶
type BackendFactory func(BackendConfig) (Backend, error)
BackendFactory is a function that creates a backend from a config
func GetBackendFactory ¶
func GetBackendFactory(backendType BackendType) (BackendFactory, bool)
GetBackendFactory returns the factory for a given backend type
type BackendType ¶
type BackendType string
BackendType identifies which backend a configuration or build input is for
const ( BackendTypeContainerd BackendType = "containerd" BackendTypeDocker BackendType = "docker" BackendTypeFirecracker BackendType = "firecracker" BackendTypeNanos BackendType = "nanos" )
func AvailableBackendTypes ¶
func AvailableBackendTypes() []BackendType
AvailableBackendTypes returns all registered backend types
type BuildInput ¶
type BuildInput interface {
// Type returns the backend type this input is for
Type() BackendType
}
BuildInput is a type that can hold different build inputs for different backends Backends can type-assert to get their specific input type
type ContainerConfig ¶
type ContainerConfig struct {
Image string
Command []string
Shell []string
Env []string
WorkDir string
Volumes []VolumeMount // Unified volume mounts
Network *NetworkConfig // Unified network configuration
Resources *ResourceLimits
}
ContainerConfig holds all configuration for creating a container
type ContainerInfo ¶
type ContainerInfo struct {
ID ContainerID
Status string
ExitCode int
StartedAt time.Time
Image string
Resources *ResourceLimits
}
ContainerInfo contains information about a container
type ContainerdConfig ¶
type ContainerdConfig struct {
// SocketPath is the path to the containerd socket
// If empty, auto-detects based on platform and rootless mode
// In rootless mode, defaults to ~/.local/share/containerd/containerd.sock
SocketPath string
// Namespace is the containerd namespace to use
Namespace string
// RootlessMode specifies how rootless container mode should be handled
// Defaults to RootlessModeAuto (auto-detect based on user privileges)
RootlessMode RootlessMode
// RootlesskitPath is the path to rootlesskit binary (auto-detected if empty)
RootlesskitPath string
// FuseOverlayfsPath is the path to fuse-overlayfs binary (auto-detected if empty)
FuseOverlayfsPath string
// AutoStart enables automatic containerd startup if not running
// If true and containerd is not available, starts a rootless containerd instance
// Socket will be created in user home directory (~/.local/share/containerd/containerd.sock)
AutoStart bool
// ContainerdPath is the path to containerd binary (auto-detected if empty)
ContainerdPath string
}
ContainerdConfig contains configuration for the containerd backend
func (ContainerdConfig) BackendType ¶
func (c ContainerdConfig) BackendType() BackendType
type DockerConfig ¶
type DockerConfig struct {
// Host is the Docker daemon host/socket path
// If empty, defaults to DOCKER_HOST environment variable or /var/run/docker.sock
Host string
// APIVersion is the Docker API version to use
// If empty, uses API version negotiation
APIVersion string
}
DockerConfig contains configuration for the Docker backend
func (DockerConfig) BackendType ¶
func (d DockerConfig) BackendType() BackendType
type FirecrackerConfig ¶
type FirecrackerConfig struct {
// SocketPath is the path to the Firecracker socket
SocketPath string
// AutoDownload automatically downloads Firecracker binary if not found
AutoDownload bool
// Version is the Firecracker version to use (e.g., "v1.4.0")
// If empty, uses latest stable
Version string
// BinaryPath is the path to the Firecracker binary
// If empty and AutoDownload is true, downloads to cache
BinaryPath string
}
FirecrackerConfig contains configuration for the Firecracker backend
func (FirecrackerConfig) BackendType ¶
func (f FirecrackerConfig) BackendType() BackendType
type IPConfig ¶
type IPConfig struct {
// IPv4 configuration
IPv4 *IPv4Config
// IPv6 configuration
IPv6 *IPv6Config
}
IPConfig represents IP address configuration
type IPv4Config ¶
type IPv4Config struct {
// Static IP address (if empty, uses DHCP)
Address string
// Wait for DHCP (seconds, for OPS/Nanos)
WaitForDHCPSeconds int
// Gateway
Gateway string
// Subnet mask
Netmask string
}
IPv4Config represents IPv4 settings
type IPv6Config ¶
type IPv6Config struct {
// Static IPv6 address (if empty, uses DHCPv6)
Address string
// Wait for DHCPv6 (seconds, for OPS/Nanos)
WaitForDHCPSeconds int
// Gateway
Gateway string
}
IPv6Config represents IPv6 settings
type Image ¶
type Image interface {
// Pull retrieves the image from a registry/repository
Pull(ctx context.Context) error
// Build builds an image from backend-specific inputs
// Returns ErrBuildNotSupported if the backend doesn't support building
// Input types vary by backend:
// - Containerd: ContainerdBuildInput (Dockerfile + build context, uses BuildKit)
// - OPS/Nanos: NanosBuildInput (application binary path + config)
// - Firecracker: FirecrackerBuildInput (kernel + rootfs paths)
Build(ctx context.Context, input BuildInput) error
// Exists checks if the image exists locally
Exists(ctx context.Context) bool
// Remove removes the image from the backend
Remove(ctx context.Context) error
// Name returns the image name/identifier
Name() string
// Digest returns the image digest
Digest(ctx context.Context) (string, error)
// Tags returns all tags for this image
Tags(ctx context.Context) ([]string, error)
}
Image defines the interface for image operations
type NanosConfig ¶
type NanosConfig struct {
// ConfigPath is the path to the OPS config file (JSON)
ConfigPath string
// WorkDir is the working directory for OPS operations
WorkDir string
}
NanosConfig contains configuration for the Nanos backend
func (NanosConfig) BackendType ¶
func (n NanosConfig) BackendType() BackendType
type NetworkConfig ¶
type NetworkConfig struct {
// Network mode: bridge, host, none, custom
// For OPS/Nanos: maps to hypervisor network type (QEMU/Xen)
Mode string
// Port mappings: host port -> container port
PortMappings []PortMapping
// DNS servers
DNS []string
// Network aliases (for containerd/Docker)
Aliases []string
// Custom network name (for custom mode)
NetworkName string
// IP Configuration (for OPS/Nanos, Firecracker on bare metal)
IPConfig *IPConfig
// MTU size (for OPS/Nanos)
MTU int
// Additional backend-specific options
BackendOptions map[string]interface{}
}
NetworkConfig represents unified network configuration
type PortMapping ¶
type PortMapping struct {
HostPort int
ContainerPort int
Protocol string // "tcp", "udp"
HostIP string // Optional: bind to specific host IP
}
PortMapping represents a port mapping
type ResourceLimits ¶
type ResourceLimits struct {
Memory int64 // Memory limit in bytes
MemorySwap int64 // Total memory + swap limit in bytes (-1 for unlimited swap)
CPUQuota int64 // CPU quota in microseconds
CPUPeriod int64 // CPU period in microseconds
Storage int64 // Storage limit in bytes
PIDs int64 // Maximum number of PIDs
}
ResourceLimits defines resource constraints for containers
type RootlessMode ¶
type RootlessMode int
RootlessMode specifies how rootless container mode should be handled
const ( // RootlessModeAuto automatically detects rootless mode based on user privileges RootlessModeAuto RootlessMode = iota // RootlessModeEnabled forces rootless mode (fails if running as root) RootlessModeEnabled // RootlessModeDisabled forces root mode (runs as root) RootlessModeDisabled )
func (RootlessMode) String ¶
func (rm RootlessMode) String() string
String returns a string representation of the RootlessMode
type VolumeMount ¶
type VolumeMount struct {
Source string // Source path on host OR volume name (for OPS/Nanos)
Destination string // Destination path in container
ReadOnly bool // Whether the mount is read-only
// OPS/Nanos specific: if true, Source is treated as volume name
// Format: "volume_name:/mount/path" (for OPS volume mounting)
// If false, Source is a host path (standard bind mount)
IsVolumeName bool
}
VolumeMount represents a volume mount configuration