stack

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: 20 Imported by: 0

Documentation

Overview

Package stack derives everything about a stack that follows from its worktree and its compose file without asking Docker: names, labels, routes and the override siding writes. Everything here is a pure function.

Index

Constants

View Source
const (
	LabelRepo     = "dev.siding.repo"
	LabelBranch   = "dev.siding.branch"
	LabelWorktree = "dev.siding.worktree"
	LabelMachine  = "dev.siding.machine"
	LabelAgent    = "dev.siding.agent"
	LabelGitDir   = "dev.siding.gitdir"
	LabelBudget   = "dev.siding.budget"
	LabelBuilds   = "dev.siding.builds"
	LabelIdle     = "dev.siding.idle"
	LabelShared   = "dev.siding.shared"
	// LabelHostAlias, on siding-proxy, is what host.docker.internal resolves to in it.
	LabelHostAlias = "dev.siding.host-alias"
	LabelRoute     = "dev.siding.route"
	LabelPort      = "dev.siding.port"

	// LabelProject is Compose's own label naming a container's project.
	LabelProject = "com.docker.compose.project"
	// LabelService is Compose's own label naming a container's service.
	LabelService = "com.docker.compose.service"
)

Labels siding puts on what it creates. The conventions in CLAUDE.md list them.

View Source
const OverrideFile = ".siding/override.yml"

OverrideFile is where siding writes the override, relative to the worktree.

View Source
const ProxyNetworkKey = "siding_proxy"

ProxyNetworkKey is the key of the proxy network in the override. It differs from every network name a user is likely to pick, so the override never redefines one of theirs.

View Source
const ServiceHeader = "X-Siding-Service"

ServiceHeader is the response header every siding router adds, naming <project>/<service>. A response that carries it came from the service, not from the proxy (design D9).

Variables

This section is empty.

Functions

func DotEnvValues

func DotEnvValues(content string) []string

DotEnvValues returns the values a .env file defines, read with Compose's rules: KEY=VALUE per line, an optional "export ", comments starting with #, single or double quotes.

func MachineID

func MachineID(osID, home string) (string, error)

MachineID returns the stable id for dev.siding.machine: a one-way hash of the operating system's machine id, so the raw id never appears in a label. Without one it uses, and on first use writes, a random id in <home>/.siding/machine-id.

func OSMachineID

func OSMachineID() string

OSMachineID returns the operating system's machine id: /etc/machine-id on Linux, the platform UUID on macOS, or "" when there is none.

func Override

func Override(p *compose.Project, id Identity, routes []Route, network string) []byte

Override renders .siding/override.yml: no published ports, siding's labels on every container, network and volume of the project, and for every route the proxy network and the Traefik labels. network is the proxy's Docker network.

func Slug

func Slug(name string) string

Slug turns a name into lowercase letters, digits and single dashes, at most 40 characters.

Types

type Identity

type Identity struct {
	Repo     string // repository name, e.g. shop
	Branch   string // branch name, e.g. feature/login
	Worktree string // absolute path of the worktree
	Machine  string // stable machine id
	Agent    string // optional agent name
	// GitDir is the repository's common git directory, so gc can still ask git about the branch
	// when the worktree is gone.
	GitDir string
}

Identity names one stack.

func FromLabels

func FromLabels(l map[string]string) Identity

FromLabels reads an Identity back from a container's labels.

func (Identity) BranchSlug

func (id Identity) BranchSlug() string

BranchSlug is the slug of the branch.

func (Identity) ContainerLabels

func (id Identity) ContainerLabels() map[string]string

ContainerLabels are the labels of the stack's containers: Labels plus the git directory and the agent, if any. Those two stay off networks and volumes: they are new in v0.2 or change between ups, and Compose recreates a network whose labels changed.

func (Identity) Host

func (id Identity) Host() string

Host is the stack's host, <repo-slug>.<branch-slug>.localhost.

func (Identity) Labels

func (id Identity) Labels() map[string]string

Labels are the labels of the stack's networks and volumes. They never change between two ups of one project: Compose recreates a network whose labels changed.

func (Identity) Project

func (id Identity) Project() string

Project is the Compose project, <repo-slug>-<branch-slug>.

func (Identity) RepoSlug

func (id Identity) RepoSlug() string

RepoSlug is the slug of the repository name.

func (Identity) ServiceHost

func (id Identity) ServiceHost(service string) string

ServiceHost is the host of one service, <service>.<repo-slug>.<branch-slug>.localhost.

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor replaces known secret values in log lines with ***.

func NewRedactor

func NewRedactor(values ...string) *Redactor

NewRedactor redacts the given values except short ones, numbers and booleans.

func (*Redactor) Line

func (r *Redactor) Line(line string) string

Line returns line with every known value replaced by ***.

func (*Redactor) Lines

func (r *Redactor) Lines(lines []string) []string

Lines redacts every line.

type Route

type Route struct {
	Service string
	// Port is the container port the proxy sends requests to.
	Port int
	// Path is the service's path on the stack's host ("/" for the root), or "" when it has
	// only its service host.
	Path string
}

Route says how the proxy reaches one HTTP service.

func Find

func Find(routes []Route, service string) (Route, bool)

Find returns the route of a service.

func Routes

func Routes(p *compose.Project) (routes []Route, warnings []string, err error)

Routes derives the routing table of a project: one Route per HTTP service that is not hidden, sorted by service. Warnings name services siding cannot route.

Jump to

Keyboard shortcuts

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