Documentation
¶
Overview ¶
Package compose provides a small API to execute commands in Compose services via Docker Engine.
Index ¶
- func Down(ctx context.Context, projectName string) error
- func LoadProject(ctx context.Context, dir string, files ...string) (*types.Project, error)
- type Cmd
- func (c *Cmd) CombinedOutput(ctx context.Context) ([]byte, error)
- func (c *Cmd) Output(ctx context.Context) ([]byte, error)
- func (c *Cmd) Run(ctx context.Context) error
- func (c *Cmd) Start(ctx context.Context) (startErr error)
- func (c *Cmd) Wait(ctx context.Context) error
- func (c *Cmd) WaitUntilHealthy(ctx context.Context) error
- type ExitError
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Down ¶ added in v0.2.0
Down cleans up all resources (containers and networks) associated with the project. It ignores "not found" errors for idempotency.
func LoadProject ¶
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 ¶
CombinedOutput runs the command and returns its combined standard output and standard error.
func (*Cmd) WaitUntilHealthy ¶ added in v0.2.0
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 ¶
ExitError is returned when a container exits with a non-zero status. It is analogous to os/exec.ExitError.
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 ¶
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 ¶
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.