compose

package
v0.46.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compose is the Docker Compose invocation.

The one non-obvious rule, and the reason this file exists instead of an inline string:

`up` passes only the SELECTED profiles. `down` passes EVERY profile in the spec.

Compose treats a service whose profile is not enabled as absent. So a stack brought up with `--profile backend` and torn down with the same flag leaves the *other* profiles' resources behind — most visibly the project's default network, which then accumulates one dead `<stack>_default` per PR forever. Enumerating every profile on `down` costs nothing (passing a profile with no matching service is a no-op) and is the difference between a clean box and a slow leak.

Second rule: `down -v` removes containers, volumes and networks — but NOT images. Per-stack images are removed by an explicit axis (see examples/), not by compose.

Third, since 0.26.0: every function here DISPATCHES on `spec.compose.orchestrator`. Under `swarm` the same verbs become `docker stack deploy` / `docker stack rm` / `docker service logs` / `docker stack ps` (built in swarm), and the file passed is the converted one. The callers in stack and api do not know which; that is the point of keeping one seam.

`sleep` is the fourth verb: `down` WITHOUT `-v` (swarm: `stack rm`, which never touches volumes). The containers and networks go, the data stays, the axes are not consulted — a sleeping preview is one that can be brought back by `up` alone.

Every verb returns an error only when the derived compose file could not be produced (a *spec.Error from autolabel — the TS threw the same); a command that ran and failed is a Result with OK false, never an error.

Logging: on a host that ships logs to Loki, `up` checks the plugin before it deploys anything autolabel gave the loki driver. Under compose a missing or disabled plugin fails every logged container's create with dockerd's error, which names the driver and not the fix — so the check answers a Result with OK false (the rule above) and `up` never runs. Under swarm the scheduler keeps logged tasks off a node without the plugin, so the deploy runs and the log names those nodes; if none qualifies, readiness times out and those lines are the only thing saying why. The install line always goes to `note`, never into the Result: stack.Up keeps the first 300 runes of the Result's first line, and the line alone is longer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeDown

func ComposeDown(st *spec.Stack, r exec.Runner) (exec.Result, error)

ComposeDown is `compose down -v` / `stack rm` plus the labelled volumes.

func ComposeEnv

func ComposeEnv(st *spec.Stack, extra map[string]string) map[string]string

ComposeEnv is the environment every compose subcommand runs with.

The wildcard-subdomain rules go in here rather than only into `up` because compose interpolates the compose FILE on every subcommand. A label that reads `${PSTACK_WILD_BACKEND}` would otherwise make `down`, `logs` and `ps` warn about an unset variable and substitute an empty string — and on `down` that means compose is reasoning about a *differently-labelled* project than the one `up` created.

func ComposeLogs

func ComposeLogs(st *spec.Stack, r exec.Runner, tail float64, service string, opts LogsOptions) (exec.Result, error)

ComposeLogs is recent logs for a stack. `--no-color` because the output is rendered in a browser, where ANSI escapes are noise, and `--tail` because an unbounded fetch on a chatty stack would stream megabytes into a tab. Every profile is enabled for the same reason `down` enables them: compose treats an unenabled profile's services as absent, so their logs would silently be missing.

service is one compose SERVICE to read, instead of the whole stack. On a stack with a chatty sidecar the interleaved output is unreadable and the interesting lines are already past the tail, so narrowing is often the difference between finding the error and not. Shell-quoted, because it arrives from a query parameter and is interpolated into a command.

opts is the rest of what `docker compose logs` can tell you, which this used to throw away. `timestamps` is the one that matters most: without it a log line cannot be lined up against a deploy, a healthcheck flap or another service's line, and "when did this start" is unanswerable from the page. `since`/`until` are what make a long-lived container readable at all — a tail of 2000 on a service that logs every request is 2000 lines of the last four minutes.

func ComposePs

func ComposePs(st *spec.Stack, r exec.Runner) (exec.Result, error)

ComposePs is `compose ps` / `stack ps`.

func ComposeSleep

func ComposeSleep(st *spec.Stack, r exec.Runner) (exec.Result, error)

ComposeSleep puts the project to sleep: containers and networks go, VOLUMES STAY. That is the whole difference from ComposeDown, and it is a separate function rather than a flag so the `down -v` the leak tests assert on cannot be weakened by a default.

func ComposeUp

func ComposeUp(st *spec.Stack, r exec.Runner, extraEnv map[string]string, note func(string)) (exec.Result, error)

ComposeUp is `compose up` / `stack deploy`. note receives the job-log lines: what the swarm conversion changed, which services kept their own `logging:`, and what the loki plugin check found. nil drops them.

func Shq

func Shq(v string) string

Shq single-quotes a value for bash — see swarm.Shq, where it lives because of the import graph.

Types

type LogsCommand

type LogsCommand struct {
	Cmd string
	Env map[string]string
}

LogsCommand is a `logs` command line and the environment it needs.

func ComposeLogsCommand

func ComposeLogsCommand(st *spec.Stack, r exec.Runner, tail float64, service string, opts LogsOptions) (*LogsCommand, error)

ComposeLogsCommand is the `logs` command line and the environment it needs, without running it. nil when the spec has no compose section.

Split out because FOLLOWING logs cannot go through Runner: that buffers a process to completion, and `--follow` never completes. The SSE route spawns this itself and streams the pipe. Both paths building their command here is what stops the followed stream and the fetched one disagreeing about which project, profiles or files they are reading.

tail is a JS number (the API accepts and echoes `?tail=1.5`), truncated here. service "" reads the whole stack.

type LogsOptions

type LogsOptions = swarm.LogsOptions

LogsOptions is the rest of what `logs` can be asked for.

Jump to

Keyboard shortcuts

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