compose

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 EnsureDocker

func EnsureDocker() error

EnsureDocker checks if docker is available.

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

func WriteTemplate(path, template string) error

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 NewRunner

func NewRunner(projectName string) *Runner

NewRunner creates a new compose runner with the specified project name.

func NewRunnerWithFile

func NewRunnerWithFile(projectName, composeFile string) *Runner

NewRunnerWithFile creates a new compose runner with a custom compose file path.

func (*Runner) DetectVersion

func (r *Runner) DetectVersion() error

DetectVersion auto-detects the available compose version.

func (*Runner) Down

func (r *Runner) Down(ctx context.Context, dir string) error

Down stops and removes the docker-compose services.

func (*Runner) DownWithVolumes

func (r *Runner) DownWithVolumes(ctx context.Context, dir string) error

DownWithVolumes stops and removes services and their volumes.

func (*Runner) GenerateFile

func (r *Runner) GenerateFile(services map[string]Service, dir string) error

GenerateFile creates a docker-compose.yml file with the given services.

func (*Runner) GenerateFileTo

func (r *Runner) GenerateFileTo(services map[string]Service, path string) error

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

func (r *Runner) Logs(ctx context.Context, dir string, service string) (string, error)

Logs shows the logs of docker-compose services.

func (*Runner) Ps

func (r *Runner) Ps(ctx context.Context, dir string) (string, error)

Ps shows the status of docker-compose services.

func (*Runner) SetVersion

func (r *Runner) SetVersion(v ComposeVersion)

SetVersion sets the compose CLI version to use.

func (*Runner) Status

func (r *Runner) Status(ctx context.Context, dir string) (string, error)

Status shows the health status of services.

func (*Runner) Up

func (r *Runner) Up(ctx context.Context, dir string) error

Up starts the docker-compose services.

func (*Runner) UpWithWait

func (r *Runner) UpWithWait(ctx context.Context, dir string) error

UpWithWait starts services and waits for healthchecks to pass.

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.

Jump to

Keyboard shortcuts

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