Documentation
¶
Overview ¶
Package runtime runs experiments through the docker and docker compose CLIs. The core reaches it through an interface, so core tests use a fake.
Index ¶
- Variables
- type Compose
- func (c *Compose) Available(ctx context.Context) error
- func (c *Compose) Build(ctx context.Context, p Project, services []string) error
- func (c *Compose) Containers(ctx context.Context, experiment string) ([]Container, error)
- func (c *Compose) Down(ctx context.Context, p Project, volumes bool) error
- func (c *Compose) Exec(ctx context.Context, experiment, service string, cmd []string) ([]byte, error)
- func (c *Compose) ImageUser(ctx context.Context, p Project, service string) (ImageUser, error)
- func (c *Compose) Logs(ctx context.Context, p Project, services []string, follow bool, tail int) iter.Seq2[LogLine, error]
- func (c *Compose) Owners(ctx context.Context, experiment string) ([]string, error)
- func (c *Compose) PublishedPorts(ctx context.Context) ([]PublishedPort, error)
- func (c *Compose) RemoveOwned(ctx context.Context, experimentID string, volumes bool) error
- func (c *Compose) Stats(ctx context.Context, ids []string) (map[string]Usage, error)
- func (c *Compose) StatsStream(ctx context.Context) iter.Seq2[Sample, error]
- func (c *Compose) Subnets(ctx context.Context) ([]Network, error)
- func (c *Compose) Up(ctx context.Context, p Project) error
- type Container
- type ImageUser
- type LogLine
- type Network
- type Project
- type PublishedPort
- type Sample
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ErrSubnetTaken = errors.New("a network's subnet is taken by another network")
ErrSubnetTaken means Docker refused to create a network because its subnet overlaps a network that already exists. Another process (a second bb, or any docker client) created that network after the subnet was chosen, so choosing again sees it and avoids it.
var ErrUserUnresolved = errors.New("cannot resolve the image's user to a uid")
ErrUserUnresolved means an image's USER is a name the image cannot map to a numeric uid (it has no passwd entry, or no id command to ask).
Functions ¶
This section is empty.
Types ¶
type Compose ¶
type Compose struct {
// Bin is the docker executable; empty means "docker" on PATH.
Bin string
}
Compose implements the runtime with the docker CLI.
func (*Compose) Containers ¶
Containers lists an experiment's containers by label.
func (*Compose) Down ¶
Down stops and removes the project's containers and networks, and its volumes when volumes is true. It works without compose files too.
func (*Compose) Exec ¶
func (c *Compose) Exec(ctx context.Context, experiment, service string, cmd []string) ([]byte, error)
Exec runs a command in the running container of an experiment's service and returns its standard output. It is how the web UI's explorers read service data with each service's own tools (ADR-0012).
func (*Compose) ImageUser ¶
ImageUser resolves the uid a built service image starts as: Config.User from docker image inspect (empty means root), a number as is, and a name through `id -u <name>` run in the image with no network.
func (*Compose) Logs ¶
func (c *Compose) Logs(ctx context.Context, p Project, services []string, follow bool, tail int) iter.Seq2[LogLine, error]
Logs streams service output. With follow it runs until ctx is cancelled.
func (*Compose) Owners ¶
Owners lists the distinct experiment ids on containers, networks, and volumes labeled for experiment. An empty string means an unlabeled resource.
func (*Compose) PublishedPorts ¶
func (c *Compose) PublishedPorts(ctx context.Context) ([]PublishedPort, error)
PublishedPorts lists the fixed host ports of every container, running or not: a stopped container takes its ports back when it starts.
func (*Compose) RemoveOwned ¶
RemoveOwned removes networks, and volumes when volumes is true, labeled with experimentID. Compose only removes what the current compose files declare, so this catches resources of services or segments removed since an earlier up. Matching on the experiment id, not the name, leaves a same-named experiment from another directory alone. Run it after Down.
func (*Compose) StatsStream ¶
StatsStream runs one streaming docker stats over every running container, a container started later included, and yields each row as docker refreshes it (about once a second) until ctx is cancelled or the command ends. It costs one process however many readers use the result.
type Container ¶
type Container struct {
ID string
Service string
Kind string
Image string
State string // created, running, restarting, exited, ...
Health string // starting, healthy, unhealthy, or empty without a health check
ExitCode int
OOMKilled bool
StartedAt time.Time
// RestartCount is how many times the restart policy has restarted it.
RestartCount int
}
Container is one container's state.
type ImageUser ¶
type ImageUser struct {
Image string // the image name compose gave the service
User string // Config.User as written in the image: empty, a uid, or a name, maybe with :group
UID int
}
ImageUser is the user a service's built image starts its process as.
type Network ¶
type Network struct {
Name string
Subnet netip.Prefix
ExperimentID string
// IPRange is the part of Subnet Docker hands out dynamically; zero
// when the network has none (the whole subnet).
IPRange netip.Prefix
}
Network is a docker network's subnet and the Breadboard experiment id that owns it, if any.
type Project ¶
type Project struct {
Name string // compose project name, bb-<experiment>
Dir string // directory holding the compose files
Files []string // compose files, absolute, in -f order
}
Project identifies a compose project on disk.
type PublishedPort ¶
type PublishedPort struct {
HostIP string
HostPort int
ExperimentID string // empty for a container no experiment owns
Service string
// Running reports whether the container runs and so holds the port
// now; a stopped container only reserves it.
Running bool
}
PublishedPort is a host port a container publishes (or will publish when it starts), with the experiment and service labels of its owner.