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 ¶
const ( ComposeFile = "docker-compose.yml" EnvFile = ".env" )
File names inside a bundle.
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.
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.
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.
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 ¶
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 ¶
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.
Types ¶
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.