compose

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package compose runs the user's installed `docker compose` CLI. mutti never reimplements Compose; it decides which files, project name and environment Compose gets.

Index

Constants

View Source
const IngressNetwork = "mutti-ingress"

IngressNetwork is the key of mutti's ingress network in the override.

View Source
const LoopbackIP = "127.0.0.1"

LoopbackIP is where mutti publishes ports, so dev environments are not reachable from the LAN.

Variables

View Source
var CancelGrace = 30 * time.Second

CancelGrace is how long Compose may take to stop after a cancel before it is killed.

View Source
var ErrNotInstalled = errors.New("docker compose is not installed")

ErrNotInstalled means docker or its Compose plugin is missing.

View Source
var Features = []Feature{
	{Name: "up --wait", Since: MustParseVersion("2.1.1"), Required: true, Use: "mutti up waits for healthchecks"},
	{Name: "include", Since: MustParseVersion("2.20.0"), Use: "projects that split Compose files with include"},
	{Name: "watch", Since: MustParseVersion("2.22.0"), Use: "file sync with docker compose watch"},
	{Name: "!reset / !override", Since: MustParseVersion("2.24.4"), Required: true, Use: "mutti's override replaces published ports"},
}

Features lists every Compose capability mutti depends on, oldest first.

Functions

func RenderOverride

func RenderOverride(m *Model, o Override) []byte

RenderOverride returns the Compose override for m, or nil if nothing needs overriding.

  • Published ports move to random host ports on loopback, so two instances of one project never fight over a host port; FixedPorts get their fixed one.
  • Services join the ingress network next to the networks they already have.
  • Labels are added.

Types

type BindOpts

type BindOpts struct {
	CreateHostPath bool   `json:"create_host_path,omitempty"`
	Propagation    string `json:"propagation,omitempty"`
	SELinux        string `json:"selinux,omitempty"`
}

BindOpts are the options of a bind mount.

type CLI

type CLI struct {
	Docker  string   // docker binary; empty means "docker" from PATH
	Environ []string // base environment; nil means the current process environment
}

CLI runs the docker binary's compose plugin.

func (CLI) BuildxVersion

func (c CLI) BuildxVersion(ctx context.Context) (string, error)

BuildxVersion returns `docker buildx version`.

func (CLI) Config

func (c CLI) Config(ctx context.Context, s Spec) (*Model, error)

Config returns the fully resolved model of a project with all profiles enabled, so every service is known no matter which profiles a later command uses.

func (CLI) Run

func (c CLI) Run(ctx context.Context, s Spec, streams IO, args ...string) (int, error)

Run runs a Compose command attached to streams.

func (CLI) Version

func (c CLI) Version(ctx context.Context) (Version, error)

Version returns the installed Compose version.

type Feature

type Feature struct {
	Name     string
	Since    Version
	Required bool   // mutti refuses to run without it
	Use      string // what mutti or projects need it for
}

Feature is a Compose capability mutti relies on or uses when present.

type IO

type IO struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

IO are the streams a command is attached to.

type Model

type Model struct {
	Name     string             `json:"name"`
	Services map[string]Service `json:"services"`
	XMutti   json.RawMessage    `json:"x-mutti,omitempty"`
}

Model is the part of `docker compose config --format json` mutti reads.

func (*Model) ServiceNames

func (m *Model) ServiceNames() []string

ServiceNames returns the service names, sorted.

type Override

type Override struct {
	// Network is the name of the instance's ingress network, which mutti creates and the router
	// joins. Every service that can join networks is attached to it. Empty means none.
	Network string
	// Labels are extra container labels, per service.
	Labels map[string]map[string]string
	// CommonLabels are added to every service.
	CommonLabels map[string]string
	// FixedPorts publish container ports on fixed host ports: service -> container port -> host
	// port. Ports the service does not publish yet are added.
	FixedPorts map[string]map[uint16]uint16
	// Binds replace bind mounts of a service, matched by target, e.g. with sources translated to
	// paths on the Docker host.
	Binds map[string][]VolumeMount
}

Override is what mutti adds on top of the user's Compose files.

type Port

type Port struct {
	Target    uint16 `json:"target"`
	Published string `json:"published,omitempty"`
	HostIP    string `json:"host_ip,omitempty"`
	Protocol  string `json:"protocol,omitempty"`
}

Port is a port entry in Compose's long syntax.

type Runner

type Runner interface {
	Version(ctx context.Context) (Version, error)
	Config(ctx context.Context, s Spec) (*Model, error)
	// Run runs `docker compose <global flags> <args>` and returns its exit code. err is only set
	// when Compose could not be started at all.
	Run(ctx context.Context, s Spec, streams IO, args ...string) (exitCode int, err error)
	// BuildxVersion returns the version line of the buildx plugin Compose builds with.
	BuildxVersion(ctx context.Context) (string, error)
}

Runner runs Compose commands. CLI is the real implementation.

type Service

type Service struct {
	Image       string                     `json:"image,omitempty"`
	Ports       []Port                     `json:"ports,omitempty"`
	Expose      []string                   `json:"expose,omitempty"`
	Profiles    []string                   `json:"profiles,omitempty"`
	Labels      map[string]string          `json:"labels,omitempty"`
	Networks    map[string]json.RawMessage `json:"networks,omitempty"`
	NetworkMode string                     `json:"network_mode,omitempty"`
	Volumes     []VolumeMount              `json:"volumes,omitempty"`
}

Service is one service of the model.

type Spec

type Spec struct {
	Project  string   // Compose project name (= instance name)
	Dir      string   // project directory
	Files    []string // Compose files in merge order
	Profiles []string // profiles to enable; "*" enables all
	Env      []string // extra environment, e.g. MUTTI_* interpolation variables
}

Spec selects the Compose project a command runs against.

type Version

type Version struct{ Major, Minor, Patch int }

Version is a Compose release version.

func MinVersion

func MinVersion() Version

MinVersion is the oldest Compose mutti runs with: the newest Since of all required features.

func MustParseVersion

func MustParseVersion(s string) Version

MustParseVersion is ParseVersion for constants.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion reads versions like "2.24.4", "v2.29.1-desktop.1" or "5.5.1".

func (Version) Has

func (v Version) Has(f Feature) bool

Has reports whether version v has feature f.

func (Version) Less

func (v Version) Less(o Version) bool

Less reports whether v is older than o.

func (Version) String

func (v Version) String() string

type VolumeMount

type VolumeMount struct {
	Type     string    `json:"type"` // bind, volume, tmpfs, ...
	Source   string    `json:"source,omitempty"`
	Target   string    `json:"target"`
	ReadOnly bool      `json:"read_only,omitempty"`
	Bind     *BindOpts `json:"bind,omitempty"`
}

VolumeMount is a mount of a service in Compose's long syntax.

Directories

Path Synopsis
Package composetest provides a compose.Runner that simulates `docker compose` on top of the in-memory engine from enginetest.
Package composetest provides a compose.Runner that simulates `docker compose` on top of the in-memory engine from enginetest.

Jump to

Keyboard shortcuts

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