Documentation
¶
Index ¶
- type BuildSpec
- type ContainerInfo
- type ContainerSpec
- type ContainerStatus
- type DockerClient
- type FileChange
- type PortMapping
- type Service
- func (s *Service) AttachInteractiveSession(ctx context.Context, containerID string) error
- func (s *Service) BuildImage(ctx context.Context, spec BuildSpec, forceRebuild bool) error
- func (s *Service) CheckHealth(ctx context.Context) error
- func (s *Service) Close() error
- func (s *Service) ContainerDiff(ctx context.Context, containerID string) ([]FileChange, error)
- func (s *Service) ContainerExists(ctx context.Context, name string) (ContainerInfo, error)
- func (s *Service) CreateContainer(ctx context.Context, spec *ContainerSpec) (ContainerInfo, error)
- func (s *Service) ExecuteInteractiveCommand(ctx context.Context, containerID string, command []string) error
- func (s *Service) ExecutePostCreateCommand(ctx context.Context, containerID string, postCreateCommand interface{}) error
- func (s *Service) FindProjectContainer(ctx context.Context, account, projectPath, projectHash string) (*ContainerInfo, error)
- func (s *Service) GetClient() DockerClient
- func (s *Service) ImageExists(ctx context.Context, imageName string) (bool, error)
- func (s *Service) ListContainersByLabel(ctx context.Context, labelKey, labelValue string) ([]ContainerInfo, error)
- func (s *Service) ListReactorContainers(ctx context.Context) ([]ContainerInfo, error)
- func (s *Service) ProvisionContainer(ctx context.Context, spec *ContainerSpec) (ContainerInfo, error)
- func (s *Service) ProvisionContainerWithCleanup(ctx context.Context, spec *ContainerSpec, forceCleanup bool) (ContainerInfo, error)
- func (s *Service) RemoveContainer(ctx context.Context, containerID string) error
- func (s *Service) ResizeTerminal(ctx context.Context, containerID string, size TTYSize) error
- func (s *Service) StartContainer(ctx context.Context, containerID string) error
- func (s *Service) StopContainer(ctx context.Context, containerID string) error
- type TTYSize
- type TerminalState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildSpec ¶ added in v1.1.0
type BuildSpec struct {
Dockerfile string // Path to Dockerfile relative to context
Context string // Path to build context directory
ImageName string // Name to tag the built image with
}
BuildSpec defines the specification for building a Docker image
type ContainerInfo ¶
type ContainerInfo struct {
ID string
Name string
Status ContainerStatus
Image string
}
ContainerInfo holds information about a container
type ContainerSpec ¶
type ContainerSpec struct {
Name string
Image string
Command []string
WorkDir string
User string
Environment []string
Mounts []string // In "source:target:mode" format
PortMappings []PortMapping // Port forwarding configurations
NetworkMode string
Labels map[string]string // Docker labels for container identification
}
type ContainerStatus ¶
type ContainerStatus string
ContainerStatus represents the status of a container
const ( StatusRunning ContainerStatus = "running" StatusStopped ContainerStatus = "stopped" StatusNotFound ContainerStatus = "not_found" )
type DockerClient ¶
type DockerClient interface {
// Health and connection management
Ping(ctx context.Context) (types.Ping, error)
Close() error
// Core container lifecycle operations - CRITICAL PATH
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error
ContainerStop(ctx context.Context, containerID string, options container.StopOptions) error
ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error
// Session and interaction operations
ContainerAttach(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error)
ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
// Exec operations for session management
ContainerExecCreate(ctx context.Context, containerID string, options container.ExecOptions) (container.ExecCreateResponse, error)
ContainerExecAttach(ctx context.Context, execID string, config container.ExecStartOptions) (types.HijackedResponse, error)
ContainerExecStart(ctx context.Context, execID string, config container.ExecStartOptions) error
ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)
// Additional operations for discovery and debugging
ContainerDiff(ctx context.Context, containerID string) ([]container.FilesystemChange, error)
ContainerKill(ctx context.Context, containerID string, signal string) error
ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
ContainerResize(ctx context.Context, containerID string, options container.ResizeOptions) error
// Image management
ImagePull(ctx context.Context, refStr string, options image.PullOptions) (io.ReadCloser, error)
ImageBuild(ctx context.Context, buildContext io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error)
ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
}
DockerClient defines the interface for Docker API operations needed by our Service. This interface allows us to mock the Docker client in unit tests while using the real Docker client in production.
The interface is focused on the critical path operations needed for container recovery.
type FileChange ¶
type FileChange struct {
Kind string // A (Added), D (Deleted), C (Changed)
Path string // Path to the changed file
}
FileChange represents a filesystem change in a container
type PortMapping ¶
ContainerSpec defines the specification for creating a container PortMapping represents a port forwarding configuration
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages Docker daemon interactions
func NewService ¶
NewService creates a new Docker service with a real Docker client
func NewServiceWithClient ¶
func NewServiceWithClient(client DockerClient) *Service
NewServiceWithClient creates a new Docker service with the provided client. This constructor is primarily used for testing with mock clients.
func (*Service) AttachInteractiveSession ¶
AttachInteractiveSession attaches to a running container with enhanced TTY support
func (*Service) BuildImage ¶ added in v1.1.0
BuildImage builds a Docker image from the given BuildSpec It checks if the image already exists and skips building if found, unless forceRebuild is true
func (*Service) CheckHealth ¶
CheckHealth verifies Docker daemon is accessible and running
func (*Service) ContainerDiff ¶
ContainerDiff returns filesystem changes made to a container
func (*Service) ContainerExists ¶
ContainerExists checks if a container with the given name exists
func (*Service) CreateContainer ¶
func (s *Service) CreateContainer(ctx context.Context, spec *ContainerSpec) (ContainerInfo, error)
CreateContainer creates a new container with the given specifications
func (*Service) ExecuteInteractiveCommand ¶ added in v1.1.0
func (s *Service) ExecuteInteractiveCommand(ctx context.Context, containerID string, command []string) error
ExecuteInteractiveCommand runs a command interactively in the specified container
func (*Service) ExecutePostCreateCommand ¶ added in v1.1.0
func (s *Service) ExecutePostCreateCommand(ctx context.Context, containerID string, postCreateCommand interface{}) error
ExecutePostCreateCommand runs the postCreateCommand in the specified container postCreateCommand can be either a string or []string (array of strings)
func (*Service) FindProjectContainer ¶
func (s *Service) FindProjectContainer(ctx context.Context, account, projectPath, projectHash string) (*ContainerInfo, error)
FindProjectContainer finds a container for a specific project path
func (*Service) GetClient ¶ added in v1.1.0
func (s *Service) GetClient() DockerClient
GetClient returns the underlying Docker client for direct API access
func (*Service) ImageExists ¶ added in v1.1.0
ImageExists checks if an image with the given name/tag exists locally
func (*Service) ListContainersByLabel ¶ added in v1.1.0
func (s *Service) ListContainersByLabel(ctx context.Context, labelKey, labelValue string) ([]ContainerInfo, error)
ListContainersByLabel returns all containers that have the specified label
func (*Service) ListReactorContainers ¶
func (s *Service) ListReactorContainers(ctx context.Context) ([]ContainerInfo, error)
ListReactorContainers returns all containers that match the reactor naming pattern
func (*Service) ProvisionContainer ¶
func (s *Service) ProvisionContainer(ctx context.Context, spec *ContainerSpec) (ContainerInfo, error)
ProvisionContainer implements the three-phase container recovery strategy: 1. Check for running container with deterministic name 2. Check for stopped container and restart it 3. Create new container only if needed For discovery containers, always removes existing containers to ensure clean environment
func (*Service) ProvisionContainerWithCleanup ¶
func (s *Service) ProvisionContainerWithCleanup(ctx context.Context, spec *ContainerSpec, forceCleanup bool) (ContainerInfo, error)
ProvisionContainerWithCleanup allows specifying whether to always clean up existing containers
func (*Service) RemoveContainer ¶
RemoveContainer removes a container (must be stopped first)
func (*Service) ResizeTerminal ¶
ResizeTerminal provides external interface for terminal resizing
func (*Service) StartContainer ¶
StartContainer starts a stopped container
type TerminalState ¶
type TerminalState struct {
OriginalState *term.State
RawModeSet bool
Size TTYSize
SignalChan chan os.Signal
ResizeChan chan TTYSize
// contains filtered or unexported fields
}
TerminalState manages terminal state and cleanup
func NewTerminalState ¶
func NewTerminalState() *TerminalState
NewTerminalState creates a new terminal state manager
func (*TerminalState) Cleanup ¶
func (ts *TerminalState) Cleanup() error
Cleanup restores terminal state
func (*TerminalState) GetTerminalSize ¶
func (ts *TerminalState) GetTerminalSize() (TTYSize, error)
GetTerminalSize returns current terminal dimensions
func (*TerminalState) Setup ¶
func (ts *TerminalState) Setup() error
Setup configures terminal for interactive session
func (*TerminalState) StartSignalHandling ¶
func (ts *TerminalState) StartSignalHandling()
StartSignalHandling begins signal forwarding to container