compose

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 16 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 materializes a resolved model into a Docker Compose project: docker-compose.yml, the certificate and configuration files they mount, and a .env file in dotenv mode.

The same bundle drives `bb up` (written to .bb/runtime/) and `bb export compose` (written anywhere, runnable without bb).

Index

Constants

View Source
const (
	ComposeFile = "docker-compose.yml"
	EnvFile     = ".env"
)

File names inside a bundle.

View Source
const (
	LabelExperiment = "breadboard.experiment"
	LabelService    = "breadboard.service"
	LabelKind       = "breadboard.kind"
	// LabelExperimentID tells experiments with the same name apart.
	LabelExperimentID = "breadboard.experiment-id"
	// LabelConfigHash changes whenever a service's mounted files change, so
	// compose recreates the container and it reads the new files.
	LabelConfigHash = "breadboard.config-hash"
	// LabelCapture is set on a pod holder and every container that joins
	// its namespace: transparent while netinit's traffic rules live in the
	// namespace, off otherwise. The rules die only with the namespace, so a
	// change of mode must recreate the holder and every joiner.
	LabelCapture = "breadboard.capture"
)

Labels set on every container, network, and volume.

View Source
const (
	HostCertPath = "tls/bb-host/host.crt"
	HostKeyPath  = "tls/bb-host/host.key"
)

Paths of the host router's host certificate inside a bundle. Only the router mounts them.

View Source
const (
	KindPod  = "pod"
	KindInit = "init"
)

Kinds of the containers a pod adds. They carry the breadboard.kind label but are not services of their own: status folds the holder into its app.

View Source
const DefaultNetwork = "default"

DefaultNetwork is the experiment's shared network. It has a fixed subnet and every container a fixed address only in a lab with a transparent pod, whose egress policy allows destinations by address.

Variables

This section is empty.

Functions

func DynamicRange

func DynamicRange(p netip.Prefix) netip.Prefix

DynamicRange is the part of the default network's subnet Docker may hand out to containers without a fixed address (such as a debugging container attached by hand): the upper half, clear of fixed addresses.

func InstanceSegmentAddress

func InstanceSegmentAddress(p netip.Prefix, instance int) netip.Addr

InstanceSegmentAddress is an app instance's static address on its private segment: SegmentAddress for a single instance or replica 1, then one up per replica.

func RelPath

func RelPath(base, target string) (string, error)

RelPath returns target relative to base, both absolute, with forward slashes. Paths inside base start with ./ so compose reads them as bind mounts rather than volume names.

func SegmentAddress

func SegmentAddress(p netip.Prefix) netip.Addr

SegmentAddress is a target's static address on its segment: the tenth host, clear of the gateway.

Types

type Bundle

type Bundle struct {
	Files []File
}

Bundle is a complete compose project.

func Render

func Render(in Input) (*Bundle, error)

Render builds the bundle.

func (*Bundle) File

func (b *Bundle) File(p string) (File, bool)

File returns a file by path.

type Cert

type Cert struct {
	Cert []byte
	Key  []byte
}

Cert is a service's certificate and key, PEM.

type EnvGroup

type EnvGroup struct {
	Service   string
	Title     string // the service's catalog title, or the sidecar type's
	Plaintext bool
	Reason    string
	Sidecar   bool
	Vars      []catalog.EnvVar
	// Rewrites names the variables of earlier groups a sidecar set in
	// place (a pooler pointing DATABASE_URL at itself).
	Rewrites []string
}

EnvGroup is a block of an app's environment: Breadboard's own variables (Service empty), one used service's env contract, or the variables a sidecar adds (Sidecar set).

func AppEnv

func AppEnv(m *model.Model, svc *model.Service, ref func(service string) func(key string) string, subnets map[string]netip.Prefix) ([]EnvGroup, error)

AppEnv is the environment an app instance receives, in order: Breadboard's own variables first, then one group per edge, then one per sidecar that adds or rewrites variables. When two used services share a variable name, the later one is prefixed with its service name. A sidecar may rewrite a variable in place (a pooler pointing DATABASE_URL at itself); its group then lists the name in Rewrites. ref resolves a service's secrets (values, or ${VAR} references in dotenv mode).

type File

type File struct {
	Path string // slash-separated, relative to the bundle directory
	Data []byte
	Mode os.FileMode
}

File is one generated file.

type Input

type Input struct {
	Model *model.Model
	// ExperimentID is the project's id from .bb/state.json.
	ExperimentID string
	Secrets      *secrets.Materializer
	CA           []byte // Breadboard CA certificate, PEM
	TrustBundle  []byte // CA plus public roots, PEM
	Certs        map[string]Cert
	// Subnets holds the allocated subnet of every private segment, and of
	// the default network under DefaultNetwork when the lab has static
	// addressing.
	Subnets map[string]netip.Prefix
	// Addresses are the static addresses on the default network, by the
	// service that owns the network (an infra service, an app instance,
	// or a pod holder). Set together with Subnets[DefaultNetwork].
	Addresses map[string]netip.Addr
	// AppDir returns an app's source directory relative to the bundle
	// directory, with forward slashes.
	AppDir func(app string) string
	// ReadFile reads a file named relative to experiment.yaml, such as an
	// Envoy sidecar's user-owned config. Its content is copied into the
	// bundle, so an edit changes the sidecar's config hash and exports
	// stay self-contained.
	ReadFile func(path string) ([]byte, error)
	// Header is the comment written at the top of each compose file.
	Header string
	// HostCert is the host router's certificate from the host CA, and
	// HostPort the 127.0.0.1 port its HTTPS entrypoint is published on.
	// Both are set exactly when the model has a host router.
	HostCert *Cert
	HostPort int
}

Input is everything the materializer needs besides the model.

Jump to

Keyboard shortcuts

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