compose

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTagTemplate is the default tag template appended to images without a tag when building locally.
	// Format:
	// If the project workdir is a git repo: "2025-08-16-130734.84d33bb" or "2025-08-16-130734.84d33bb.dirty"
	// If not a git repo: "2025-08-16-130734" which is the current date and time.
	DefaultTagTemplate = `` /* 137-byte string literal not displayed */
	// DefaultImageTemplate is the default image template used when no image is specified.
	DefaultImageTemplate = "{{.Project}}/{{.Service}}:" + DefaultTagTemplate
)
View Source
const (
	// SecretRefPrefix prefixes a reference to a secret defined in the top-level 'secrets' section,
	// e.g. 'secret://my_secret'.
	SecretRefPrefix = "secret://"
	// SecretCommandExtensionKey is the short-form secret extension providing the command to run,
	// equivalent to 'driver: exec' with 'driver_opts.command'.
	SecretCommandExtensionKey = "x-command"
)
View Source
const CaddyExtensionKey = "x-caddy"
View Source
const ContextExtensionKey = "x-context"

ContextExtensionKey is the top-level Compose extension key for specifying the cluster context.

View Source
const MachinesExtensionKey = "x-machines"
View Source
const PortsExtensionKey = "x-ports"
View Source
const PreDeployHookExtensionKey = "x-pre_deploy"

Variables

This section is empty.

Functions

func ClusterContext added in v0.18.0

func ClusterContext(project *types.Project) string

ClusterContext extracts the x-context value from the project's top-level extensions. Returns an empty string if x-context is not set.

func HasCommandSecretRefs added in v0.20.0

func HasCommandSecretRefs(project *types.Project) bool

HasCommandSecretRefs reports whether any service environment references a secret that is resolved by running a command.

func LoadProject

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

LoadProject loads a Compose project from the default locations or the given paths.

func LoadProjectFromContent added in v0.15.0

func LoadProjectFromContent(
	ctx context.Context, content string, opts ...composecli.ProjectOptionsFn,
) (*types.Project, error)

LoadProjectFromContent loads a Compose project from the given YAML content.

func ProcessImageTemplates added in v0.14.0

func ProcessImageTemplates(project *types.Project) (*types.Project, error)

ProcessImageTemplates processes image names in services to expand Go template expressions using git metadata. If a service has no image specified, uses the default template {{.Project}}/{{.Service}}:{{.Tag}}. If a service has a build section and an image without a tag, appends the default tag template. Fully specified images are left unchanged.

Template context: ImageTemplateContext Template functions: gitsha(length?), gitdate(format, timezone?), date(format, timezone?)

Examples:

image: myapp:{{.Tag}}                        → myapp:2025-08-16-130734.84d33bb
image: registry.io/api:v1.0-{{gitsha 7}}     → registry.io/api:v1.0-84d33bb
image: worker:{{gitdate "2006-01-02"}}       → worker:2025-08-16
build: . / image: mybackend                  → mybackend:2025-08-16-130734.84d33bb
build: . / (no image)                        → myproject/myservice:2025-08-16-130734.84d33bb
image: postgres                              → postgres (unchanged)

func ResolveSecrets added in v0.20.0

func ResolveSecrets(ctx context.Context, project *types.Project) error

ResolveSecrets resolves 'secret://name' references in the services' environment to actual secret values, setting each referenced variable to the secret's value in place. Each referenced secret is resolved at most once, even if referenced by multiple services. Secrets that are not referenced are never resolved.

func ServiceSpecFromCompose

func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.ServiceSpec, error)

Types

type Caddy added in v0.11.1

type Caddy struct {
	Config string `yaml:"config" json:"config"`
}

func (*Caddy) DecodeMapstructure added in v0.11.1

func (c *Caddy) DecodeMapstructure(value any) error

DecodeMapstructure decodes x-caddy extension from either a string or an object. When x-caddy is a string, it's mapped directly to the Config field.

type Client

type Client interface {
	api.DNSClient
	deploy.Client
}

type Deployment

type Deployment struct {
	Client       Client
	Project      *types.Project
	SpecResolver *deploy.ServiceSpecResolver
	Strategy     deploy.Strategy
	// contains filtered or unexported fields
}

func NewDeployment

func NewDeployment(ctx context.Context, cli Client, project *types.Project) (*Deployment, error)

func NewDeploymentWithStrategy added in v0.11.0

func NewDeploymentWithStrategy(ctx context.Context, cli Client, project *types.Project, strategy deploy.Strategy) (*Deployment, error)

func (*Deployment) Plan

func (d *Deployment) Plan(ctx context.Context) (Plan, error)

func (*Deployment) Run

func (d *Deployment) Run(ctx context.Context) error

func (*Deployment) ServiceSpec

func (d *Deployment) ServiceSpec(name string) (api.ServiceSpec, error)

ServiceSpec returns the service specification for the given compose service that is ready for deployment.

type ImageTemplateContext added in v0.14.0

type ImageTemplateContext struct {
	// Project is the project name.
	Project string
	// Service is the service name where the image is defined.
	Service string
	// Git is the git repo state.
	Git gitutil.GitState
	// Tag is the rendered DefaultTagTemplate used for images without a tag.
	Tag string
}

ImageTemplateContext contains structured data for image template processing.

type MachinesSource added in v0.10.0

type MachinesSource []string

MachinesSource represents the parsed x-machines extension data as slice of strings

func (*MachinesSource) DecodeMapstructure added in v0.10.0

func (m *MachinesSource) DecodeMapstructure(value any) error

DecodeMapstructure implements custom decoding for multiple input types

type Plan added in v0.18.0

type Plan struct {
	Volumes  []*operation.CreateVolumeOperation
	Services []*deploy.ServicePlan
}

Plan holds the compose-level deployment plan with volume and service operations.

func (*Plan) Execute added in v0.18.0

func (p *Plan) Execute(ctx context.Context, cli operation.Client) error

Execute runs all volume operations followed by all service operations.

func (*Plan) Format added in v0.18.0

func (p *Plan) Format() string

Format renders the entire deployment plan as a styled tree with a summary footer.

func (*Plan) IsEmpty added in v0.18.0

func (p *Plan) IsEmpty() bool

IsEmpty returns true if the plan has no volume or service operations.

type PortsSource

type PortsSource []string

type PreDeployHook added in v0.18.0

type PreDeployHook struct {
	Command     types.ShellCommand      `yaml:"command" json:"command"`
	Environment types.MappingWithEquals `yaml:"environment,omitempty" json:"environment,omitempty"`
	Privileged  *bool                   `yaml:"privileged,omitempty" json:"privileged,omitempty"`
	Timeout     *types.Duration         `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	User        string                  `yaml:"user,omitempty" json:"user,omitempty"`
}

PreDeployHook represents the parsed x-pre_deploy extension config.

func (*PreDeployHook) Validate added in v0.18.0

func (p *PreDeployHook) Validate() error

Validate checks that the pre-deploy hook configuration is valid.

Jump to

Keyboard shortcuts

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