container

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package container provides container lifecycle management for agents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentOpts

type AgentOpts struct {
	AgentID uuid.UUID
	Image   string            // Docker image to run (e.g., "my-agent:abc123")
	Env     map[string]string // Additional environment variables
}

AgentOpts configures an agent container.

type Container

type Container struct {
	ID       string // Docker container ID
	Name     string // Human-readable name
	Endpoint string // HTTP endpoint (e.g., "http://172.17.0.2:8080")
	Token    string // Bearer token for authenticating requests to this container
}

Container represents a running container.

type ContainerManager

type ContainerManager interface {
	// StartAgent ensures an agent container is running.
	// Returns the existing container if already running and healthy.
	StartAgent(ctx context.Context, opts AgentOpts) (*Container, error)

	// GetRunning returns the running container for an agent without starting
	// one if absent. Returns (nil, nil) when no container is up. Used by
	// out-of-band signals (e.g. /refresh push) where booting a container
	// just to notify it would defeat the purpose.
	GetRunning(ctx context.Context, agentID uuid.UUID) (*Container, error)

	// StopAgent stops a specific agent container.
	StopAgent(ctx context.Context, id string) error

	// StartToolserver starts an ephemeral toolserver container for build operations.
	// Returns the container with a WebSocket endpoint for tool execution.
	StartToolserver(ctx context.Context, opts ToolserverOpts) (*Container, error)

	// StopToolserver stops and removes an ephemeral toolserver container.
	StopToolserver(ctx context.Context, name string) error

	// KillToolserver force-kills (SIGKILL) and removes an ephemeral
	// toolserver container without waiting for graceful shutdown. Used
	// on the build-cancel path so an in-flight tool stops emitting logs
	// the moment cancel hits, instead of after the 5s graceful timeout.
	KillToolserver(ctx context.Context, name string) error

	// RemoveImage removes a Docker image by reference (e.g., "agentID:hash").
	RemoveImage(ctx context.Context, imageRef string) error
}

ContainerManager manages the lifecycle of agent containers.

type DockerManager

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

DockerManager implements ContainerManager using the Docker API.

func NewDockerManager

func NewDockerManager(cfg *config.Config, logger *zap.Logger) *DockerManager

NewDockerManager creates a Docker-based ContainerManager.

func (*DockerManager) Close

func (m *DockerManager) Close()

Close stops the idle reaper and closes the Docker client.

func (*DockerManager) GetRunning

func (m *DockerManager) GetRunning(ctx context.Context, agentID uuid.UUID) (*Container, error)

GetRunning implements ContainerManager. Returns (nil, nil) when no container exists for the agent — caller is expected to treat that as "nothing to do" rather than an error. Repopulates the in-memory cache when it finds a running container Airlock didn't previously know about (typical after an Airlock restart).

func (*DockerManager) KillToolserver added in v0.1.6

func (m *DockerManager) KillToolserver(ctx context.Context, name string) error

KillToolserver force-removes an ephemeral toolserver container without waiting for graceful shutdown. RemoveOptions{Force: true} sends SIGKILL and removes in one call, so any in-flight tool execution dies immediately. Used by the build-cancellation path: graceful shutdown is 5+ seconds of dead air during which the toolserver keeps running its in-flight tool (e.g. a long `bash go build`) and emitting log lines — which makes the cancel feel like it didn't take. Idempotent: returns nil/NotFound if the container is already gone.

func (*DockerManager) PruneAgentResources

func (m *DockerManager) PruneAgentResources(ctx context.Context, validAgents map[string]string)

PruneAgentResources removes Docker containers and images for agents that no longer exist in the database, and removes stale image tags for active agents (keeping only the current image_ref).

validAgents maps agent UUID string → current image_ref (e.g., "uuid:hash"). Any airlock-agent-* container or UUID-tagged image not matching this set is removed.

func (*DockerManager) RemoveImage

func (m *DockerManager) RemoveImage(ctx context.Context, imageRef string) error

RemoveImage removes a Docker image by reference.

func (*DockerManager) StartAgent

func (m *DockerManager) StartAgent(ctx context.Context, opts AgentOpts) (*Container, error)

StartAgent implements ContainerManager.

func (*DockerManager) StartToolserver

func (m *DockerManager) StartToolserver(ctx context.Context, opts ToolserverOpts) (*Container, error)

StartToolserver starts an ephemeral toolserver container for build operations. The container runs the toolserver binary with the workspace mounted. Returns the container with a WebSocket endpoint for remote tool execution.

func (*DockerManager) StopAgent

func (m *DockerManager) StopAgent(ctx context.Context, id string) error

StopAgent implements ContainerManager.

func (*DockerManager) StopToolserver

func (m *DockerManager) StopToolserver(ctx context.Context, name string) error

StopToolserver stops and removes an ephemeral toolserver container.

type ToolserverOpts

type ToolserverOpts struct {
	Image   string        // toolserver image (e.g., "agent-builder:v1.0.0")
	Mounts  []mount.Mount // workspace bind mounts
	WorkDir string        // -space-dir value inside the container
	Env     []string      // additional environment variables
}

ToolserverOpts configures an ephemeral toolserver container for build operations.

Jump to

Keyboard shortcuts

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