engine

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("spod container execution requires Linux user namespaces")

Functions

func DefaultRoot

func DefaultRoot() (string, error)

DefaultRoot returns the platform-standard location for spod's storage: $XDG_DATA_HOME/spod/storage (defaulting to ~/.local/share/spod/storage) on Linux and other Unix systems, ~/Library/Application Support/spod/storage on macOS, and %LOCALAPPDATA%\spod\storage on Windows. SPOD_ROOT overrides the location and must be absolute.

func Init

func Init()

Init must be the very first call in main() for every binary that links this package. When the current process is a libcontainer re-exec (the init of a new container), it hands control to libcontainer and never returns. Otherwise it returns immediately and normal startup continues.

Detection uses the _LIBCONTAINER_INITPIPE environment marker that libcontainer sets on its re-exec child, so ordinary subcommands (e.g. a user-facing "init" wizard) are never mistaken for container init.

func ValidateName

func ValidateName(name string) error

Types

type Container

type Container struct {
	Name       string
	Image      string
	Status     string
	Entrypoint []string
	PID        int
	Created    time.Time
	Options    RunOptions
}

type Engine

type Engine struct {
	Root string
}

Engine is a daemonless, per-user image and container store.

func New

func New(root string) (*Engine, error)

func (*Engine) Discard

func (e *Engine) Discard(path string) error

Discard retains removed resources in the store's trash rather than deleting them.

func (*Engine) Exec

func (e *Engine) Exec(ctx context.Context, name string, opts ExecOptions, io IO) (int, error)

Exec runs an additional process inside a running container.

func (*Engine) Export

func (e *Engine) Export(ctx context.Context, name string, out io.Writer) error

Export writes a container's root filesystem as a plain uncompressed tar stream. The archive holds the filesystem as the container sees it: entries are owned by root, with modes and symlinks preserved. Runtime bind mounts and device nodes are host resources and are not part of the archive. The container keeps running while it is exported; files written concurrently may be captured mid-write.

func (*Engine) Images

func (e *Engine) Images() ([]Image, error)

Images lists only complete published images.

func (*Engine) Import

func (e *Engine) Import(ctx context.Context, ref string, archive io.Reader) (*Image, error)

Import builds a stored image from a plain filesystem tar, such as one produced by Export, so it can serve as the base image of other containers. The archive becomes the image's single layer; no entrypoint, environment, or history is inferred beyond a default PATH. The archive is buffered while the layer digest is computed. Import works on every platform; only running the resulting containers requires Linux.

func (*Engine) ImportOCI added in v0.2.0

func (e *Engine) ImportOCI(ctx context.Context, ref, path string) (*Image, error)

ImportOCI stores an image tarball under ref. Both common save formats are accepted: the OCI layout (podman save --format oci-archive) and the docker-save layout (docker save). Unlike Import, the archive carries the image's real layers and configuration, so the stored image behaves exactly like the source: entrypoint, environment, and history included. The archive must contain a single-platform image matching the host.

func (*Engine) Inspect

func (e *Engine) Inspect(ctx context.Context, name string) (*Container, error)

Inspect returns the current metadata for a container, reconciled with its live runtime state.

func (*Engine) InspectImage

func (e *Engine) InspectImage(ref string) (*Image, error)

InspectImage reads local metadata without contacting a registry.

func (*Engine) List

func (e *Engine) List(ctx context.Context) ([]Container, error)

List returns all containers in the store with reconciled status.

func (*Engine) PrepareRootfs

func (e *Engine) PrepareRootfs(ctx context.Context, ref, dest string) (_ *Image, retErr error)

PrepareRootfs creates an independent writable filesystem, never hardlinking files to the shared cache. dest must not exist, or must be an empty directory on the storage filesystem. The returned Image.Rootfs points to dest.

func (*Engine) Pull

func (e *Engine) Pull(ctx context.Context, ref string) (*Image, error)

Pull downloads a Linux image for the host architecture without a daemon. A cached reference is reused; remove it explicitly to refresh a mutable tag.

func (*Engine) Remove

func (e *Engine) Remove(ctx context.Context, name string, force bool) error

Remove deletes a container's metadata and rootfs. A running container is only removed when force is true (it is killed first). Removed resources are moved to the store trash, never deleted outright.

func (*Engine) RemoveImage

func (e *Engine) RemoveImage(ref string) error

RemoveImage retains the image in trash and refuses references used by a container. Unreadable container metadata fails closed.

func (*Engine) Rename

func (e *Engine) Rename(ctx context.Context, oldName, newName string) error

Rename changes a stopped container's name. Its store directories, metadata, named volumes, attach socket, and logs move with it, and mount sources referencing the moved volumes are rewritten. Running containers must be stopped first. Every move is journaled with its inverse, and metadata is replaced atomically, so a failure restores the original state instead of stranding data.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, opts RunOptions, io IO) (int, error)

Run creates a container with its own persistent rootfs and metadata, starts it, and blocks until the init process exits, returning its exit status. The caller (typically a detached monitor re-exec) owns stdio. Metadata reaches the running state (with PID) before Run begins waiting, so other processes can observe and signal it.

func (*Engine) Start

func (e *Engine) Start(ctx context.Context, name string, io IO) (int, error)

Start re-launches a previously created, stopped container using its persisted resolved configuration and existing rootfs, blocking until it exits.

func (*Engine) Stop

func (e *Engine) Stop(ctx context.Context, name string, timeout time.Duration) error

Stop sends SIGTERM to the container's init process and, if it does not exit within timeout, SIGKILL.

type ExecOptions

type ExecOptions struct {
	Command []string
	Env     []string
	WorkDir string
	User    string
	TTY     bool
}

type IO

type IO struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

type Image

type Image struct {
	Reference string
	Digest    string
	Rootfs    string
	Config    v1.Config
	Created   time.Time
	Platform  v1.Platform
}

Image describes an image and its unpacked filesystem. Pull and InspectImage return an immutable shared Rootfs; PrepareRootfs returns the writable copy.

type Lifecycle

Lifecycle is implemented directly by Engine on Linux and returns ErrUnsupported elsewhere.

type Mount

type Mount struct {
	Source   string
	Target   string
	ReadOnly bool
}

type RunOptions

type RunOptions struct {
	Name        string
	Image       string
	Command     []string
	Entrypoint  []string
	Env         []string
	WorkDir     string
	User        string
	Hostname    string
	Mounts      []Mount
	Labels      map[string]string
	TTY         bool
	Interactive bool
	Remove      bool
	Network     string
}

Jump to

Keyboard shortcuts

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