Help us shape the future of Go! Take the 2026 Go Developer Survey

oci

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const LabelHome = "crib.home"

LabelHome is the container label key that records which CRIB_HOME (workspace store) created the container. Used by doctor to avoid deleting containers that belong to a different store (e.g. test isolation via CRIB_HOME).

View Source
const LabelWorkspace = "crib.workspace"

LabelWorkspace is the container label key used for workspace discovery.

Variables

This section is empty.

Functions

func ContainerName

func ContainerName(workspaceID string) string

ContainerName returns the container name for a workspace.

func ImageName

func ImageName(workspaceID, tag string) string

ImageName returns the image name for a workspace with the given tag.

func WorkspaceLabel

func WorkspaceLabel(workspaceID string) string

WorkspaceLabel returns the label filter string for finding workspace containers.

Types

type Helper

type Helper struct {
	// contains filtered or unexported fields
}

Helper wraps the docker/podman CLI binary for executing commands.

func NewHelper

func NewHelper(command string, logger *slog.Logger) *Helper

NewHelper creates a Helper that shells out to the given command (e.g. "docker" or "podman").

func (*Helper) Command

func (h *Helper) Command() string

Command returns the base command name (e.g. "docker" or "podman").

func (*Helper) Inspect

func (h *Helper) Inspect(ctx context.Context, ids []string, inspectType string, result any) error

Inspect runs `<cmd> inspect --type <inspectType>` on the given IDs and unmarshals the JSON result into the provided pointer.

func (*Helper) Output

func (h *Helper) Output(ctx context.Context, args ...string) ([]byte, error)

Output executes the command and returns captured stdout.

func (*Helper) Run

func (h *Helper) Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error

Run executes the command with the given args and attached I/O streams. If the command exits non-zero, the returned error includes captured stderr.

type OCIDriver

type OCIDriver struct {
	// contains filtered or unexported fields
}

OCIDriver implements driver.Driver using docker or podman CLI commands.

func NewOCIDriver

func NewOCIDriver(logger *slog.Logger) (*OCIDriver, error)

NewOCIDriver creates an OCIDriver by auto-detecting the container runtime.

func (*OCIDriver) BuildImage

func (d *OCIDriver) BuildImage(ctx context.Context, workspaceID string, opts *driver.BuildOptions) error

BuildImage builds a container image from a Dockerfile. For Docker, it tries `docker buildx build --load` first, falling back to `docker build`. For Podman, it uses `podman build` directly.

func (*OCIDriver) CommitContainer added in v0.5.0

func (d *OCIDriver) CommitContainer(ctx context.Context, _, containerID, imageName string, changes []string) error

CommitContainer creates an image from a container's changes. changes are passed as --change flags (e.g. "LABEL key=value").

func (*OCIDriver) ContainerLogs

func (d *OCIDriver) ContainerLogs(ctx context.Context, _, containerID string, stdout, stderr io.Writer, opts *driver.LogsOptions) error

ContainerLogs returns the logs from a container. opts may be nil for default behavior (all logs, no follow).

func (*OCIDriver) DeleteContainer

func (d *OCIDriver) DeleteContainer(ctx context.Context, _, containerID string) error

DeleteContainer removes a container forcefully with no grace period.

func (*OCIDriver) ExecContainer

func (d *OCIDriver) ExecContainer(ctx context.Context, _, containerID string, cmd []string, stdin io.Reader, stdout, stderr io.Writer, env []string, user string) error

ExecContainer runs a command inside a container with attached I/O. env is injected via an env file (--env-file) when safe, keeping values out of the process table; it falls back to -e flags for values the env-file format cannot represent (e.g. newlines). user overrides the exec user (e.g. "root"); empty string uses the container default.

func (*OCIDriver) FindContainer

func (d *OCIDriver) FindContainer(ctx context.Context, workspaceID string) (*driver.ContainerDetails, error)

FindContainer locates a container by workspace ID using label filtering. Returns nil if no container is found. Skips containers in "removing" state.

func (*OCIDriver) InspectImage

func (d *OCIDriver) InspectImage(ctx context.Context, imageName string) (*driver.ImageDetails, error)

InspectImage returns details about a container image.

func (*OCIDriver) ListContainers added in v0.5.0

func (d *OCIDriver) ListContainers(ctx context.Context) ([]driver.ContainerDetails, error)

ListContainers returns all containers with the crib.workspace label.

func (*OCIDriver) ListImages added in v0.7.0

func (d *OCIDriver) ListImages(ctx context.Context, label string) ([]driver.ImageInfo, error)

ListImages returns images matching the given label filter.

func (*OCIDriver) ListVolumes added in v0.5.0

func (d *OCIDriver) ListVolumes(ctx context.Context, nameFilter string) ([]driver.VolumeInfo, error)

ListVolumes returns volumes whose names start with nameFilter.

func (*OCIDriver) RemoveImage added in v0.5.0

func (d *OCIDriver) RemoveImage(ctx context.Context, imageName string) error

RemoveImage removes a container image.

func (*OCIDriver) RemoveVolume added in v0.5.0

func (d *OCIDriver) RemoveVolume(ctx context.Context, name string) error

RemoveVolume removes a named volume.

func (*OCIDriver) RestartContainer added in v0.2.0

func (d *OCIDriver) RestartContainer(ctx context.Context, _, containerID string) error

RestartContainer restarts a running or stopped container.

func (*OCIDriver) RunContainer

func (d *OCIDriver) RunContainer(ctx context.Context, workspaceID string, options *driver.RunOptions) (string, error)

RunContainer creates and starts a new container for the workspace. The workspace label is injected automatically. Returns the chosen container name (default crib-<ws-id> or the runArgs --name override).

func (*OCIDriver) Runtime

func (d *OCIDriver) Runtime() Runtime

Runtime returns the detected container runtime.

func (*OCIDriver) StartContainer

func (d *OCIDriver) StartContainer(ctx context.Context, _, containerID string) error

StartContainer starts a stopped container.

func (*OCIDriver) StopContainer

func (d *OCIDriver) StopContainer(ctx context.Context, _, containerID string) error

StopContainer stops a running container.

func (*OCIDriver) TargetArchitecture

func (d *OCIDriver) TargetArchitecture(ctx context.Context) (string, error)

TargetArchitecture returns the architecture of the container runtime host.

type Runtime

type Runtime int

Runtime identifies the container runtime.

const (
	RuntimeDocker Runtime = iota
	RuntimePodman
)

func (Runtime) String

func (r Runtime) String() string

String returns the runtime name.

Jump to

Keyboard shortcuts

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