Documentation
¶
Overview ¶
Package runtime abstracts a container runtime (Docker or Podman) behind the small set of operations Ballast needs: discover containers and their mounts, watch the socket for lifecycle changes, exec into a container to quiesce or dump it, and stop or start it for a cold backup.
The interface is deliberately kept free of any tool-specific type. It was shaped against exactly one real consumer (Ballast) before being lifted into github.com/tagwright/core, which is the discipline that keeps the abstraction honest.
The Docker adapter lands first. The Podman adapter follows behind the same interface, talking to Podman's Docker-compatible compat API and absorbing the socket-path and compose-label differences.
Index ¶
- Variables
- type Container
- type DockerRuntime
- func (e DockerRuntime) Close() error
- func (e DockerRuntime) Exec(ctx context.Context, id string, spec ExecSpec) (*ExecHandle, error)
- func (e DockerRuntime) Inspect(ctx context.Context, id string) (Container, error)
- func (e DockerRuntime) List(ctx context.Context) ([]Container, error)
- func (e DockerRuntime) Start(ctx context.Context, id string) error
- func (e DockerRuntime) Stop(ctx context.Context, id string, timeoutSeconds int) error
- func (e DockerRuntime) Watch(ctx context.Context) (<-chan Event, <-chan error)
- type Event
- type EventType
- type ExecHandle
- type ExecSpec
- type Mount
- type MountType
- type PodmanRuntime
- func (e PodmanRuntime) Close() error
- func (e PodmanRuntime) Exec(ctx context.Context, id string, spec ExecSpec) (*ExecHandle, error)
- func (e PodmanRuntime) Inspect(ctx context.Context, id string) (Container, error)
- func (e PodmanRuntime) List(ctx context.Context) ([]Container, error)
- func (e PodmanRuntime) Start(ctx context.Context, id string) error
- func (e PodmanRuntime) Stop(ctx context.Context, id string, timeoutSeconds int) error
- func (e PodmanRuntime) Watch(ctx context.Context) (<-chan Event, <-chan error)
- type Runtime
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("runtime: not implemented")
ErrNotImplemented is returned by adapter methods that are not wired up yet.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
ID string
Name string
State string // running, exited, paused, ...
Labels map[string]string
Mounts []Mount
Project string // com.docker.compose.project, empty if not a compose service
Service string // com.docker.compose.service, empty if not a compose service
}
Container is the normalized view of a container across runtimes.
type DockerRuntime ¶
type DockerRuntime struct {
// contains filtered or unexported fields
}
DockerRuntime is the Docker adapter for Runtime. It talks to the Docker Engine API over the socket Ballast mounts read-only, using the request and mapping machinery in engine.go that it shares with PodmanRuntime.
The client is created lazily on first use and cached, so constructing a DockerRuntime never touches the socket: nothing fails until a method that actually needs the daemon is called.
func NewDocker ¶
func NewDocker(socket string) *DockerRuntime
NewDocker returns a Docker adapter bound to the given API socket path.
func (DockerRuntime) Close ¶
func (e DockerRuntime) Close() error
Close releases the underlying client.
func (DockerRuntime) Exec ¶
Exec runs a command inside a running container and returns a handle whose Stdout streams the command's standard output as it is produced, which matters because the caller pipes a live dump into restic --stdin rather than buffering it. Standard error is captured separately and folded into the error Wait returns on a non-zero exit.
type ExecHandle ¶
ExecHandle is a running exec. The caller reads Stdout to completion, then calls Wait to learn the exit code. Stderr is captured separately for logging.
type Mount ¶
type Mount struct {
Type MountType
Name string // named-volume name, empty for binds and tmpfs
Source string // host-side path, empty for tmpfs
Destination string // container-side path
ReadOnly bool
}
Mount is one filesystem mount attached to a container.
type MountType ¶
type MountType string
MountType distinguishes the kinds of mount Ballast cares about.
type PodmanRuntime ¶
type PodmanRuntime struct {
// contains filtered or unexported fields
}
PodmanRuntime is the Podman adapter for Runtime. Podman's REST API includes a Docker-compatible compat layer (documented against the Docker v1.40 API) on the same socket as its native libpod API, so PodmanRuntime talks to it with the exact request and mapping machinery DockerRuntime uses, in engine.go; the two adapters differ only in their default socket path and in how compose project/service identity is read off a container's labels.
The client is created lazily on first use and cached, so constructing a PodmanRuntime never touches the socket: nothing fails until a method that actually needs the daemon is called.
func NewPodman ¶
func NewPodman(socket string) *PodmanRuntime
NewPodman returns a Podman adapter bound to the given API socket path. An empty socket resolves to a sensible default: the rootless per-user socket derived from XDG_RUNTIME_DIR (or /run/user/<uid> when that is unset, matching systemd's own convention) for a non-root caller, and the rootful system-service socket for a root caller with no XDG_RUNTIME_DIR set.
func (PodmanRuntime) Close ¶
func (e PodmanRuntime) Close() error
Close releases the underlying client.
func (PodmanRuntime) Exec ¶
Exec runs a command inside a running container and returns a handle whose Stdout streams the command's standard output as it is produced, which matters because the caller pipes a live dump into restic --stdin rather than buffering it. Standard error is captured separately and folded into the error Wait returns on a non-zero exit.
type Runtime ¶
type Runtime interface {
// List returns every container the runtime knows about, running or not.
List(ctx context.Context) ([]Container, error)
// Inspect returns a single container by ID or name.
Inspect(ctx context.Context, id string) (Container, error)
// Watch streams lifecycle events until ctx is cancelled. The error channel
// carries a terminal error and is then closed alongside the event channel.
Watch(ctx context.Context) (<-chan Event, <-chan error)
// Exec runs a command inside a running container and returns a handle whose
// Stdout the caller reads (for stream backups it is piped straight into the
// engine's stdin) before calling Wait for the exit code.
Exec(ctx context.Context, id string, spec ExecSpec) (*ExecHandle, error)
// Stop stops a running container, waiting up to timeoutSeconds before a kill.
Stop(ctx context.Context, id string, timeoutSeconds int) error
// Start starts a stopped container.
Start(ctx context.Context, id string) error
// Close releases the underlying client.
Close() error
}
Runtime is a container runtime Ballast can drive. Implementations must be safe for concurrent use by multiple goroutines.