Documentation
¶
Overview ¶
Package compose provides Docker Compose file parsing and generation utilities.
Index ¶
- func DetectComposeVersion() (string, error)
- type ComposeFile
- type HealthCheck
- type Service
- func (s *Service) AddDependsOn(serviceName string, condition string)
- func (s *Service) AddHealthCheck(interval, timeout string, retries int, testCmd ...string)
- func (s *Service) GetEnv(key string) (string, bool)
- func (s *Service) GetPort(containerPort string) (string, error)
- func (s *Service) SetRestart(policy string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectComposeVersion ¶
DetectComposeVersion detects whether docker compose v2 or v1 is available. Returns "v2" for "docker compose", "v1" for "docker-compose", or error if neither.
Types ¶
type ComposeFile ¶
type ComposeFile struct {
Version string `yaml:"version,omitempty"`
Services map[string]Service `yaml:"services"`
Networks map[string]any `yaml:"networks,omitempty"`
Volumes map[string]any `yaml:"volumes,omitempty"`
}
ComposeFile represents a Docker Compose file structure.
func BuildComposeFile ¶
func BuildComposeFile(services map[string]Service) *ComposeFile
BuildComposeFile creates a complete Docker Compose file from services.
func Parse ¶
func Parse(path string) (*ComposeFile, error)
Parse reads and parses a Docker Compose file from the given path.
func ParseFromString ¶
func ParseFromString(content string) (*ComposeFile, error)
ParseFromString parses a Docker Compose file from a string.
func (*ComposeFile) GetService ¶
func (c *ComposeFile) GetService(name string) (Service, bool)
GetService returns a service by name.
func (*ComposeFile) String ¶
func (c *ComposeFile) String() (string, error)
String returns the YAML representation of the compose file.
func (*ComposeFile) WriteToFile ¶
func (c *ComposeFile) WriteToFile(path string) error
WriteToFile writes the compose file to disk.
type HealthCheck ¶
type HealthCheck struct {
Test []string `yaml:"test,omitempty"`
Interval string `yaml:"interval,omitempty"`
Timeout string `yaml:"timeout,omitempty"`
Retries int `yaml:"retries,omitempty"`
StartPeriod string `yaml:"start_period,omitempty"`
}
HealthCheck represents a Docker health check configuration.
type Service ¶
type Service struct {
Image string `yaml:"image,omitempty"`
ContainerName string `yaml:"container_name,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
Ports []string `yaml:"ports,omitempty"`
Volumes []string `yaml:"volumes,omitempty"`
Command string `yaml:"command,omitempty"`
Networks []string `yaml:"networks,omitempty"`
HealthCheck *HealthCheck `yaml:"healthcheck,omitempty"`
DependsOn map[string]any `yaml:"depends_on,omitempty"`
Restart string `yaml:"restart,omitempty"`
}
Service represents a single service in a Docker Compose file.
func GenerateMySQLCompose ¶
func GenerateMySQLCompose(serviceName, image, username, password, database string, port string) Service
GenerateMySQLCompose generates a Docker Compose snippet for MySQL.
func GeneratePostgresCompose ¶
func GeneratePostgresCompose(serviceName, image, username, password, database string, port string) Service
GeneratePostgresCompose generates a Docker Compose snippet for PostgreSQL.
func (*Service) AddDependsOn ¶
AddDependsOn adds a dependency on another service.
func (*Service) AddHealthCheck ¶
AddHealthCheck adds a healthcheck to the service.
func (*Service) GetPort ¶
GetPort returns the host port for a container port mapping. Format expected: "host:container" or just "container" if not mapped.
func (*Service) SetRestart ¶
SetRestart sets the restart policy.