compose

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package compose handles the Docker Compose source kind for devcontainer.json: parsing the user's compose project via compose-spec/compose-go and synthesizing override files that the engine layers on top during `docker compose up`.

Compose runtime orchestration (`up`, `down`, `ps`) is delegated to runtime.ComposeRuntime — this package is parser + override generator only. See design/compose.md for the full design and the §13 "future Go-native compose runtime" analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

Load parses the compose project described by opts. The returned *types.Project carries fully resolved interpolation, extends, and profile selection — caller doesn't need to repeat those.

compose-go's Project is intentionally not modified by callers directly (immutability invariant in v2); use Override to produce override YAML rather than mutating in place.

func PrimaryService

func PrimaryService(project *composetypes.Project, name string) (*composetypes.ServiceConfig, error)

PrimaryService returns the service named `name` from the project. Returns nil + error if the service doesn't exist (typical cause: devcontainer.json's "service" field doesn't match any service in the loaded compose project).

func WriteBuildOverride

func WriteBuildOverride(dst string, ov Override) error

WriteBuildOverride writes dst with the build override. Pins the primary service's image to ov.Image and clears any inherited build: directive via the YAML !reset tag (compose v2 idiom).

Returns an error if ov.Image or ov.Service is empty.

func WriteRunOverride

func WriteRunOverride(dst string, project *composetypes.Project, ov Override) error

WriteRunOverride writes dst with the run-time override: workspace bind mount, container env, labels. Reads the primary service's existing volumes from `project` and emits the full merged list so compose v2's "sequence-replace" merge doesn't drop the user's declarations.

`project` may be nil; in that case the override emits only our declarations (caller asserts no user-declared volumes exist).

Types

type BindMount

type BindMount struct {
	Source   string
	Target   string
	ReadOnly bool
}

BindMount describes one bind volume in the override.

type LoadOptions

type LoadOptions struct {
	// Files lists compose files in declaration order — earlier files
	// are overridden by later ones. Required.
	Files []string

	// WorkingDir is the directory compose-go uses as the base for
	// relative-path resolution inside the project (build contexts,
	// env_file paths, etc.). Required.
	WorkingDir string

	// ProjectName is set on the resulting types.Project. Engine derives
	// it from the workspace id; required.
	ProjectName string

	// Profiles activates compose profiles. Empty = no profiles
	// activated (which keeps services without `profiles:` running and
	// drops services that opt into a profile).
	Profiles []string

	// Env contains environment variables exposed to compose's $VAR
	// interpolation. Empty falls back to compose-go's default
	// behavior of reading os.Environ().
	Env []string
}

LoadOptions configures Load.

type Override

type Override struct {
	// Service is the name of the primary service to override; matches
	// devcontainer.json's "service" field.
	Service string

	// Image, when set, replaces the primary service's image and
	// clears its build directive (mutually exclusive in compose).
	// Engine sets this to the feature-extended image tag built
	// upstream.
	Image string

	// ExtraBindMounts are added to the primary service's volumes.
	// Engine adds the workspace folder bind here, plus any mounts
	// declared in devcontainer.json (cfg.Mounts).
	//
	// IMPORTANT: compose v2's default merge strategy for sequence
	// fields is REPLACEMENT, not concatenation. WriteRunOverride
	// reads the existing service's volumes from the loaded project
	// and emits the full merged list so we don't drop the user's
	// declarations.
	ExtraBindMounts []BindMount

	// ExtraEnvironment is merged into the primary service's
	// environment map. Compose merges maps natively, so we only
	// need to emit our additions.
	ExtraEnvironment map[string]string

	// Labels written on the primary service so Engine.Attach's
	// label-based lookup works (`dev.containers.id`, etc.).
	Labels map[string]string
}

Override describes the engine-side additions we layer onto the user's compose project for the primary service. Each field is optional (zero value is "no change for that aspect").

Jump to

Keyboard shortcuts

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