Help us shape the future of Go! Take the 2026 Go Developer Survey

compose

package
v0.1.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrComposeFilePathEmpty indicates a missing compose file path.
	ErrComposeFilePathEmpty = errors.New("compose file path cannot be empty")
	// ErrContainerClientNil indicates that ComposeClient was not initialized properly.
	ErrContainerClientNil = errors.New("container client cannot be nil")
	// ErrClientOptionNil indicates that a nil client option was supplied.
	ErrClientOptionNil = errors.New("compose client option cannot be nil")
	// ErrServiceRegistryNil indicates that WithServiceRegistry received nil.
	ErrServiceRegistryNil = errors.New("service registry cannot be nil")
	// ErrUpSessionInvalid indicates an UpSession was not returned by PrepareUp.
	ErrUpSessionInvalid = errors.New("compose up session is invalid")
	// ErrDownSessionInvalid indicates a DownSession was not returned by PrepareDown.
	ErrDownSessionInvalid = errors.New("compose down session is invalid")
	// ErrInvalidDNSConfig indicates invalid or incomplete per-network DNS configuration.
	ErrInvalidDNSConfig = errors.New("invalid DNS configuration")
	// ErrServiceNotFound indicates a requested service is absent from the loaded project.
	ErrServiceNotFound = errors.New("service not found in compose project")
	// ErrUnsupportedFeature indicates the compose feature is not implemented yet.
	ErrUnsupportedFeature = errors.New("unsupported compose feature")
)

Functions

This section is empty.

Types

type BuildOptions

type BuildOptions struct {
	// Services limits build to the selected services. Empty means all services.
	Services []string
	// Output receives streaming build output.
	Output io.Writer
}

BuildOptions controls which services are built and where build logs are written.

type ClientOption

type ClientOption func(*ComposeClient) error

ClientOption configures an optional Compose client integration.

func WithContainerClient

func WithContainerClient(containerClient *container.Client) ClientOption

WithContainerClient supplies the container runtime used by Compose. It is useful to applications that also manage ACC infrastructure with the same runtime client. When omitted, NewComposeClient constructs the default client.

func WithServiceRegistry

func WithServiceRegistry(registry ServiceRegistry) ClientOption

WithServiceRegistry configures a registry that receives service runtime records during Up and container removals during Down.

type ComposeClient

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

ComposeClient orchestrates multi-service operations using the container SDK.

func NewComposeClient

func NewComposeClient(options ...ClientOption) (*ComposeClient, error)

NewComposeClient creates a Compose client backed by a default container client. Without WithServiceRegistry, it performs no registry or filesystem state management.

func (*ComposeClient) BuildImages

func (c *ComposeClient) BuildImages(ctx context.Context, path string, parseOpts ParseOptions, opts BuildOptions) error

Build loads a compose project and builds images for services that declare build config.

func (*ComposeClient) Down

func (c *ComposeClient) Down(ctx context.Context, path string, parseOpts ParseOptions, opts DownOptions) error

Down stops and removes labeled project containers in reverse dependency order.

func (*ComposeClient) Logs

func (c *ComposeClient) Logs(ctx context.Context, path string, parseOpts ParseOptions, opts LogsOptions) error

Logs retrieves logs for selected services in a Compose project.

func (*ComposeClient) ParseWithOptionsToJson

func (c *ComposeClient) ParseWithOptionsToJson(ctx context.Context, path string, opts ParseOptions) (map[string]any, error)

ParseWithOptions validates a compose file and returns it as a JSON object.

func (*ComposeClient) PrepareDown

func (c *ComposeClient) PrepareDown(ctx context.Context, path string, parseOpts ParseOptions, opts DownOptions) (*DownSession, error)

PrepareDown loads the Compose project and identifies the service containers and volumes that a teardown will affect. It does not remove any resources.

func (*ComposeClient) PrepareUp

func (c *ComposeClient) PrepareUp(ctx context.Context, path string, parseOpts ParseOptions, opts UpOptions) (*UpSession, error)

PrepareUp loads and validates a Compose project, resolves images and mount sources, creates required volumes, and ensures required networks. It does not start any Compose service containers.

func (*ComposeClient) Up

func (c *ComposeClient) Up(ctx context.Context, path string, parseOpts ParseOptions, opts UpOptions) error

Up brings selected services up in dependency order. It builds missing local images for services that declare build configuration before starting them.

type DownOptions

type DownOptions struct {
	// Services selects services and their transitive dependents for teardown.
	// Empty means all services.
	Services []string
	// RemoveOrphans also removes project containers whose service is no longer
	// declared in the current Compose file.
	RemoveOrphans bool
	// Force forces container deletion when supported by the runtime.
	Force bool
	// Volumes removes eligible ACC-owned named and anonymous volumes. With
	// Services set, only volumes attached to containers removed by this invocation
	// are eligible, and volumes referenced by any remaining container are retained.
	// Without Services, detached project-owned named volumes are also eligible.
	Volumes bool
	// OnWarning receives non-fatal warnings. The SDK never renders warnings
	// itself; callers decide whether and how to present them.
	OnWarning func(string)
}

DownOptions controls compose down behavior.

type DownSession

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

DownSession is a prepared Compose teardown. It separates service removal from project-resource cleanup so applications can manage their own infrastructure between those phases.

func (*DownSession) ProjectName

func (p *DownSession) ProjectName() string

ProjectName returns the resolved Compose project name for this teardown.

func (*DownSession) RemoveNetworks

func (p *DownSession) RemoveNetworks(ctx context.Context) error

RemoveNetworks removes eligible project networks after service containers and application-managed infrastructure are gone.

func (*DownSession) RemoveResources

func (p *DownSession) RemoveResources(ctx context.Context) error

RemoveResources removes eligible project volumes and networks after service containers and any application-managed infrastructure are gone.

func (*DownSession) RemoveServices

func (p *DownSession) RemoveServices(ctx context.Context) error

RemoveServices stops and deletes the selected Compose service containers.

func (*DownSession) RemoveVolumes

func (p *DownSession) RemoveVolumes(ctx context.Context) error

RemoveVolumes removes eligible project volumes after the selected service containers are gone. For selected-service teardown, only attached volumes without references from any remaining container are eligible.

type LogsOptions

type LogsOptions struct {
	// Services limits logs to selected services. Empty means all services.
	Services []string
	// Follow keeps streaming logs until the context is cancelled or the process exits.
	Follow bool
	// Output receives the service logs.
	Output io.Writer
}

LogsOptions controls which service logs are displayed and whether they are followed.

type ParseOptions

type ParseOptions struct {
	// WorkingDir is used for resolving relative paths and environment files.
	// Defaults to the compose file's directory when empty. It does not change
	// the default project name.
	WorkingDir string
	// ProjectName overrides the Compose project name. When empty, the top-level
	// Compose name is used when present; otherwise the compose file's parent
	// directory name is used.
	ProjectName string
	// Environment provides additional variables used during interpolation.
	Environment map[string]string
	// EnvFiles contains explicit environment files used during interpolation.
	// Files are loaded in the order provided.
	EnvFiles []string
	// DisableOSEnvironment prevents process environment variables from being
	// used during interpolation.
	DisableOSEnvironment bool
	// DisableDotEnv prevents the default .env file from being loaded.
	// Explicit EnvFiles are still honored.
	DisableDotEnv bool
}

ParseOptions configures compose parsing behavior.

type ServiceNetworkRuntime

type ServiceNetworkRuntime struct {
	// Name is the Compose-resolved runtime network name.
	Name string
	// Addresses contains assigned IP addresses without CIDR prefixes.
	Addresses []netip.Addr
	// Aliases contains aliases declared for this service on this network.
	Aliases []string
}

ServiceNetworkRuntime describes a service container's addresses and aliases on one runtime network.

type ServiceRegistry

type ServiceRegistry interface {
	// Ensure prepares the registry before Compose mutates runtime resources.
	Ensure(context.Context) error
	// Upsert records a service after its container has been started and inspected.
	// Its errors are reported as warnings because the runtime has already changed.
	Upsert(context.Context, ServiceRuntime) error
	// Remove deletes records after the corresponding containers are removed. Its
	// errors are reported as warnings and do not interrupt runtime cleanup.
	Remove(context.Context, []string) error
}

ServiceRegistry receives runtime service records created and removed by Compose. Implementations may persist these records or publish them to a service-discovery system. Omitting WithServiceRegistry disables this integration.

type ServiceRuntime

type ServiceRuntime struct {
	// ProjectName is the resolved Compose project name.
	ProjectName string
	// ServiceName is the service's key in the Compose project.
	ServiceName string
	// ContainerID is the runtime container identifier.
	ContainerID string
	// Nameservers contains the service's resolved Compose dns values.
	Nameservers []string
	// Networks contains the container's inspected network attachments.
	Networks []ServiceNetworkRuntime
}

ServiceRuntime describes one running Compose service container.

type ServiceStartOptions

type ServiceStartOptions struct {
	// DNSByNetwork maps runtime network names to DNS server addresses. Every
	// network used by a service must have an entry when this is set.
	// With no entries, Compose dns values are passed directly to the runtime.
	DNSByNetwork map[string]netip.Addr
}

ServiceStartOptions controls the service-start phase of an UpSession.

type UpOptions

type UpOptions struct {
	// Services limits startup to the selected services. Empty means all services.
	Services []string
	// Build forces all buildable services to build before any containers start.
	// Without it, a buildable service is built only when its local image is absent.
	Build bool
	// RenewAnonymousVolumes creates fresh anonymous volumes when existing
	// service containers are recreated instead of reusing volumes by target.
	RenewAnonymousVolumes bool
	// RemoveOrphans removes ACC-owned containers for services that are no
	// longer declared by the loaded Compose project.
	RemoveOrphans bool
	// Output receives attached service logs and is the fallback for build and
	// runtime output.
	Output io.Writer
	// BuildOutput receives build output. When nil, Output is used.
	BuildOutput io.Writer
	// RuntimeOutput receives startup output, including automatic image-pull
	// progress, even when Attach is false. When nil, Output is used.
	RuntimeOutput io.Writer
	// Attach streams service logs until detached or context cancellation.
	Attach bool
	// Detach, when non-nil, detaches attached log streaming when signaled.
	// Canceling the context also detaches.
	Detach <-chan struct{}
	// OnWarning receives non-fatal Compose warnings. The SDK never renders
	// warnings itself; callers decide whether and how to present them.
	OnWarning func(string)
	// OnFatalWarning receives a diagnostic immediately before Up returns an
	// error for an unsupported Compose feature. The SDK never renders
	// diagnostics itself; callers decide whether and how to present them.
	OnFatalWarning func(string)
}

UpOptions controls compose up behavior.

type UpSession

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

UpSession is an opaque, validated Compose startup session. It is returned only by PrepareUp, which ensures callers cannot start services before the Compose project and its runtime resources have been prepared.

func (*UpSession) NetworkNames

func (p *UpSession) NetworkNames() []string

NetworkNames returns the sorted runtime networks required by selected services and by existing project containers that this Up leaves untouched.

func (*UpSession) ProjectName

func (p *UpSession) ProjectName() string

ProjectName returns the resolved project name for this startup session.

func (*UpSession) RemoveObsoleteNetworks

func (p *UpSession) RemoveObsoleteNetworks(ctx context.Context) error

RemoveObsoleteNetworks removes ACC-owned project networks that are no longer declared or retained for an orphan after service reconciliation.

func (*UpSession) ServiceNames

func (p *UpSession) ServiceNames() []string

ServiceNames returns the services selected for reconciliation in dependency order.

func (*UpSession) StartServices

func (p *UpSession) StartServices(ctx context.Context, startOpts ServiceStartOptions) (err error)

StartServices starts the prepared services in dependency order. A DNS server is selected from each service's attached runtime networks; this is deliberately done here because Compose owns service/network membership.

func (*UpSession) StopLogs

func (p *UpSession) StopLogs()

StopLogs stops any attached log streams after a later reconciliation error.

func (*UpSession) WaitForLogs

func (p *UpSession) WaitForLogs() error

WaitForLogs keeps an attached up running after service and resource reconciliation has finished. It returns immediately for detached sessions.

Jump to

Keyboard shortcuts

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