Documentation
¶
Overview ¶
Package docker provides Docker client functionality for managing containers.
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) ContainerLogs(ctx context.Context, containerID string, options container.LogsOptions) (string, error)
- func (c *Client) CreateContainer(ctx context.Context, config *container.Config, ...) (string, error)
- func (c *Client) InspectContainer(ctx context.Context, containerID string) (container.InspectResponse, error)
- func (c *Client) IsContainerRunning(ctx context.Context, containerID string) (bool, error)
- func (c *Client) ListContainers(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PullImage(ctx context.Context, imageName string) error
- func (c *Client) RemoveContainer(ctx context.Context, containerID string) error
- func (c *Client) StartContainer(ctx context.Context, containerID string) error
- func (c *Client) StopContainer(ctx context.Context, containerID string) error
- type GenericContainerConfig
- type HealthCheck
- type HealthChecker
- func (hc *HealthChecker) CheckContainerHealth(ctx context.Context, containerID string) (*HealthCheck, error)
- func (hc *HealthChecker) CheckPostgreSQLConnection(ctx context.Context, dsn string) (*HealthCheck, error)
- func (hc *HealthChecker) CheckPostgreSQLInstance(ctx context.Context, containerID, dsn string) (*HealthCheck, error)
- func (hc *HealthChecker) WaitForHealthy(ctx context.Context, containerID, dsn string, timeout time.Duration) error
- type HealthStatus
- type Manager
- func (m *Manager) AllocatePort(ctx context.Context) (int, error)
- func (m *Manager) Close() error
- func (m *Manager) ContainerLogs(ctx context.Context, containerID string, options container.LogsOptions) (string, error)
- func (m *Manager) CreateGenericContainer(ctx context.Context, config GenericContainerConfig) (string, error)
- func (m *Manager) GetClient() *Client
- func (m *Manager) InspectContainer(ctx context.Context, containerID string) (*container.InspectResponse, error)
- func (m *Manager) ListContainersByType(ctx context.Context, dbType types.DatabaseType) ([]container.Summary, error)
- func (m *Manager) Ping(ctx context.Context) error
- func (m *Manager) PullImage(ctx context.Context, image string) error
- func (m *Manager) ReleasePort(port int)
- func (m *Manager) RemoveContainer(ctx context.Context, containerID string) error
- func (m *Manager) StartContainer(ctx context.Context, containerID string) error
- func (m *Manager) StopContainer(ctx context.Context, containerID string) error
- type PortManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Docker client with additional functionality.
func (*Client) ContainerLogs ¶
func (c *Client) ContainerLogs(ctx context.Context, containerID string, options container.LogsOptions) (string, error)
ContainerLogs retrieves logs from a container.
func (*Client) CreateContainer ¶
func (c *Client) CreateContainer(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, containerName string) (string, error)
CreateContainer creates a new container with the given configuration.
func (*Client) InspectContainer ¶
func (c *Client) InspectContainer(ctx context.Context, containerID string) (container.InspectResponse, error)
InspectContainer returns detailed information about a container.
func (*Client) IsContainerRunning ¶
IsContainerRunning checks if a container is currently running.
func (*Client) ListContainers ¶
func (c *Client) ListContainers(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
ListContainers lists containers with optional filters.
func (*Client) RemoveContainer ¶
RemoveContainer removes a container by ID.
func (*Client) StartContainer ¶
StartContainer starts a container by ID.
type GenericContainerConfig ¶
type GenericContainerConfig struct {
Image string
ContainerName string
Environment []string
Port int
ContainerPort string
HealthCheck []string
Labels map[string]string
}
GenericContainerConfig holds configuration for creating a generic database container.
type HealthCheck ¶
type HealthCheck struct {
Status HealthStatus `json:"status"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
Duration time.Duration `json:"duration"`
}
HealthCheck represents a health check result.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker provides health checking functionality for PostgreSQL containers.
func NewHealthChecker ¶
func NewHealthChecker(client *Client) *HealthChecker
NewHealthChecker creates a new health checker.
func (*HealthChecker) CheckContainerHealth ¶
func (hc *HealthChecker) CheckContainerHealth(ctx context.Context, containerID string) (*HealthCheck, error)
CheckContainerHealth checks the health of a container using Docker's health check.
func (*HealthChecker) CheckPostgreSQLConnection ¶
func (hc *HealthChecker) CheckPostgreSQLConnection(ctx context.Context, dsn string) (*HealthCheck, error)
CheckPostgreSQLConnection checks if PostgreSQL is accessible by attempting a connection.
func (*HealthChecker) CheckPostgreSQLInstance ¶
func (hc *HealthChecker) CheckPostgreSQLInstance(ctx context.Context, containerID, dsn string) (*HealthCheck, error)
CheckPostgreSQLInstance performs a comprehensive health check on a PostgreSQL instance.
func (*HealthChecker) WaitForHealthy ¶
func (hc *HealthChecker) WaitForHealthy(ctx context.Context, containerID, dsn string, timeout time.Duration) error
WaitForHealthy waits for a PostgreSQL instance to become healthy.
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the health status of a container or service.
const ( // HealthStatusHealthy indicates the service is healthy and ready. HealthStatusHealthy HealthStatus = "healthy" // HealthStatusUnhealthy indicates the service is not working properly. HealthStatusUnhealthy HealthStatus = "unhealthy" // HealthStatusStarting indicates the service is starting up. HealthStatusStarting HealthStatus = "starting" // HealthStatusStopped indicates the service is stopped. HealthStatusStopped HealthStatus = "stopped" // HealthStatusUnknown indicates the health status cannot be determined. HealthStatusUnknown HealthStatus = "unknown" )
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager combines Docker client and port management functionality.
func NewManager ¶
NewManager creates a new Docker manager with the specified port range.
func (*Manager) AllocatePort ¶
AllocatePort allocates an available port.
func (*Manager) ContainerLogs ¶
func (m *Manager) ContainerLogs(ctx context.Context, containerID string, options container.LogsOptions) (string, error)
ContainerLogs gets container logs.
func (*Manager) CreateGenericContainer ¶
func (m *Manager) CreateGenericContainer(ctx context.Context, config GenericContainerConfig) (string, error)
CreateGenericContainer creates a generic database container.
func (*Manager) InspectContainer ¶
func (m *Manager) InspectContainer(ctx context.Context, containerID string) (*container.InspectResponse, error)
InspectContainer inspects a container.
func (*Manager) ListContainersByType ¶
func (m *Manager) ListContainersByType(ctx context.Context, dbType types.DatabaseType) ([]container.Summary, error)
ListContainersByType lists all containers of a specific database type.
func (*Manager) ReleasePort ¶
ReleasePort releases a previously allocated port.
func (*Manager) RemoveContainer ¶
RemoveContainer removes a container.
func (*Manager) StartContainer ¶
StartContainer starts a container.
type PortManager ¶
type PortManager struct {
// contains filtered or unexported fields
}
PortManager manages port allocation for containers.
func NewPortManager ¶
func NewPortManager(startPort, endPort int) *PortManager
NewPortManager creates a new port manager with the specified port range.
func (*PortManager) AllocatePort ¶
func (pm *PortManager) AllocatePort(_ context.Context) (int, error)
AllocatePort allocates an available port in the configured range.
func (*PortManager) GetAllocatedPorts ¶
func (pm *PortManager) GetAllocatedPorts() []int
GetAllocatedPorts returns a slice of all currently allocated ports.
func (*PortManager) IsPortAllocated ¶
func (pm *PortManager) IsPortAllocated(port int) bool
IsPortAllocated checks if a port is currently allocated.
func (*PortManager) ReleasePort ¶
func (pm *PortManager) ReleasePort(port int)
ReleasePort releases a previously allocated port.