Documentation
¶
Index ¶
- func EnvFileSafe(env []string) bool
- func EnvFileSafeForCompose(env []string) bool
- func WriteEnvFile(path string, env []string) error
- func WriteEnvFileTo(w io.Writer, env []string) error
- func WriteEnvTempFile(env []string) (path string, cleanup func(), err error)
- type BuildOptions
- type ContainerConfig
- type ContainerDetails
- type ContainerState
- type Driver
- type ImageConfig
- type ImageDetails
- type ImageInfo
- type LogsOptions
- type PortBinding
- type RunOptions
- type VolumeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvFileSafe ¶ added in v0.10.0
EnvFileSafe reports whether all env entries can be represented in an env-file for `docker run/exec --env-file` / `podman run/exec --env-file`. That parser is literal: only a leading `#` starts a comment and the rest of the line is taken verbatim, so the only unrepresentable value is one containing a newline (which would break the line structure).
func EnvFileSafeForCompose ¶ added in v0.10.0
EnvFileSafeForCompose reports whether all env entries can be represented in a compose `env_file:`. Compose's env-file parser is richer than docker run's: it strips surrounding quotes, trims leading/trailing whitespace, treats a space before `#` as an inline comment, and interpolates unquoted/double-quoted values. Values containing any of those constructs would be silently mutated, so they must fall back to the inline `environment:` block instead.
func WriteEnvFile ¶ added in v0.10.0
WriteEnvFile writes KEY=VALUE lines to path with 0600 permissions. Values are written verbatim (no quoting or interpolation), matching the env-file format accepted by docker and podman.
func WriteEnvFileTo ¶ added in v0.10.0
WriteEnvFileTo writes KEY=VALUE lines to w, one per line, verbatim.
func WriteEnvTempFile ¶ added in v0.10.0
WriteEnvTempFile writes env to a 0600 temp file suitable for `--env-file` and returns its path plus a cleanup func that removes it. It returns ("", nil, nil) when env is empty or contains a value the env-file parser would mutate (a newline), so the caller can fall back to -e flags. When path != "" the caller MUST call cleanup (typically via defer).
Types ¶
type BuildOptions ¶
type BuildOptions struct {
PrebuildHash string
Image string
Dockerfile string
Context string
Args map[string]string
Target string
CacheFrom []string
Labels map[string]string // Image labels (e.g. crib.workspace=wsID)
Options []string // Extra CLI flags from build.options
Stdout io.Writer
Stderr io.Writer
}
BuildOptions holds parameters for building a container image.
type ContainerConfig ¶
ContainerConfig holds container configuration metadata.
type ContainerDetails ¶
type ContainerDetails struct {
ID string
Created string
State ContainerState
Config ContainerConfig
Ports []PortBinding
}
ContainerDetails describes a running or stopped container.
type ContainerState ¶
ContainerState holds the runtime state of a container.
func (ContainerState) IsRemoving ¶
func (s ContainerState) IsRemoving() bool
IsRemoving reports whether the container is in the process of being removed.
func (ContainerState) IsRunning ¶
func (s ContainerState) IsRunning() bool
IsRunning reports whether the container is in the running state.
type Driver ¶
type Driver interface {
// FindContainer locates a container by workspace ID.
// Returns nil if no container is found.
FindContainer(ctx context.Context, workspaceID string) (*ContainerDetails, error)
// RunContainer creates and starts a container with the given options.
// Returns the container name chosen by the driver (either the default
// crib-<ws-id> or a user override from runArgs --name).
RunContainer(ctx context.Context, workspaceID string, options *RunOptions) (string, error)
// StartContainer starts a stopped container.
StartContainer(ctx context.Context, workspaceID, containerID string) error
// StopContainer stops a running container.
StopContainer(ctx context.Context, workspaceID, containerID string) error
// RestartContainer restarts a running or stopped container.
RestartContainer(ctx context.Context, workspaceID, containerID string) error
// DeleteContainer removes a container.
DeleteContainer(ctx context.Context, workspaceID, containerID string) error
// ExecContainer runs a command inside a container with attached I/O.
// env is a list of KEY=VALUE pairs injected via -e flags.
// user overrides the exec user (e.g. "root"); pass "" to use the container default.
ExecContainer(ctx context.Context, workspaceID, containerID string, cmd []string, stdin io.Reader, stdout, stderr io.Writer, env []string, user string) error
// ContainerLogs returns the logs from a container.
// opts may be nil for default behavior (all logs, no follow).
ContainerLogs(ctx context.Context, workspaceID, containerID string, stdout, stderr io.Writer, opts *LogsOptions) error
// BuildImage builds a container image.
BuildImage(ctx context.Context, workspaceID string, options *BuildOptions) error
// InspectImage returns details about a container image.
InspectImage(ctx context.Context, imageName string) (*ImageDetails, error)
// TargetArchitecture returns the architecture of the container runtime (e.g. "amd64", "arm64").
TargetArchitecture(ctx context.Context) (string, error)
// ListContainers returns all containers with the crib.workspace label.
ListContainers(ctx context.Context) ([]ContainerDetails, error)
// CommitContainer creates an image from a container's changes.
// changes are passed as --change flags (e.g. "LABEL key=value").
CommitContainer(ctx context.Context, workspaceID, containerID, imageName string, changes []string) error
// RemoveImage removes a container image.
RemoveImage(ctx context.Context, imageName string) error
// ListImages returns images matching the given label filter.
// Use "crib.workspace" for all crib images, or "crib.workspace=wsID" for a specific workspace.
ListImages(ctx context.Context, label string) ([]ImageInfo, error)
// ListVolumes returns volumes whose names match the given filter prefix.
ListVolumes(ctx context.Context, nameFilter string) ([]VolumeInfo, error)
// RemoveVolume removes a named volume.
RemoveVolume(ctx context.Context, name string) error
}
Driver abstracts the container runtime (Docker or Podman).
type ImageConfig ¶
type ImageConfig struct {
User string
Env []string
Labels map[string]string
Entrypoint []string
Cmd []string
}
ImageConfig holds image configuration metadata.
type ImageDetails ¶
type ImageDetails struct {
ID string
Config ImageConfig
}
ImageDetails describes a container image.
type ImageInfo ¶ added in v0.7.0
type ImageInfo struct {
Reference string // repo:tag (e.g. "crib-myws:crib-abc123")
ID string // image ID
Size int64 // image size in bytes
WorkspaceID string // value of crib.workspace label
}
ImageInfo describes a crib-managed image discovered by label.
type LogsOptions ¶ added in v0.5.0
type LogsOptions struct {
Follow bool // stream logs as they are produced
Tail string // number of lines from the end ("all" or a number)
}
LogsOptions controls container log output.
type PortBinding ¶ added in v0.4.0
type PortBinding struct {
ContainerPort int // Port inside the container
HostPort int // Port on the host
HostIP string // Host bind address (e.g. "0.0.0.0")
Protocol string // "tcp" or "udp"
RawSpec string // Original spec when ports can't be represented as ints (e.g. ranges)
}
PortBinding describes a published port mapping.
type RunOptions ¶
type RunOptions struct {
Image string
User string
Entrypoint string
Cmd []string
Env []string
CapAdd []string
SecurityOpt []string
Labels map[string]string
Privileged bool
Init bool
WorkspaceMount config.Mount
Mounts []config.Mount
Ports []string // Publish specs (e.g. "8080:8080")
ExtraArgs []string // Raw CLI args passed through from runArgs
}
RunOptions holds parameters for creating and starting a container.
type VolumeInfo ¶ added in v0.5.0
VolumeInfo describes a named Docker/Podman volume.