docker

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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
}

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) ([]types.Container, 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) (types.ContainerJSON, error)

	// Exec operations for session management
	ContainerExecCreate(ctx context.Context, containerID string, options types.ExecConfig) (types.IDResponse, error)
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) 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 types.ImagePullOptions) (io.ReadCloser, 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

type PortMapping struct {
	HostPort      int
	ContainerPort int
}

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

func NewService() (*Service, error)

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

func (s *Service) AttachInteractiveSession(ctx context.Context, containerID string) error

AttachInteractiveSession attaches to a running container with enhanced TTY support

func (*Service) CheckHealth

func (s *Service) CheckHealth(ctx context.Context) error

CheckHealth verifies Docker daemon is accessible and running

func (*Service) Close

func (s *Service) Close() error

Close closes the Docker client connection

func (*Service) ContainerDiff

func (s *Service) ContainerDiff(ctx context.Context, containerID string) ([]FileChange, error)

ContainerDiff returns filesystem changes made to a container

func (*Service) ContainerExists

func (s *Service) ContainerExists(ctx context.Context, name string) (ContainerInfo, error)

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) 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) 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

func (s *Service) RemoveContainer(ctx context.Context, containerID string) error

RemoveContainer removes a container (must be stopped first)

func (*Service) ResizeTerminal

func (s *Service) ResizeTerminal(ctx context.Context, containerID string, size TTYSize) error

ResizeTerminal provides external interface for terminal resizing

func (*Service) StartContainer

func (s *Service) StartContainer(ctx context.Context, containerID string) error

StartContainer starts a stopped container

func (*Service) StopContainer

func (s *Service) StopContainer(ctx context.Context, containerID string) error

StopContainer stops a running container

type TTYSize

type TTYSize struct {
	Rows uint16
	Cols uint16
}

TTYSize represents terminal dimensions

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

Jump to

Keyboard shortcuts

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