engine

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal added in v0.6.0

func IsTerminal() bool

IsTerminal reports whether stdin is connected to a terminal.

func LogsFlags added in v0.7.8

func LogsFlags(opts LogsOptions) []string

LogsFlags renders LogsOptions as CLI flags compatible with both Apple's `container logs` and `nerdctl logs`.

Types

type ContainerInfo

type ContainerInfo struct {
	ID      string
	Name    string
	Image   string
	State   string
	Status  string
	IP      string
	Ports   string
	Created time.Time
	Command string
	// Labels set at create time. Compose reads
	// com.docker.compose.{project,service,oneoff,config-hash} off list
	// responses to scope `docker compose ps` to its own project and fill
	// the Service column. Missing labels → blank service name and compose
	// treats the container as foreign.
	Labels map[string]string
}

func ParseNerdctlContainerList added in v0.4.0

func ParseNerdctlContainerList(data []byte) ([]ContainerInfo, error)

type Engine

type Engine struct {
	Binary string
}

Engine is the Apple Container CLI backend (macOS).

func New

func New(binary string) *Engine

func (*Engine) BinaryPath added in v0.4.0

func (e *Engine) BinaryPath() string

func (*Engine) ContainerExec

func (e *Engine) ContainerExec(ctx context.Context, nameOrID string, args []string, interactive bool) error

func (*Engine) ContainerInspect

func (e *Engine) ContainerInspect(ctx context.Context, nameOrID string) ([]byte, error)

func (*Engine) ContainerList

func (e *Engine) ContainerList(ctx context.Context, all bool) ([]ContainerInfo, error)

func (*Engine) ContainerLogs

func (e *Engine) ContainerLogs(ctx context.Context, nameOrID string, opts LogsOptions) error

func (*Engine) ContainerRemove

func (e *Engine) ContainerRemove(ctx context.Context, nameOrID string, force bool) error

func (*Engine) ContainerRun

func (e *Engine) ContainerRun(ctx context.Context, args []string, interactive bool) error

func (*Engine) ContainerStart

func (e *Engine) ContainerStart(ctx context.Context, nameOrID string) error

func (*Engine) ContainerStop

func (e *Engine) ContainerStop(ctx context.Context, nameOrID string) error

func (*Engine) EnsureSystemRunning added in v0.5.0

func (e *Engine) EnsureSystemRunning(ctx context.Context) error

EnsureSystemRunning checks whether the Apple Container system service is active and starts it automatically if it isn't. This prevents the confusing "XPC connection error: Connection invalid" message users see when the service has been stopped (e.g. after a reboot).

func (*Engine) Exec

func (e *Engine) Exec(ctx context.Context, args ...string) ([]byte, []byte, error)

func (*Engine) ExecInteractive

func (e *Engine) ExecInteractive(ctx context.Context, args ...string) error

func (*Engine) ExecStream

func (e *Engine) ExecStream(ctx context.Context, args ...string) (io.ReadCloser, error)

func (*Engine) ExecStreamSplit added in v0.7.8

func (e *Engine) ExecStreamSplit(ctx context.Context, args ...string) (io.ReadCloser, io.ReadCloser, error)

func (*Engine) ImageBuild

func (e *Engine) ImageBuild(ctx context.Context, args []string) error

func (*Engine) ImageList

func (e *Engine) ImageList(ctx context.Context) ([]ImageInfo, error)

func (*Engine) ImagePull

func (e *Engine) ImagePull(ctx context.Context, image string, opts ImagePullOpts) error

func (*Engine) ImagePush

func (e *Engine) ImagePush(ctx context.Context, image string) error

func (*Engine) ImageRemove

func (e *Engine) ImageRemove(ctx context.Context, image string) error

func (*Engine) NetworkConnect

func (e *Engine) NetworkConnect(ctx context.Context, network, container string) error

func (*Engine) NetworkCreate

func (e *Engine) NetworkCreate(ctx context.Context, name string, labels map[string]string) error

func (*Engine) NetworkDisconnect

func (e *Engine) NetworkDisconnect(ctx context.Context, network, container string) error

func (*Engine) NetworkInspect

func (e *Engine) NetworkInspect(ctx context.Context, name string) ([]byte, error)

func (*Engine) NetworkList

func (e *Engine) NetworkList(ctx context.Context) ([]NetworkInfo, error)

func (*Engine) NetworkRemove

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

func (*Engine) Validate

func (e *Engine) Validate() error

func (*Engine) VolumeCreate

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

func (*Engine) VolumeInspect

func (e *Engine) VolumeInspect(ctx context.Context, name string) ([]byte, error)

func (*Engine) VolumeList

func (e *Engine) VolumeList(ctx context.Context) ([]VolumeInfo, error)

func (*Engine) VolumeRemove

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

type ImageInfo

type ImageInfo struct {
	ID      string
	Name    string
	Tag     string
	Digest  string
	Size    string
	Created time.Time
	Arch    string
}

func ParseNerdctlImageList added in v0.4.0

func ParseNerdctlImageList(data []byte) ([]ImageInfo, error)

type ImagePullOpts added in v0.7.0

type ImagePullOpts struct {
	// Platform restricts the pull to a single platform, e.g. "linux/arm64".
	// Empty string uses the backend default (typically host architecture).
	Platform string
	// MaxConcurrent caps the number of layers downloaded in parallel.
	// 0 uses the backend default (Apple container CLI: 3). Only honored by
	// backends that expose this at the CLI — nerdctl does not.
	MaxConcurrent int
	// Progress selects the progress renderer: "ansi", "none", or "" for
	// auto-detect (ansi when stdout is a TTY, none otherwise). Prevents
	// ANSI redraw escape codes from cluttering piped/CI output.
	Progress string
}

ImagePullOpts controls image pull behavior. The zero value uses backend defaults.

type InspectData

type InspectData struct {
	Raw []byte // raw JSON from `container inspect`
}

type LogsOptions added in v0.7.8

type LogsOptions struct {
	Follow     bool
	Tail       string // "all" or a number; empty = backend default
	Since      string // RFC3339 timestamp or duration like "10m"
	Until      string // RFC3339 timestamp or duration
	Timestamps bool
}

LogsOptions controls container log retrieval. Zero value: full backlog, no follow.

type MockRuntime added in v0.5.0

type MockRuntime struct {
	ValidateFunc          func() error
	BinaryPathFunc        func() string
	ExecFunc              func(ctx context.Context, args ...string) ([]byte, []byte, error)
	ExecInteractiveFunc   func(ctx context.Context, args ...string) error
	ExecStreamFunc        func(ctx context.Context, args ...string) (io.ReadCloser, error)
	ContainerRunFunc      func(ctx context.Context, args []string, interactive bool) error
	ContainerListFunc     func(ctx context.Context, all bool) ([]ContainerInfo, error)
	ContainerStopFunc     func(ctx context.Context, nameOrID string) error
	ContainerStartFunc    func(ctx context.Context, nameOrID string) error
	ContainerRemoveFunc   func(ctx context.Context, nameOrID string, force bool) error
	ContainerExecFunc     func(ctx context.Context, nameOrID string, args []string, interactive bool) error
	ContainerLogsFunc     func(ctx context.Context, nameOrID string, opts LogsOptions) error
	ContainerInspectFunc  func(ctx context.Context, nameOrID string) ([]byte, error)
	ImagePullFunc         func(ctx context.Context, image string, opts ImagePullOpts) error
	ImagePushFunc         func(ctx context.Context, image string) error
	ImageListFunc         func(ctx context.Context) ([]ImageInfo, error)
	ImageRemoveFunc       func(ctx context.Context, image string) error
	ImageBuildFunc        func(ctx context.Context, args []string) error
	NetworkCreateFunc     func(ctx context.Context, name string, labels map[string]string) error
	NetworkListFunc       func(ctx context.Context) ([]NetworkInfo, error)
	NetworkRemoveFunc     func(ctx context.Context, name string) error
	NetworkConnectFunc    func(ctx context.Context, network, container string) error
	NetworkDisconnectFunc func(ctx context.Context, network, container string) error
	NetworkInspectFunc    func(ctx context.Context, name string) ([]byte, error)
	VolumeCreateFunc      func(ctx context.Context, name string) error
	VolumeListFunc        func(ctx context.Context) ([]VolumeInfo, error)
	VolumeRemoveFunc      func(ctx context.Context, name string) error
	VolumeInspectFunc     func(ctx context.Context, name string) ([]byte, error)
}

MockRuntime is a test double for the Runtime interface. Each method delegates to its corresponding function field. If a field is nil the method panics, except BinaryPath which returns "/mock/binary".

func (*MockRuntime) BinaryPath added in v0.5.0

func (m *MockRuntime) BinaryPath() string

func (*MockRuntime) ContainerExec added in v0.5.0

func (m *MockRuntime) ContainerExec(ctx context.Context, nameOrID string, args []string, interactive bool) error

func (*MockRuntime) ContainerInspect added in v0.5.0

func (m *MockRuntime) ContainerInspect(ctx context.Context, nameOrID string) ([]byte, error)

func (*MockRuntime) ContainerList added in v0.5.0

func (m *MockRuntime) ContainerList(ctx context.Context, all bool) ([]ContainerInfo, error)

func (*MockRuntime) ContainerLogs added in v0.5.0

func (m *MockRuntime) ContainerLogs(ctx context.Context, nameOrID string, opts LogsOptions) error

func (*MockRuntime) ContainerRemove added in v0.5.0

func (m *MockRuntime) ContainerRemove(ctx context.Context, nameOrID string, force bool) error

func (*MockRuntime) ContainerRun added in v0.5.0

func (m *MockRuntime) ContainerRun(ctx context.Context, args []string, interactive bool) error

func (*MockRuntime) ContainerStart added in v0.5.0

func (m *MockRuntime) ContainerStart(ctx context.Context, nameOrID string) error

func (*MockRuntime) ContainerStop added in v0.5.0

func (m *MockRuntime) ContainerStop(ctx context.Context, nameOrID string) error

func (*MockRuntime) Exec added in v0.5.0

func (m *MockRuntime) Exec(ctx context.Context, args ...string) ([]byte, []byte, error)

func (*MockRuntime) ExecInteractive added in v0.5.0

func (m *MockRuntime) ExecInteractive(ctx context.Context, args ...string) error

func (*MockRuntime) ExecStream added in v0.5.0

func (m *MockRuntime) ExecStream(ctx context.Context, args ...string) (io.ReadCloser, error)

func (*MockRuntime) ExecStreamSplit added in v0.7.8

func (m *MockRuntime) ExecStreamSplit(ctx context.Context, args ...string) (io.ReadCloser, io.ReadCloser, error)

func (*MockRuntime) ImageBuild added in v0.5.0

func (m *MockRuntime) ImageBuild(ctx context.Context, args []string) error

func (*MockRuntime) ImageList added in v0.5.0

func (m *MockRuntime) ImageList(ctx context.Context) ([]ImageInfo, error)

func (*MockRuntime) ImagePull added in v0.5.0

func (m *MockRuntime) ImagePull(ctx context.Context, image string, opts ImagePullOpts) error

func (*MockRuntime) ImagePush added in v0.5.0

func (m *MockRuntime) ImagePush(ctx context.Context, image string) error

func (*MockRuntime) ImageRemove added in v0.5.0

func (m *MockRuntime) ImageRemove(ctx context.Context, image string) error

func (*MockRuntime) NetworkConnect added in v0.5.0

func (m *MockRuntime) NetworkConnect(ctx context.Context, network, container string) error

func (*MockRuntime) NetworkCreate added in v0.5.0

func (m *MockRuntime) NetworkCreate(ctx context.Context, name string, labels map[string]string) error

func (*MockRuntime) NetworkDisconnect added in v0.5.0

func (m *MockRuntime) NetworkDisconnect(ctx context.Context, network, container string) error

func (*MockRuntime) NetworkInspect added in v0.5.0

func (m *MockRuntime) NetworkInspect(ctx context.Context, name string) ([]byte, error)

func (*MockRuntime) NetworkList added in v0.5.0

func (m *MockRuntime) NetworkList(ctx context.Context) ([]NetworkInfo, error)

func (*MockRuntime) NetworkRemove added in v0.5.0

func (m *MockRuntime) NetworkRemove(ctx context.Context, name string) error

func (*MockRuntime) Validate added in v0.5.0

func (m *MockRuntime) Validate() error

func (*MockRuntime) VolumeCreate added in v0.5.0

func (m *MockRuntime) VolumeCreate(ctx context.Context, name string) error

func (*MockRuntime) VolumeInspect added in v0.5.0

func (m *MockRuntime) VolumeInspect(ctx context.Context, name string) ([]byte, error)

func (*MockRuntime) VolumeList added in v0.5.0

func (m *MockRuntime) VolumeList(ctx context.Context) ([]VolumeInfo, error)

func (*MockRuntime) VolumeRemove added in v0.5.0

func (m *MockRuntime) VolumeRemove(ctx context.Context, name string) error

type NerdctlRuntime added in v0.4.0

type NerdctlRuntime struct {
	Binary string
}

NerdctlRuntime is the containerd/nerdctl backend (Linux).

func NewNerdctl added in v0.4.0

func NewNerdctl(binary string) *NerdctlRuntime

func (*NerdctlRuntime) BinaryPath added in v0.4.0

func (n *NerdctlRuntime) BinaryPath() string

func (*NerdctlRuntime) ContainerExec added in v0.4.0

func (n *NerdctlRuntime) ContainerExec(ctx context.Context, nameOrID string, args []string, interactive bool) error

func (*NerdctlRuntime) ContainerInspect added in v0.4.0

func (n *NerdctlRuntime) ContainerInspect(ctx context.Context, nameOrID string) ([]byte, error)

func (*NerdctlRuntime) ContainerList added in v0.4.0

func (n *NerdctlRuntime) ContainerList(ctx context.Context, all bool) ([]ContainerInfo, error)

func (*NerdctlRuntime) ContainerLogs added in v0.4.0

func (n *NerdctlRuntime) ContainerLogs(ctx context.Context, nameOrID string, opts LogsOptions) error

func (*NerdctlRuntime) ContainerRemove added in v0.4.0

func (n *NerdctlRuntime) ContainerRemove(ctx context.Context, nameOrID string, force bool) error

func (*NerdctlRuntime) ContainerRun added in v0.4.0

func (n *NerdctlRuntime) ContainerRun(ctx context.Context, args []string, interactive bool) error

func (*NerdctlRuntime) ContainerStart added in v0.4.0

func (n *NerdctlRuntime) ContainerStart(ctx context.Context, nameOrID string) error

func (*NerdctlRuntime) ContainerStop added in v0.4.0

func (n *NerdctlRuntime) ContainerStop(ctx context.Context, nameOrID string) error

func (*NerdctlRuntime) Exec added in v0.4.0

func (n *NerdctlRuntime) Exec(ctx context.Context, args ...string) ([]byte, []byte, error)

func (*NerdctlRuntime) ExecInteractive added in v0.4.0

func (n *NerdctlRuntime) ExecInteractive(ctx context.Context, args ...string) error

func (*NerdctlRuntime) ExecStream added in v0.4.0

func (n *NerdctlRuntime) ExecStream(ctx context.Context, args ...string) (io.ReadCloser, error)

func (*NerdctlRuntime) ExecStreamSplit added in v0.7.8

func (n *NerdctlRuntime) ExecStreamSplit(ctx context.Context, args ...string) (io.ReadCloser, io.ReadCloser, error)

func (*NerdctlRuntime) ImageBuild added in v0.4.0

func (n *NerdctlRuntime) ImageBuild(ctx context.Context, args []string) error

func (*NerdctlRuntime) ImageList added in v0.4.0

func (n *NerdctlRuntime) ImageList(ctx context.Context) ([]ImageInfo, error)

func (*NerdctlRuntime) ImagePull added in v0.4.0

func (n *NerdctlRuntime) ImagePull(ctx context.Context, image string, opts ImagePullOpts) error

func (*NerdctlRuntime) ImagePush added in v0.4.0

func (n *NerdctlRuntime) ImagePush(ctx context.Context, image string) error

func (*NerdctlRuntime) ImageRemove added in v0.4.0

func (n *NerdctlRuntime) ImageRemove(ctx context.Context, image string) error

func (*NerdctlRuntime) NetworkConnect added in v0.4.0

func (n *NerdctlRuntime) NetworkConnect(ctx context.Context, network, container string) error

func (*NerdctlRuntime) NetworkCreate added in v0.4.0

func (n *NerdctlRuntime) NetworkCreate(ctx context.Context, name string, labels map[string]string) error

func (*NerdctlRuntime) NetworkDisconnect added in v0.4.0

func (n *NerdctlRuntime) NetworkDisconnect(ctx context.Context, network, container string) error

func (*NerdctlRuntime) NetworkInspect added in v0.4.0

func (n *NerdctlRuntime) NetworkInspect(ctx context.Context, name string) ([]byte, error)

func (*NerdctlRuntime) NetworkList added in v0.4.0

func (n *NerdctlRuntime) NetworkList(ctx context.Context) ([]NetworkInfo, error)

func (*NerdctlRuntime) NetworkRemove added in v0.4.0

func (n *NerdctlRuntime) NetworkRemove(ctx context.Context, name string) error

func (*NerdctlRuntime) Validate added in v0.4.0

func (n *NerdctlRuntime) Validate() error

func (*NerdctlRuntime) VolumeCreate added in v0.4.0

func (n *NerdctlRuntime) VolumeCreate(ctx context.Context, name string) error

func (*NerdctlRuntime) VolumeInspect added in v0.4.0

func (n *NerdctlRuntime) VolumeInspect(ctx context.Context, name string) ([]byte, error)

func (*NerdctlRuntime) VolumeList added in v0.4.0

func (n *NerdctlRuntime) VolumeList(ctx context.Context) ([]VolumeInfo, error)

func (*NerdctlRuntime) VolumeRemove added in v0.4.0

func (n *NerdctlRuntime) VolumeRemove(ctx context.Context, name string) error

type NetworkInfo

type NetworkInfo struct {
	ID     string
	Name   string
	Driver string
	Scope  string
	// Labels are the resource labels set at create time. Critical for
	// Docker Compose compatibility: compose reads
	// com.docker.compose.project to decide whether a network is "its own"
	// vs foreign. Returning empty labels causes compose to refuse its own
	// networks with "not created by Docker Compose".
	Labels map[string]string
}

func ParseNerdctlNetworkList added in v0.4.0

func ParseNerdctlNetworkList(data []byte) ([]NetworkInfo, error)

type Runtime added in v0.4.0

type Runtime interface {
	// Validate checks that the backend binary exists and is usable.
	Validate() error

	// BinaryPath returns the path to the underlying runtime binary.
	BinaryPath() string

	// Low-level exec — used by API server and commands that need raw CLI access.
	Exec(ctx context.Context, args ...string) ([]byte, []byte, error)
	ExecInteractive(ctx context.Context, args ...string) error
	ExecStream(ctx context.Context, args ...string) (io.ReadCloser, error)
	ExecStreamSplit(ctx context.Context, args ...string) (stdout io.ReadCloser, stderr io.ReadCloser, err error)

	// Container lifecycle
	ContainerRun(ctx context.Context, args []string, interactive bool) error
	ContainerList(ctx context.Context, all bool) ([]ContainerInfo, error)
	ContainerStop(ctx context.Context, nameOrID string) error
	ContainerStart(ctx context.Context, nameOrID string) error
	ContainerRemove(ctx context.Context, nameOrID string, force bool) error
	ContainerExec(ctx context.Context, nameOrID string, args []string, interactive bool) error
	ContainerLogs(ctx context.Context, nameOrID string, opts LogsOptions) error
	ContainerInspect(ctx context.Context, nameOrID string) ([]byte, error)

	// Images
	ImagePull(ctx context.Context, image string, opts ImagePullOpts) error
	ImagePush(ctx context.Context, image string) error
	ImageList(ctx context.Context) ([]ImageInfo, error)
	ImageRemove(ctx context.Context, image string) error
	ImageBuild(ctx context.Context, args []string) error

	// Networks. Labels may be nil. Compose v2 sends
	// com.docker.compose.{project,network,version}; without these, it
	// refuses to re-adopt the network on a subsequent 'docker compose up'.
	NetworkCreate(ctx context.Context, name string, labels map[string]string) error
	NetworkList(ctx context.Context) ([]NetworkInfo, error)
	NetworkRemove(ctx context.Context, name string) error
	NetworkConnect(ctx context.Context, network, container string) error
	NetworkDisconnect(ctx context.Context, network, container string) error
	NetworkInspect(ctx context.Context, name string) ([]byte, error)

	// Volumes
	VolumeCreate(ctx context.Context, name string) error
	VolumeList(ctx context.Context) ([]VolumeInfo, error)
	VolumeRemove(ctx context.Context, name string) error
	VolumeInspect(ctx context.Context, name string) ([]byte, error)
}

Runtime is the interface that all container backends must implement. The current Engine struct (Apple Container CLI) implements this interface. Future backends (e.g., NerdctlRuntime) will also implement it.

func DetectRuntime added in v0.4.0

func DetectRuntime(binaryOverride string) (Runtime, error)

DetectRuntime auto-detects the appropriate container runtime for the current platform. On macOS it uses Apple's container CLI, on Linux it uses nerdctl (containerd).

type VolumeInfo

type VolumeInfo struct {
	Name       string
	Driver     string
	Mountpoint string
	Created    time.Time
	// Labels — see NetworkInfo.Labels. Compose checks
	// com.docker.compose.project here too.
	Labels map[string]string
}

func ParseNerdctlVolumeList added in v0.4.0

func ParseNerdctlVolumeList(data []byte) ([]VolumeInfo, error)

Jump to

Keyboard shortcuts

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