compose

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package compose runs docker compose and reads the normalised configuration it prints. siding never parses a compose file itself: interpolation, profiles, include and extends are Compose's business.

Index

Constants

View Source
const MinVersion = "2.24"

MinVersion is the oldest Compose siding works with: `ports: !reset []` needs 2.24.

Variables

View Source
var FileNames = []string{"compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"}

FileNames are the compose files Compose itself looks for, in its order.

Functions

func AtLeast

func AtLeast(have, want string) bool

AtLeast compares dotted version numbers: AtLeast("2.24.1", "2.24") is true.

func FindFile

func FindFile(dir, top, file string) (string, error)

FindFile returns the compose file of a worktree: file when given (relative to dir), else the first of FileNames in top.

Types

type CLI

type CLI struct {
	// Binary is the docker executable; empty means "docker".
	Binary string
	// contains filtered or unexported fields
}

CLI runs docker compose. Its zero value uses "docker" from PATH.

func (*CLI) Config

func (c *CLI) Config(ctx context.Context, inv Invocation) ([]byte, error)

Config returns the output of docker compose config --format json.

func (*CLI) Run

func (c *CLI) Run(ctx context.Context, inv Invocation, args []string, stdout, stderr io.Writer) error

Run runs docker compose with args, streaming its output. On failure the error carries the last lines Compose printed on stderr.

func (*CLI) UnresolvedConfig

func (c *CLI) UnresolvedConfig(ctx context.Context, inv Invocation) ([]byte, error)

UnresolvedConfig prints the normalised configuration without reading env files, so it succeeds even when an env_file is missing; EnvFiles reads their paths from it.

type EnvFile

type EnvFile struct {
	Path     string
	Required bool
}

EnvFile is an env_file of a service: an absolute path, and whether Compose needs it.

func EnvFiles

func EnvFiles(data []byte) ([]EnvFile, error)

EnvFiles returns the env files of every service in the output of UnresolvedConfig, each path once, in order. An entry without "required" is required, as Compose has it.

type Invocation

type Invocation struct {
	// Dir is the working directory; Compose's project directory is the first file's.
	Dir     string
	Project string
	// Files are passed as -f, in order. Without files, Compose acts on the project by name.
	Files []string
}

Invocation names a Compose project and the files it is made of.

type Project

type Project struct {
	Name     string
	Services map[string]Service
	Networks map[string]Resource
	Volumes  map[string]Resource
}

Project is the part of a normalised compose configuration siding needs.

func ParseConfig

func ParseConfig(data []byte) (*Project, error)

ParseConfig reads the output of docker compose config --format json.

func (*Project) ServiceNames

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

ServiceNames returns the service names in the order Compose prints them (sorted).

type Resource

type Resource struct {
	Name     string
	External bool
	Labels   map[string]string
}

Resource is a top-level network or volume.

type Service

type Service struct {
	// Ports are the distinct container ports from ports (targets) and expose, ascending.
	Ports []int
	// Published are the ports the compose file publishes on the host.
	Published   []int
	Labels      map[string]string
	Networks    []string // keys of the service's networks, sorted
	NetworkMode string
	Environment map[string]string

	ContainerName string
	// Binds are the absolute host paths of the service's bind mounts.
	Binds []string
	// Volumes are the keys of the named volumes the service mounts.
	Volumes []string
	// Healthcheck is set when the compose file gives the service a healthcheck. One from the
	// image is not visible here.
	Healthcheck bool
	// MemoryLimit is deploy.resources.limits.memory, else mem_limit, in bytes; 0 for none.
	MemoryLimit int64
	// Replicas is deploy.replicas, else scale, else 1.
	Replicas int
	// Build is set when the service is built from a Dockerfile.
	Build bool
}

Service is one service of a Project.

type TailBuffer

type TailBuffer struct {
	Max int
	// contains filtered or unexported fields
}

TailBuffer keeps the last Max lines written to it.

func (*TailBuffer) Lines

func (t *TailBuffer) Lines() []string

Lines returns the kept lines, the unfinished last one included.

func (*TailBuffer) String

func (t *TailBuffer) String() string

func (*TailBuffer) Write

func (t *TailBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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