runtime

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: 15 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 runtime runs experiments through the docker and docker compose CLIs. The core reaches it through an interface, so core tests use a fake.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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 New

func New() *Compose

New returns a runtime using docker from PATH.

func (*Compose) Available

func (c *Compose) Available(ctx context.Context) error

Available checks that the docker daemon and the compose plugin respond.

func (*Compose) Build

func (c *Compose) Build(ctx context.Context, p Project, services []string) error

Build builds the images of the given services without starting anything.

func (*Compose) Containers

func (c *Compose) Containers(ctx context.Context, experiment string) ([]Container, error)

Containers lists an experiment's containers by label.

func (*Compose) Down

func (c *Compose) Down(ctx context.Context, p Project, volumes bool) error

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

func (c *Compose) ImageUser(ctx context.Context, p Project, service string) (ImageUser, error)

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

func (c *Compose) Owners(ctx context.Context, experiment string) ([]string, error)

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

func (c *Compose) RemoveOwned(ctx context.Context, experimentID string, volumes bool) error

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) Stats

func (c *Compose) Stats(ctx context.Context, ids []string) (map[string]Usage, error)

Stats samples CPU and memory use once for running containers.

func (*Compose) StatsStream

func (c *Compose) StatsStream(ctx context.Context) iter.Seq2[Sample, error]

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.

func (*Compose) Subnets

func (c *Compose) Subnets(ctx context.Context) ([]Network, error)

Subnets lists every docker network subnet on this host with its owner.

func (*Compose) Up

func (c *Compose) Up(ctx context.Context, p Project) error

Up builds app images and starts every service in the background.

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 LogLine

type LogLine struct {
	Service string
	Text    string
}

LogLine is one line of container output.

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.

type Sample

type Sample struct {
	ID    string
	Usage Usage
}

Sample is one container's usage from a stats stream.

type Usage

type Usage struct {
	CPUPercent  float64
	MemoryBytes uint64
	MemoryLimit uint64
}

Usage is a container's live resource use.

Jump to

Keyboard shortcuts

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