compose

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadEnvFile

func LoadEnvFile(path string) (map[string]string, error)

LoadEnvFile loads environment variables from a file. Format: KEY=VALUE (one per line). Lines starting with # are comments. Empty lines are ignored. Quotes around values are stripped.

func LoadEnvFiles

func LoadEnvFiles(paths []string) (map[string]string, error)

LoadEnvFiles loads multiple env files and merges them. Later files override earlier ones.

func MergeEnv

func MergeEnv(maps ...map[string]string) map[string]string

MergeEnv merges multiple environment maps. Later maps override earlier ones.

func ParseEnvSlice

func ParseEnvSlice(env []string) map[string]string

ParseEnvSlice converts a slice of "KEY=VALUE" strings to a map.

func SubstituteEnv

func SubstituteEnv(input string, env map[string]string) string

SubstituteEnv replaces ${VAR}, ${VAR:-default}, ${VAR:+alt}, and $VAR in the input string with values from the provided environment map. If a variable is not found in the map, it falls back to os.Getenv.

func SubstituteEnvInMap

func SubstituteEnvInMap(m map[string]string, env map[string]string) map[string]string

SubstituteEnvInMap applies SubstituteEnv to all values in a map.

func SubstituteEnvInSlice

func SubstituteEnvInSlice(s []string, env map[string]string) []string

SubstituteEnvInSlice applies SubstituteEnv to all strings in a slice.

func ToEnvSlice

func ToEnvSlice(m map[string]string) []string

ToEnvSlice converts a map to a slice of "KEY=VALUE" strings.

func Validate

func Validate(file *ComposeFile) error

Validate validates a compose file.

Types

type BuildConfig

type BuildConfig struct {
	Context    string            `yaml:"context"`
	Dokifile   string            `yaml:"dokifile,omitempty"`
	Dockerfile string            `yaml:"dockerfile,omitempty"`
	Args       map[string]string `yaml:"args,omitempty"`
	Labels     map[string]string `yaml:"labels,omitempty"`
	Target     string            `yaml:"target,omitempty"`
	Network    string            `yaml:"network,omitempty"`
	CacheFrom  []string          `yaml:"cache_from,omitempty"`
}

BuildConfig defines build settings for a service.

type ComposeFile

type ComposeFile struct {
	Version  string              `yaml:"version,omitempty"`
	Name     string              `yaml:"name,omitempty"`
	Services map[string]*Service `yaml:"services"`
	Networks map[string]*Network `yaml:"networks,omitempty"`
	Volumes  map[string]*Volume  `yaml:"volumes,omitempty"`
	Configs  map[string]*Config  `yaml:"configs,omitempty"`
	Secrets  map[string]*Secret  `yaml:"secrets,omitempty"`
	Include  []string            `yaml:"include,omitempty"`
}

ComposeFile represents a docki-compose file (doki.yml).

type Config

type Config struct {
	File     string `yaml:"file,omitempty"`
	External bool   `yaml:"external,omitempty"`
}

Config represents a compose config.

type ConfigManager

type ConfigManager struct {
	// contains filtered or unexported fields
}

ConfigManager manages compose configs.

func NewConfigManager

func NewConfigManager(projectDir string, configs map[string]*Config) *ConfigManager

NewConfigManager creates a new config manager.

func (*ConfigManager) GetConfigPath

func (cm *ConfigManager) GetConfigPath(name string) (string, error)

GetConfigPath returns the path to a config file.

func (*ConfigManager) MountAllConfigs

func (cm *ConfigManager) MountAllConfigs(svcConfigs []string, destDir string) error

MountAllConfigs mounts all configs for a service.

func (*ConfigManager) MountConfig

func (cm *ConfigManager) MountConfig(name, destDir string) error

MountConfig mounts a config into a container directory.

type DeployConfig

type DeployConfig struct {
	Replicas      int                  `yaml:"replicas,omitempty"`
	Resources     *DeployResources     `yaml:"resources,omitempty"`
	RestartPolicy *DeployRestartPolicy `yaml:"restart_policy,omitempty"`
}

DeployConfig defines deployment settings.

type DeployResources

type DeployResources struct {
	Limits       *ResourceLimits `yaml:"limits,omitempty"`
	Reservations *ResourceLimits `yaml:"reservations,omitempty"`
}

DeployResources defines resource limits.

type DeployRestartPolicy

type DeployRestartPolicy struct {
	Condition   string `yaml:"condition,omitempty"`
	Delay       string `yaml:"delay,omitempty"`
	MaxAttempts int    `yaml:"max_attempts,omitempty"`
}

DeployRestartPolicy defines restart policy for deployments.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the compose engine.

func NewEngine

func NewEngine(project string, rt *runtime.Runtime, img *image.Store, net *network.Manager) *Engine

NewEngine creates a new compose engine.

func (*Engine) Build

func (e *Engine) Build() error

Y11: Build builds images for services with build config.

func (*Engine) Config

func (e *Engine) Config() (string, error)

Config validates the compose file and returns it as YAML.

func (*Engine) Create added in v0.9.3

func (e *Engine) Create() error

func (*Engine) Down

func (e *Engine) Down() error

Down stops and removes all services.

func (*Engine) KillServices added in v0.9.3

func (e *Engine) KillServices(signal string, services []string) error

func (*Engine) Load

func (e *Engine) Load(path string) error

Load loads a compose file from disk.

func (*Engine) Logs

func (e *Engine) Logs(tail int) (map[string]string, error)

Y25: Logs returns logs for all services.

func (*Engine) PauseServices added in v0.9.3

func (e *Engine) PauseServices(services []string) error

func (*Engine) PrintConfigSubset added in v0.9.3

func (e *Engine) PrintConfigSubset(services, volumes, networks bool)

func (*Engine) ProjectImages added in v0.9.3

func (e *Engine) ProjectImages() ([]common.ImageInfo, error)

func (*Engine) Ps

func (e *Engine) Ps() ([]common.ContainerInfo, error)

Ps lists running services.

func (*Engine) Pull

func (e *Engine) Pull() error

Y25: Pull pulls images for all services.

func (*Engine) Restart

func (e *Engine) Restart() error

Y25: Restart restarts all services.

func (*Engine) RestartServices added in v0.9.3

func (e *Engine) RestartServices(services []string) error

func (*Engine) Start added in v0.9.3

func (e *Engine) Start() error

Start starts stopped services. For containers that exited, recreates them via Up.

func (*Engine) StartServices added in v0.9.3

func (e *Engine) StartServices(services []string) error

func (*Engine) Stop

func (e *Engine) Stop() error

Y25: Stop stops all services.

func (*Engine) StopServices added in v0.9.3

func (e *Engine) StopServices(services []string) error

func (*Engine) Top added in v0.9.3

func (e *Engine) Top(services []string) error

func (*Engine) UnpauseServices added in v0.9.3

func (e *Engine) UnpauseServices(services []string) error

func (*Engine) Up

func (e *Engine) Up() error

Up starts all services defined in the compose file.

type HealthcheckConfig

type HealthcheckConfig struct {
	Test          interface{} `yaml:"test"`
	Interval      string      `yaml:"interval,omitempty"`
	Timeout       string      `yaml:"timeout,omitempty"`
	Retries       int         `yaml:"retries,omitempty"`
	StartPeriod   string      `yaml:"start_period,omitempty"`
	StartInterval string      `yaml:"start_interval,omitempty"`
	Disable       bool        `yaml:"disable,omitempty"`
}

HealthcheckConfig defines healthcheck for a service.

type LoggingConfig added in v0.9.3

type LoggingConfig struct {
	Driver  string            `yaml:"driver,omitempty"`
	Options map[string]string `yaml:"options,omitempty"`
}

LoggingConfig defines logging settings.

type Network

type Network struct {
	Driver     string `yaml:"driver,omitempty"`
	External   bool   `yaml:"external,omitempty"`
	Name       string `yaml:"name,omitempty"`
	Internal   bool   `yaml:"internal,omitempty"`
	EnableIPv6 bool   `yaml:"enable_ipv6,omitempty"`
}

Network represents a compose network.

type ResourceLimits

type ResourceLimits struct {
	CPUs   string `yaml:"cpus,omitempty"`
	Memory string `yaml:"memory,omitempty"`
}

ResourceLimits defines resource limits.

type Secret

type Secret struct {
	File     string `yaml:"file,omitempty"`
	External bool   `yaml:"external,omitempty"`
}

Secret represents a compose secret.

type SecretManager

type SecretManager struct {
	// contains filtered or unexported fields
}

SecretManager manages compose secrets.

func NewSecretManager

func NewSecretManager(projectDir string, secrets map[string]*Secret) *SecretManager

NewSecretManager creates a new secret manager.

func (*SecretManager) GetSecretPath

func (sm *SecretManager) GetSecretPath(name string) (string, error)

GetSecretPath returns the path to a secret file.

func (*SecretManager) MountAllSecrets

func (sm *SecretManager) MountAllSecrets(svcSecrets []string, destDir string) error

MountAllSecrets mounts all secrets for a service.

func (*SecretManager) MountSecret

func (sm *SecretManager) MountSecret(name, destDir string) error

MountSecret mounts a secret into a container directory.

type Service

type Service struct {
	Image           string                 `yaml:"image,omitempty"`
	Build           *BuildConfig           `yaml:"build,omitempty"`
	Command         interface{}            `yaml:"command,omitempty"`
	Entrypoint      interface{}            `yaml:"entrypoint,omitempty"`
	Environment     interface{}            `yaml:"environment,omitempty"`
	EnvFile         interface{}            `yaml:"env_file,omitempty"`
	Ports           interface{}            `yaml:"ports,omitempty"`
	Expose          []string               `yaml:"expose,omitempty"`
	Volumes         interface{}            `yaml:"volumes,omitempty"`
	Networks        interface{}            `yaml:"networks,omitempty"`
	NetworkMode     string                 `yaml:"network_mode,omitempty"`
	DependsOn       interface{}            `yaml:"depends_on,omitempty"`
	Restart         string                 `yaml:"restart,omitempty"`
	Labels          interface{}            `yaml:"labels,omitempty"`
	WorkingDir      string                 `yaml:"working_dir,omitempty"`
	User            string                 `yaml:"user,omitempty"`
	Hostname        string                 `yaml:"hostname,omitempty"`
	Domainname      string                 `yaml:"domainname,omitempty"`
	Tty             bool                   `yaml:"tty,omitempty"`
	StdinOpen       bool                   `yaml:"stdin_open,omitempty"`
	Privileged      bool                   `yaml:"privileged,omitempty"`
	ReadOnly        bool                   `yaml:"read_only,omitempty"`
	Init            bool                   `yaml:"init,omitempty"`
	DNS             interface{}            `yaml:"dns,omitempty"`
	DNSSearch       interface{}            `yaml:"dns_search,omitempty"`
	DNSOpt          interface{}            `yaml:"dns_opt,omitempty"`
	ExtraHosts      interface{}            `yaml:"extra_hosts,omitempty"`
	CapAdd          []string               `yaml:"cap_add,omitempty"`
	CapDrop         []string               `yaml:"cap_drop,omitempty"`
	SecurityOpt     []string               `yaml:"security_opt,omitempty"`
	Sysctls         map[string]string      `yaml:"sysctls,omitempty"`
	Healthcheck     *HealthcheckConfig     `yaml:"healthcheck,omitempty"`
	StopSignal      string                 `yaml:"stop_signal,omitempty"`
	StopGracePeriod string                 `yaml:"stop_grace_period,omitempty"`
	Deploy          *DeployConfig          `yaml:"deploy,omitempty"`
	Profile         string                 `yaml:"profile,omitempty"`
	Profiles        []string               `yaml:"profiles,omitempty"`
	Extends         interface{}            `yaml:"extends,omitempty"`
	Secrets         []string               `yaml:"secrets,omitempty"`
	Configs         []string               `yaml:"configs,omitempty"`
	ContainerName   string                 `yaml:"container_name,omitempty"`
	ShmSize         string                 `yaml:"shm_size,omitempty"`
	PidsLimit       int64                  `yaml:"pids_limit,omitempty"`
	OomKillDisable  bool                   `yaml:"oom_kill_disable,omitempty"`
	OomScoreAdj     int                    `yaml:"oom_score_adj,omitempty"`
	MacAddress      string                 `yaml:"mac_address,omitempty"`
	Logging         *LoggingConfig         `yaml:"logging,omitempty"`
	Ulimits         map[string]interface{} `yaml:"ulimits,omitempty"`
	Tmpfs           interface{}            `yaml:"tmpfs,omitempty"`
	BlkioConfig     map[string]interface{} `yaml:"blkio_config,omitempty"`
	Devices         []string               `yaml:"devices,omitempty"`
	Platform        string                 `yaml:"platform,omitempty"`
	Runtime         string                 `yaml:"runtime,omitempty"`
	Scale           int                    `yaml:"scale,omitempty"`
}

Service represents a service (container) in the compose file.

type ValidationError

type ValidationError struct {
	Field   string
	Service string
	Message string
}

ValidationError represents a compose file validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type ValidationErrors

type ValidationErrors []*ValidationError

ValidationErrors is a list of validation errors.

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

type Volume

type Volume struct {
	Driver     string            `yaml:"driver,omitempty"`
	External   bool              `yaml:"external,omitempty"`
	Name       string            `yaml:"name,omitempty"`
	DriverOpts map[string]string `yaml:"driver_opts,omitempty"`
}

Volume represents a compose volume.

Jump to

Keyboard shortcuts

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