compose

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteProject

func DeleteProject(name string) error

func DependencyOrder

func DependencyOrder(cf *ComposeFile) ([]string, error)

DependencyOrder returns service names in startup order (dependencies first). Uses Kahn's algorithm for topological sort.

func ProjectName

func ProjectName(composeFile string) string

ProjectName derives the project name from the compose file's directory.

func SaveProject

func SaveProject(p *ProjectState) error

Types

type BuildConfig added in v0.6.0

type BuildConfig struct {
	Context    string `yaml:"context"`
	Dockerfile string `yaml:"dockerfile,omitempty"`
}

BuildConfig handles both string and object forms for build directives.

build: ./dir                        → {Context: "./dir"}
build:
  context: ./dir
  dockerfile: Dockerfile.custom     → {Context: "./dir", Dockerfile: "Dockerfile.custom"}

func (BuildConfig) IsSet added in v0.6.0

func (b BuildConfig) IsSet() bool

IsSet returns true if a build context was specified.

func (*BuildConfig) UnmarshalYAML added in v0.6.0

func (b *BuildConfig) UnmarshalYAML(value *yaml.Node) error

type BuildOptions added in v0.6.0

type BuildOptions struct {
	File    string
	Project string
}

BuildOptions configures the build command.

type CommandOrArgs

type CommandOrArgs []string

CommandOrArgs handles both string and []string forms for command/entrypoint.

command: "echo hello"       → ["echo", "hello"]
command: ["echo", "hello"]  → ["echo", "hello"]

func (*CommandOrArgs) UnmarshalYAML

func (c *CommandOrArgs) UnmarshalYAML(value *yaml.Node) error

type ComposeFile

type ComposeFile struct {
	Services map[string]Service `yaml:"services"`
	Networks map[string]Network `yaml:"networks,omitempty"`
	Volumes  map[string]Volume  `yaml:"volumes,omitempty"`
}

ComposeFile represents a parsed docker-compose.yml.

func Load

func Load(file string) (*ComposeFile, string, error)

Load reads and parses a compose file. If file is empty, it searches for compose.yaml, compose.yml, docker-compose.yml, or docker-compose.yaml.

type DependsOn

type DependsOn []string

DependsOn handles both list and map forms.

depends_on: [db, redis]
depends_on:
  db:
    condition: service_started

func (*DependsOn) UnmarshalYAML

func (d *DependsOn) UnmarshalYAML(value *yaml.Node) error

type DownOptions

type DownOptions struct {
	File    string
	Project string
	Volumes bool // also remove volumes
}

DownOptions configures the down command.

type Environment

type Environment map[string]string

Environment handles both map and list forms.

environment:
  FOO: bar        → {"FOO": "bar"}
environment:
  - FOO=bar       → {"FOO": "bar"}
  - BAZ           → {"BAZ": ""} (inherit from host)

func (*Environment) UnmarshalYAML

func (e *Environment) UnmarshalYAML(value *yaml.Node) error

type LogsOptions

type LogsOptions struct {
	File    string
	Project string
	Service string // empty = all services
	Follow  bool
}

LogsOptions configures the logs command.

type Network

type Network struct {
	Driver   string `yaml:"driver,omitempty"`
	External bool   `yaml:"external,omitempty"`
}

Network represents a top-level network definition.

type Orchestrator

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

Orchestrator manages compose project lifecycle.

func NewOrchestrator

func NewOrchestrator(eng engine.Runtime) *Orchestrator

func (*Orchestrator) Build added in v0.6.0

func (o *Orchestrator) Build(ctx context.Context, opts BuildOptions) error

Build builds images for services that have a build directive.

func (*Orchestrator) Down

func (o *Orchestrator) Down(ctx context.Context, opts DownOptions) error

Down stops and removes all services, then cleans up networks/volumes.

func (*Orchestrator) Logs

func (o *Orchestrator) Logs(ctx context.Context, opts LogsOptions) error

Logs shows logs for one or all services.

func (*Orchestrator) Ps

func (o *Orchestrator) Ps(ctx context.Context, opts PsOptions) ([]ServiceStatus, error)

Ps returns the status of all services in the project.

func (*Orchestrator) Restart

func (o *Orchestrator) Restart(ctx context.Context, opts RestartOptions) error

Restart stops and starts a service (or all services).

func (*Orchestrator) Up

func (o *Orchestrator) Up(ctx context.Context, opts UpOptions) error

Up starts all services in dependency order.

type ProjectState

type ProjectState struct {
	Name     string                  `json:"name"`
	Dir      string                  `json:"dir"`
	File     string                  `json:"file"`
	Services map[string]ServiceState `json:"services"`
	Networks []string                `json:"networks,omitempty"`
	Volumes  []string                `json:"volumes,omitempty"`
}

ProjectState is the persisted state of a compose project.

func LoadProject

func LoadProject(name string) (*ProjectState, error)

type Proxy added in v0.6.0

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

Proxy forwards compose commands to nerdctl compose inside a VM.

func NewProxy added in v0.6.0

func NewProxy(apple engine.Runtime, mgr *sharedvm.Manager) *Proxy

NewProxy creates a compose proxy that executes nerdctl compose inside the VM managed by mgr.

func (*Proxy) Exec added in v0.6.0

func (p *Proxy) Exec(ctx context.Context, args []string, interactive bool) error

Exec runs `nerdctl compose <args>` inside the VM. Args should be the raw compose arguments (e.g., ["-f", "file.yaml", "build"]). Host paths in -f and --project-directory are translated to VM-internal paths.

type PsOptions

type PsOptions struct {
	File    string
	Project string
}

PsOptions configures the ps command.

type RestartOptions

type RestartOptions struct {
	File    string
	Project string
	Service string
}

RestartOptions configures the restart command.

type Service

type Service struct {
	Image         string            `yaml:"image"`
	Build         BuildConfig       `yaml:"build,omitempty"`
	ContainerName string            `yaml:"container_name,omitempty"`
	Command       CommandOrArgs     `yaml:"command,omitempty"`
	Entrypoint    CommandOrArgs     `yaml:"entrypoint,omitempty"`
	Ports         []string          `yaml:"ports,omitempty"`
	Volumes       []string          `yaml:"volumes,omitempty"`
	Environment   Environment       `yaml:"environment,omitempty"`
	EnvFile       StringOrSlice     `yaml:"env_file,omitempty"`
	DependsOn     DependsOn         `yaml:"depends_on,omitempty"`
	Networks      StringOrSlice     `yaml:"networks,omitempty"`
	Restart       string            `yaml:"restart,omitempty"`
	WorkingDir    string            `yaml:"working_dir,omitempty"`
	Hostname      string            `yaml:"hostname,omitempty"`
	Memory        string            `yaml:"mem_limit,omitempty"`
	CPUs          string            `yaml:"cpus,omitempty"`
	Labels        map[string]string `yaml:"labels,omitempty"`
	PullPolicy    string            `yaml:"pull_policy,omitempty"`
}

Service represents a single service in a compose file.

type ServiceState

type ServiceState struct {
	Service     string `json:"service"`
	ContainerID string `json:"container_id"`
	Image       string `json:"image"`
	Status      string `json:"status"` // running, stopped, created
}

ServiceState tracks a running service's container within a project.

type ServiceStatus

type ServiceStatus struct {
	Service   string `json:"service"`
	Container string `json:"container"`
	Image     string `json:"image"`
	Status    string `json:"status"`
}

ServiceStatus is used for ps output.

type StringOrSlice

type StringOrSlice []string

StringOrSlice handles fields that accept both a single string and a list.

env_file: .env
env_file:
  - .env
  - .env.local

func (*StringOrSlice) UnmarshalYAML

func (s *StringOrSlice) UnmarshalYAML(value *yaml.Node) error

type UpOptions

type UpOptions struct {
	File    string
	Detach  bool
	Project string // override project name
}

UpOptions configures the up command.

type Volume

type Volume struct {
	Driver   string `yaml:"driver,omitempty"`
	External bool   `yaml:"external,omitempty"`
}

Volume represents a top-level volume definition.

Jump to

Keyboard shortcuts

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