Documentation
¶
Overview ¶
Package compose provides high-level Docker Compose integration for ContainerDB. It allows generating compose files from existing containerdb configurations and running databases via docker-compose.
Index ¶
- Variables
- func EnsureDocker() error
- func EnsureDockerCompose() error
- func ParseExistingServices(path string) (map[string]ServiceConfig, error)
- func TemplateMySQL() string
- func TemplateMySQLPostgres() string
- func TemplatePostgres() string
- func WriteTemplate(path, template string) error
- type ComposeFile
- type ComposeVersion
- type HealthCheck
- type Runner
- func (r *Runner) DetectVersion() error
- func (r *Runner) Down(ctx context.Context, dir string) error
- func (r *Runner) DownWithVolumes(ctx context.Context, dir string) error
- func (r *Runner) GenerateFile(services map[string]Service, dir string) error
- func (r *Runner) GenerateFileTo(services map[string]Service, path string) error
- func (r *Runner) GetVersion() ComposeVersion
- func (r *Runner) Logs(ctx context.Context, dir string, service string) (string, error)
- func (r *Runner) Ps(ctx context.Context, dir string) (string, error)
- func (r *Runner) SetVersion(v ComposeVersion)
- func (r *Runner) Status(ctx context.Context, dir string) (string, error)
- func (r *Runner) Up(ctx context.Context, dir string) error
- func (r *Runner) UpWithWait(ctx context.Context, dir string) error
- type Service
- func GenerateMySQLService(name string, cfg *config.MySQLConfig) Service
- func GenerateMySQLServiceWithHealthCheck(name string, cfg *config.MySQLConfig) Service
- func GeneratePostgresService(name string, cfg *config.PostgresConfig) Service
- func GeneratePostgresServiceWithHealthCheck(name string, cfg *config.PostgresConfig) Service
- type ServiceConfig
Constants ¶
This section is empty.
Variables ¶
var ( // BuildComposeFile creates a complete Docker Compose file from services. BuildComposeFile = internalsvc.BuildComposeFile // Parse reads and parses a Docker Compose file from the given path. Parse = internalsvc.Parse // ParseFromString parses a Docker Compose file from a string. ParseFromString = internalsvc.ParseFromString // DetectComposeVersion detects whether docker compose v2 or v1 is available. DetectComposeVersion = internalsvc.DetectComposeVersion )
Re-export functions from internal/compose for public API use.
Functions ¶
func EnsureDockerCompose ¶
func EnsureDockerCompose() error
EnsureDockerCompose checks if docker compose is available.
func ParseExistingServices ¶
func ParseExistingServices(path string) (map[string]ServiceConfig, error)
ParseExistingServices reads an existing compose file and extracts service configs.
func TemplateMySQL ¶
func TemplateMySQL() string
TemplateMySQL generates a docker-compose.yml template for MySQL.
func TemplateMySQLPostgres ¶
func TemplateMySQLPostgres() string
TemplateMySQLPostgres generates a docker-compose.yml template with both MySQL and PostgreSQL.
func TemplatePostgres ¶
func TemplatePostgres() string
TemplatePostgres generates a docker-compose.yml template for PostgreSQL.
func WriteTemplate ¶
WriteTemplate writes a compose template to a file.
Types ¶
type ComposeFile ¶
type ComposeFile = internalsvc.ComposeFile
ComposeFile represents a Docker Compose file structure.
func ParseExisting ¶
func ParseExisting(path string) (*ComposeFile, error)
ParseExisting reads and parses an existing docker-compose.yml file.
type ComposeVersion ¶
type ComposeVersion string
ComposeVersion represents the Docker Compose CLI version.
const ( // VersionV1 is the legacy docker-compose (Python) CLI. VersionV1 ComposeVersion = "v1" // VersionV2 is the new docker compose (Go plugin) CLI. VersionV2 ComposeVersion = "v2" )
type HealthCheck ¶
type HealthCheck = internalsvc.HealthCheck
HealthCheck represents a Docker health check configuration.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner handles docker-compose operations for containerized databases.
func NewRunnerWithFile ¶
NewRunnerWithFile creates a new compose runner with a custom compose file path.
func (*Runner) DetectVersion ¶
DetectVersion auto-detects the available compose version.
func (*Runner) DownWithVolumes ¶
DownWithVolumes stops and removes services and their volumes.
func (*Runner) GenerateFile ¶
GenerateFile creates a docker-compose.yml file with the given services.
func (*Runner) GenerateFileTo ¶
GenerateFileTo generates a docker-compose.yml file at a specific path.
func (*Runner) GetVersion ¶
func (r *Runner) GetVersion() ComposeVersion
GetVersion returns the current compose version setting.
func (*Runner) SetVersion ¶
func (r *Runner) SetVersion(v ComposeVersion)
SetVersion sets the compose CLI version to use.
type Service ¶
type Service = internalsvc.Service
Service represents a single service in a Docker Compose file.
func GenerateMySQLService ¶
func GenerateMySQLService(name string, cfg *config.MySQLConfig) Service
GenerateMySQLService generates a compose service for MySQL from config.
func GenerateMySQLServiceWithHealthCheck ¶
func GenerateMySQLServiceWithHealthCheck(name string, cfg *config.MySQLConfig) Service
GenerateMySQLServiceWithHealthCheck generates a compose service with healthcheck.
func GeneratePostgresService ¶
func GeneratePostgresService(name string, cfg *config.PostgresConfig) Service
GeneratePostgresService generates a compose service for PostgreSQL from config.
func GeneratePostgresServiceWithHealthCheck ¶
func GeneratePostgresServiceWithHealthCheck(name string, cfg *config.PostgresConfig) Service
GeneratePostgresServiceWithHealthCheck generates a compose service with healthcheck.
type ServiceConfig ¶
type ServiceConfig struct {
Name string
Image string
Port string
Username string
Password string
Database string
}
ServiceConfig holds parsed service configuration.
func (*ServiceConfig) IsMySQL ¶
func (s *ServiceConfig) IsMySQL() bool
IsMySQL returns true if the service appears to be MySQL.
func (*ServiceConfig) IsPostgres ¶
func (s *ServiceConfig) IsPostgres() bool
IsPostgres returns true if the service appears to be PostgreSQL.