compose

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProjectLabel is the label used by Docker Compose to identify project containers.
	ProjectLabel = "com.docker.compose.project"

	// ServiceLabel is the label used by Docker Compose to identify service containers.
	ServiceLabel = "com.docker.compose.service"
)

Variables

This section is empty.

Functions

func LoadProject

func LoadProject(ctx context.Context, paths []string, envFiles []string) (*types.Project, error)

LoadProject loads a Docker Compose project from the given file paths and env files.

func ProjectName

func ProjectName(workspaceID string) string

ProjectName returns the compose project name for a workspace. It respects the COMPOSE_PROJECT_NAME env var, falling back to "crib-<wsID>".

Types

type Helper

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

Helper wraps the compose CLI for executing compose commands.

func NewHelper

func NewHelper(runtimeCommand string, logger *slog.Logger) (*Helper, error)

NewHelper detects the compose CLI and returns a Helper. It probes `<runtimeCommand> compose version --short` to verify availability.

func NewHelperFromRuntime

func NewHelperFromRuntime(runtimeCommand string) *Helper

NewHelperFromRuntime creates a Helper with the given runtime command without probing for compose availability. Useful for cases where only the runtime identity is needed (e.g. checking if Podman is in use).

func (*Helper) Build

func (h *Helper) Build(ctx context.Context, projectName string, files []string, services []string, stdout, stderr io.Writer, extraEnv []string) error

Build runs `compose build` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) BuiltImageName

func (h *Helper) BuiltImageName(projectName, serviceName string) string

BuiltImageName returns the expected image name for a compose-built service. The separator between project and service differs by compose provider: Docker Compose v2 uses "-", podman-compose uses "_".

func (*Helper) Down

func (h *Helper) Down(ctx context.Context, projectName string, files []string, stdout, stderr io.Writer, extraEnv []string) error

Down runs `compose down` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) ListContainers

func (h *Helper) ListContainers(ctx context.Context, projectName string, files []string, extraEnv []string) ([]string, error)

ListContainers returns the container IDs for a compose project. Returns only the IDs without any filtering or parsing.

func (*Helper) ListServiceStatuses added in v0.3.0

func (h *Helper) ListServiceStatuses(ctx context.Context, projectName string, files []string, extraEnv []string) ([]ServiceStatus, error)

ListServiceStatuses returns the status of all services in a compose project. Uses `compose ps --format json` to get service names and states.

func (*Helper) Logs added in v0.5.0

func (h *Helper) Logs(ctx context.Context, projectName string, files []string, follow bool, tail string, stdout, stderr io.Writer, extraEnv []string) error

Logs runs `compose logs` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) Restart added in v0.2.0

func (h *Helper) Restart(ctx context.Context, projectName string, files []string, stdout, stderr io.Writer, extraEnv []string) error

Restart runs `compose restart` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) Run

func (h *Helper) Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer, extraEnv []string) error

Run executes a compose command with the given args and I/O streams. extraEnv is appended to the current process environment for the subprocess.

func (*Helper) RuntimeCommand

func (h *Helper) RuntimeCommand() string

RuntimeCommand returns the base runtime command (e.g. "docker" or "podman").

func (*Helper) Stop

func (h *Helper) Stop(ctx context.Context, projectName string, files []string, stdout, stderr io.Writer, extraEnv []string) error

Stop runs `compose stop` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) Up

func (h *Helper) Up(ctx context.Context, projectName string, files []string, services []string, stdout, stderr io.Writer, extraEnv []string) error

Up runs `compose up -d` for the given project. extraEnv is appended to the subprocess environment for variable substitution.

func (*Helper) Version

func (h *Helper) Version() string

Version returns the detected compose version string.

type PortBinding added in v0.4.0

type PortBinding struct {
	ContainerPort int
	HostPort      int
	HostIP        string
	Protocol      string
}

PortBinding describes a published port mapping for a compose service.

type ServiceInfo

type ServiceInfo struct {
	// Image is the image reference for the service (empty if build-only).
	Image string
	// HasBuild is true when the service has a build section.
	HasBuild bool
	// BuildCtx is the absolute path to the build context directory.
	BuildCtx string
	// Dockerfile is the Dockerfile path (relative to BuildCtx).
	Dockerfile string
	// User is the user directive from the compose service.
	User string
}

ServiceInfo holds extracted service configuration needed for feature builds.

func GetServiceInfo

func GetServiceInfo(ctx context.Context, paths []string, serviceName string, env []string) (*ServiceInfo, error)

GetServiceInfo loads compose files and extracts configuration for the named service. env provides extra environment variables for ${VAR} substitution in compose files.

type ServiceStatus added in v0.3.0

type ServiceStatus struct {
	Service string
	State   string
	Ports   []PortBinding
}

ServiceStatus holds the status of a single compose service.

Jump to

Keyboard shortcuts

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