compose

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package compose provides a small API to execute commands in Compose services via Docker Engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Down added in v0.2.0

func Down(ctx context.Context, projectName string) error

Down cleans up all resources (containers and networks) associated with the project. It ignores "not found" errors for idempotency.

func LoadProject

func LoadProject(ctx context.Context, dir string, files ...string) (*types.Project, error)

LoadProject loads a compose project from compose files within dir.

If files is empty, it defaults to docker-compose.yml and docker-compose.override.yml (the latter only if it exists).

Environment variable resolution follows compose-go behavior, including .env in dir.

Types

type Cmd

type Cmd struct {
	// Public fields
	Service types.ServiceConfig
	Path    string
	Args    []string
	Env     []string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

Cmd represents a pending command execution, similar to os/exec.Cmd.

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput(ctx context.Context) ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*Cmd) Output

func (c *Cmd) Output(ctx context.Context) ([]byte, error)

Output runs the command and returns its standard output.

func (*Cmd) Run

func (c *Cmd) Run(ctx context.Context) error

Run starts the container and waits for it to exit, similar to (*exec.Cmd).Run.

func (*Cmd) Start

func (c *Cmd) Start(ctx context.Context) (startErr error)

Start creates and starts the container for the configured service command.

func (*Cmd) Wait

func (c *Cmd) Wait(ctx context.Context) error

Wait waits for the started container to exit and returns its exit status.

func (*Cmd) WaitUntilHealthy added in v0.2.0

func (c *Cmd) WaitUntilHealthy(ctx context.Context) error

WaitUntilHealthy blocks until the started container becomes healthy.

Strict behavior: - If the service has no healthcheck defined, it returns an error immediately. - If the container becomes unhealthy or stops running, it returns an error immediately.

type ExitError

type ExitError struct {
	Code   int
	Stderr []byte
}

ExitError is returned when a container exits with a non-zero status. It is analogous to os/exec.ExitError.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) ExitCode

func (e *ExitError) ExitCode() int

ExitCode returns the process exit status code.

type Service

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

Service is an execution context bound to a Compose service definition.

It is intentionally small; lifecycle is managed per Cmd.

func From

func From(serviceName string) *Service

From loads the compose project in the current directory and returns a Service bound to the named service.

Errors are stored in the returned Service and will be returned later when Command().Run()/Start() is called (delayed error pattern).

func FromProject

func FromProject(project *types.Project, serviceName string) (*Service, error)

FromProject creates a Service from a project and service name.

This helper is not required by the SOW public API, but simplifies correct resolution of relative paths.

func NewService

func NewService(projectName string, config types.ServiceConfig) *Service

NewService creates a Service from a resolved service config.

Relative paths (e.g. bind mount sources) are resolved relative to the current working directory.

func (*Service) Command

func (s *Service) Command(name string, arg ...string) *Cmd

Command returns a Cmd to execute the given command name and arguments in the service.

Jump to

Keyboard shortcuts

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