container

package
v0.178.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const InferNetworkPrefix = "infer-network"

InferNetworkPrefix is the prefix for session-specific Docker networks

Variables

This section is empty.

Functions

func RunPullCommand

func RunPullCommand(ctx context.Context, binary, image string, progress func(done, total int)) error

RunPullCommand streams `<binary> pull <image>` output, reporting layer progress via the optional progress callback.

Types

type ContainerInfo

type ContainerInfo struct {
	ID   string
	Name string
}

ContainerInfo represents basic container information

type ContainerRuntime

type ContainerRuntime interface {
	// Network operations
	GetNetworkName() string
	EnsureNetwork(ctx context.Context) error
	CleanupNetwork(ctx context.Context) error

	// Container lifecycle operations
	ContainerExists(containerIDOrName string) bool
	RunContainer(ctx context.Context, opts RunContainerOptions) (containerID string, err error)
	StopContainer(ctx context.Context, containerIDOrName string) error

	// Image operations. The optional progress callback receives layer counts
	// as the pull advances.
	PullImage(ctx context.Context, image string, progress func(done, total int)) error

	// Container inspection
	GetContainerHealth(ctx context.Context, containerIDOrName string) (HealthStatus, error)
	ListRunningContainers(ctx context.Context, nameFilter string) ([]ContainerInfo, error)
}

ContainerRuntime defines the interface for container runtime operations This abstraction allows support for Docker, Podman, or any other container runtime

func NewContainerRuntime

func NewContainerRuntime(sessionID convdomain.SessionID, runtimeType RuntimeType) (ContainerRuntime, error)

NewContainerRuntime creates a container runtime based on the configured type If runtimeType is empty, returns nil to allow binary mode fallback

func NewDockerRuntime

func NewDockerRuntime(sessionID convdomain.SessionID) ContainerRuntime

NewDockerRuntime creates a new Docker runtime manager

func NewPodmanRuntime

func NewPodmanRuntime(sessionID convdomain.SessionID) ContainerRuntime

NewPodmanRuntime creates a new Podman runtime manager

type DockerRuntime

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

DockerRuntime implements ContainerRuntime interface for Docker

func (*DockerRuntime) CleanupNetwork

func (dr *DockerRuntime) CleanupNetwork(ctx context.Context) error

CleanupNetwork best-effort removes the shared network. Because the network is shared across sessions it may still be in use by another session's containers, in which case removal is refused and we leave it in place (keeping networkCreated set so a later call retries once the network frees up). It is never an error to fail here - shutdown must not block.

func (*DockerRuntime) ContainerExists

func (dr *DockerRuntime) ContainerExists(containerIDOrName string) bool

ContainerExists checks if a Docker container exists by ID or name (running or stopped)

func (*DockerRuntime) EnsureNetwork

func (dr *DockerRuntime) EnsureNetwork(ctx context.Context) error

EnsureNetwork creates the shared Docker network if it doesn't exist. The network is reused across sessions, so at most one ever exists. If creation fails because the IPAM address pools are exhausted (leaked networks from prior sessions), it prunes those and retries once.

func (*DockerRuntime) GetContainerHealth

func (dr *DockerRuntime) GetContainerHealth(ctx context.Context, containerIDOrName string) (HealthStatus, error)

GetContainerHealth returns the health status of a container

func (*DockerRuntime) GetNetworkName

func (dr *DockerRuntime) GetNetworkName() string

GetNetworkName returns the shared infer network name

func (*DockerRuntime) ListRunningContainers

func (dr *DockerRuntime) ListRunningContainers(ctx context.Context, nameFilter string) ([]ContainerInfo, error)

ListRunningContainers lists all running containers matching the name filter

func (*DockerRuntime) PullImage

func (dr *DockerRuntime) PullImage(ctx context.Context, image string, progress func(done, total int)) error

PullImage pulls a Docker image, reporting layer progress via the optional callback

func (*DockerRuntime) RunContainer

func (dr *DockerRuntime) RunContainer(ctx context.Context, opts RunContainerOptions) (string, error)

RunContainer runs a Docker container with the given options

func (*DockerRuntime) StopContainer

func (dr *DockerRuntime) StopContainer(ctx context.Context, containerIDOrName string) error

StopContainer stops a Docker container

type HealthCheckConfig

type HealthCheckConfig struct {
	Interval    string // e.g., "10s"
	Timeout     string // e.g., "5s"
	Retries     int
	StartPeriod string // e.g., "10s"
}

HealthCheckConfig defines container health check configuration

type HealthStatus

type HealthStatus string

HealthStatus represents the health status of a container

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
	HealthStatusStarting  HealthStatus = "starting"
	HealthStatusNone      HealthStatus = "none"
)

type PodmanRuntime

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

PodmanRuntime implements ContainerRuntime interface for Podman

func (*PodmanRuntime) CleanupNetwork

func (pr *PodmanRuntime) CleanupNetwork(ctx context.Context) error

CleanupNetwork best-effort removes the shared network. Because the network is shared across sessions it may still be in use by another session's containers, in which case removal is refused and we leave it in place (keeping networkCreated set so a later call retries once the network frees up). It is never an error to fail here - shutdown must not block.

func (*PodmanRuntime) ContainerExists

func (pr *PodmanRuntime) ContainerExists(containerIDOrName string) bool

ContainerExists checks if a Podman container exists by ID or name (running or stopped)

func (*PodmanRuntime) EnsureNetwork

func (pr *PodmanRuntime) EnsureNetwork(ctx context.Context) error

EnsureNetwork creates the shared Podman network if it doesn't exist. The network is reused across sessions, so at most one ever exists. If creation fails because the IPAM address pools are exhausted (leaked networks from prior sessions), it prunes those and retries once.

func (*PodmanRuntime) GetContainerHealth

func (pr *PodmanRuntime) GetContainerHealth(ctx context.Context, containerIDOrName string) (HealthStatus, error)

GetContainerHealth returns the health status of a container

func (*PodmanRuntime) GetNetworkName

func (pr *PodmanRuntime) GetNetworkName() string

GetNetworkName returns the shared infer network name

func (*PodmanRuntime) ListRunningContainers

func (pr *PodmanRuntime) ListRunningContainers(ctx context.Context, nameFilter string) ([]ContainerInfo, error)

ListRunningContainers lists all running containers matching the name filter

func (*PodmanRuntime) PullImage

func (pr *PodmanRuntime) PullImage(ctx context.Context, image string, progress func(done, total int)) error

PullImage pulls a Podman image, reporting layer progress via the optional callback

func (*PodmanRuntime) RunContainer

func (pr *PodmanRuntime) RunContainer(ctx context.Context, opts RunContainerOptions) (string, error)

RunContainer runs a Podman container with the given options

func (*PodmanRuntime) StopContainer

func (pr *PodmanRuntime) StopContainer(ctx context.Context, containerIDOrName string) error

StopContainer stops a Podman container

type RunContainerOptions

type RunContainerOptions struct {
	Name         string
	Image        string
	Network      string
	Ports        []string // Format: "host:container" or "host:container/protocol"
	Environment  map[string]string
	Volumes      []string // Format: "host:container" or "host:container:mode"
	Entrypoint   []string
	Command      []string
	Args         []string
	HealthCmd    string
	HealthConfig *HealthCheckConfig
	RemoveOnExit bool
	Detached     bool
	EnvFile      string // Optional .env file path
}

RunContainerOptions contains all options for running a container

type RuntimeType

type RuntimeType string

RuntimeType represents the type of container runtime

const (
	RuntimeTypeDocker RuntimeType = "docker"
	RuntimeTypePodman RuntimeType = "podman"
)

Jump to

Keyboard shortcuts

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