docker

package
v0.0.0-...-b0537cc Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package docker provides Docker client functionality for managing containers.

Index

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 NewClient

func NewClient() (*Client, error)

NewClient creates a new Docker client wrapper.

func (*Client) Close

func (c *Client) Close() error

Close closes the Docker client connection.

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

func (c *Client) IsContainerRunning(ctx context.Context, containerID string) (bool, error)

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

func (c *Client) Ping(ctx context.Context) error

Ping checks if the Docker daemon is accessible.

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, imageName string) error

PullImage pulls a Docker image if it doesn't exist locally.

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, containerID string) error

RemoveContainer removes a container by ID.

func (*Client) StartContainer

func (c *Client) StartContainer(ctx context.Context, containerID string) error

StartContainer starts a container by ID.

func (*Client) StopContainer

func (c *Client) StopContainer(ctx context.Context, containerID string) error

StopContainer stops 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

func NewManager(startPort, endPort int) (*Manager, error)

NewManager creates a new Docker manager with the specified port range.

func (*Manager) AllocatePort

func (m *Manager) AllocatePort(ctx context.Context) (int, error)

AllocatePort allocates an available port.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the Docker manager and releases resources.

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

func (m *Manager) GetClient() *Client

GetClient returns the underlying Docker client.

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

func (m *Manager) Ping(ctx context.Context) error

Ping checks if the Docker daemon is accessible.

func (*Manager) PullImage

func (m *Manager) PullImage(ctx context.Context, image string) error

PullImage pulls a Docker image.

func (*Manager) ReleasePort

func (m *Manager) ReleasePort(port int)

ReleasePort releases a previously allocated port.

func (*Manager) RemoveContainer

func (m *Manager) RemoveContainer(ctx context.Context, containerID string) error

RemoveContainer removes a container.

func (*Manager) StartContainer

func (m *Manager) StartContainer(ctx context.Context, containerID string) error

StartContainer starts a container.

func (*Manager) StopContainer

func (m *Manager) StopContainer(ctx context.Context, containerID string) error

StopContainer stops 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.

Jump to

Keyboard shortcuts

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