core

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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 blocks until the container exits. The container's own exit status is
	// not an error: it is reported by Inspect. Wait errors only when waiting
	// itself fails.
	Wait(ctx context.Context, id ContainerID) error
	// Logs returns the container's output as a docker-multiplexed stream, to be
	// demultiplexed with stdcopy. Callers must read it before removing the container.
	Logs(ctx context.Context, id ContainerID) (io.ReadCloser, error)
	Inspect(ctx context.Context, id ContainerID) (*ContainerInfo, error)

	// Clean removes images older than age. A build node pulls a new image for
	// every toolchain version it sees, so without this its disk fills up.
	//
	// reference scopes the sweep to one image reference; empty means every
	// image the backend can see, including ones tau never pulled.
	Clean(ctx context.Context, age time.Duration, reference string) error

	// Backend-specific operations
	HealthCheck(ctx context.Context) error
	Capabilities() BackendCapabilities
}

Backend defines the interface for container runtime backends

type BackendCapabilities

type BackendCapabilities struct {
	// SupportsBuild reports whether the backend can build an image from a
	// Dockerfile. containerd cannot without BuildKit, so callers building
	// images must check this first.
	SupportsBuild 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"
)

func AvailableBackendTypes

func AvailableBackendTypes() []BackendType

AvailableBackendTypes returns all registered backend types

type ContainerConfig

type ContainerConfig struct {
	Image     string
	Command   []string
	Env       []string
	WorkDir   string
	Volumes   []VolumeMount  // Unified volume mounts
	Network   *NetworkConfig // Unified network configuration
	Resources *ResourceLimits

	// Privileges a container needs beyond the runtime's defaults. Nothing but
	// the image build sets these today: BuildKit has to mount filesystems to
	// assemble layers, which the default sandbox forbids. They are here rather
	// than hidden inside the build path because they describe the container,
	// and a workload imported from a PaaS may legitimately need them too.
	Privileges *Privileges
}

ContainerConfig holds all configuration for creating a container

type ContainerID

type ContainerID string

ContainerID is a type-safe identifier for containers

func NewContainerID added in v1.3.0

func NewContainerID() ContainerID

NewContainerID names a new container. The time is for people reading it; the random part is what keeps containers created in the same instant apart.

type ContainerInfo

type ContainerInfo struct {
	ID        ContainerID
	Status    string
	ExitCode  int
	OOMKilled bool // the kernel killed a process in the container for memory; false when unconfirmed
	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

	// Runtime names the containerd runtime handler untrusted workloads are run
	// with — "io.containerd.runsc.v1" for gVisor, say. Empty means containerd's
	// default, which is runc: the host kernel is then the only boundary a
	// container has, so a node running untrusted code should name a sandboxed
	// one. It is a handler name rather than a flag so that swapping the
	// implementation later is configuration, not a code change.
	Runtime 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 DockerfileBuild added in v1.2.0

type DockerfileBuild struct {
	// RestrictEgress confines the build the same way NetworkConfig does for a
	// container. A Dockerfile is repository content, so its RUN steps are as
	// untrusted as anything else the repository ships.
	RestrictEgress bool

	// Context is a tar stream of the build directory.
	Context io.Reader
	// Dockerfile is the path within the context; empty means "Dockerfile".
	Dockerfile string
}

DockerfileBuild is everything needed to build an image from a Dockerfile: a tar of the build context, and the name of the Dockerfile within it.

func (*DockerfileBuild) DockerfileName added in v1.2.0

func (d *DockerfileBuild) DockerfileName() string

DockerfileName returns the Dockerfile to build, defaulting to "Dockerfile".

type Image

type Image interface {
	// Pull retrieves the image from a registry/repository
	Pull(ctx context.Context) error
	// Build builds the image from a Dockerfile.
	// Returns ErrBuildNotSupported if the backend cannot build.
	Build(ctx context.Context, input *DockerfileBuild) 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 NetworkConfig

type NetworkConfig struct {
	// Network mode: bridge, host, none, custom.
	// The containerd backend runs without CNI and accepts only host and none.
	Mode string

	// Port mappings: host port -> container port. Docker only.
	PortMappings []PortMapping

	// DNS servers
	DNS []string

	// RestrictEgress makes the backend install a host firewall that blocks the
	// container from reaching node-local and private/link-local networks (the
	// cloud metadata endpoint, loopback, RFC1918) while still allowing the
	// public internet. Set for untrusted workloads. Fail-closed: if the firewall
	// cannot be installed (e.g. missing CAP_NET_ADMIN) the container is not
	// started.
	RestrictEgress bool
}

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 Privileges added in v1.2.0

type Privileges struct {
	// Capabilities to add, named without the CAP_ prefix (e.g. "SYS_ADMIN").
	Capabilities []string

	// Devices from the host to expose, by path (e.g. "/dev/fuse").
	Devices []string

	// Unconfined drops the runtime's default seccomp and AppArmor profiles.
	//
	// ponytail: one switch for both, because the only caller wants both off.
	// Split into per-profile settings if anything ever needs finer control.
	Unconfined bool

	// Privileged removes essentially all confinement. Only ask for it where the
	// runtime is already running as real root, since there the container's
	// confinement is the only thing being relaxed and nothing new is granted;
	// under a rootless runtime the user namespace is the real boundary and
	// narrower privileges belong there instead.
	Privileged bool
}

Privileges loosens a container's default confinement. Every field widens what the container may do, so leave it nil unless something demonstrably needs it.

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
	CPUShares  int64 // CPU shares (relative weight)
	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 when IsVolumeName
	Destination string // Destination path in container
	ReadOnly    bool   // Whether the mount is read-only

	// IsVolumeName treats Source as a named volume rather than a host path.
	// Docker only: containerd has no volume manager and rejects these.
	IsVolumeName bool
}

VolumeMount represents a volume mount configuration

Jump to

Keyboard shortcuts

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