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 ¶
const IngressNetwork = "mutti-ingress"
IngressNetwork is the key of mutti's ingress network in the override.
const LoopbackIP = "127.0.0.1"
LoopbackIP is where mutti publishes ports, so dev environments are not reachable from the LAN.
Variables ¶
var CancelGrace = 30 * time.Second
CancelGrace is how long Compose may take to stop after a cancel before it is killed.
var ErrNotInstalled = errors.New("docker compose is not installed")
ErrNotInstalled means docker or its Compose plugin is missing.
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 ¶
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 ¶
BuildxVersion returns `docker buildx version`.
func (CLI) Config ¶
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.
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 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 ¶
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 ¶
MustParseVersion is ParseVersion for constants.
func ParseVersion ¶
ParseVersion reads versions like "2.24.4", "v2.29.1-desktop.1" or "5.5.1".
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. |