docker

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package docker implements the Driver interface by running each ephemeral runner as a container via the Docker or Podman CLI (autodetected, or pinned via Options.Runtime — the two are drop-in for the subcommands used here). It is deliberately much thinner than the Tart driver: no VM clone, no boot wait, no SSH. A slot is one `run -d` of the runner image launched with `run.sh --jitconfig`, status is one `inspect`, teardown is one `rm -f`.

Unlike Tart (Apple caps macOS guests at 2 per host), container capacity is bounded only by host CPU/memory, so Capacity is purely config-driven.

Containers carry the label ushr=runner so List() can find ours and reconcile orphans on agent restart without touching unrelated containers on the host.

Index

Constants

View Source
const (
	DefaultEntrypoint          = "/home/runner/run.sh"
	DefaultCapacity            = 4
	DefaultBuildkitImage       = "moby/buildkit:buildx-stable-1"
	DefaultBuildCacheGB        = 20
	DefaultBuildCacheIdleHours = 168 // reap a repo's builder after a week idle

	// DefaultMinFreeGB is the free-space floor under which the agent stops
	// accepting work. Containers are thin next to a VM clone, but one job's
	// image pulls and build cache still land in the same data root.
	DefaultMinFreeGB = 25
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver is the Docker implementation of driver.Driver.

func New

func New(opts Options) *Driver

New constructs a Driver. Empty Options fields fall back to Default*.

func (*Driver) Capacity

func (d *Driver) Capacity() int

func (*Driver) Destroy

func (d *Driver) Destroy(ctx context.Context, h driver.SlotHandle) error

Destroy force-removes the container. Treated as success if it is already gone.

func (*Driver) DiskPath

func (d *Driver) DiskPath(ctx context.Context) string

DiskPath resolves the runtime's data root — images, container layers and the build cache all live there. Docker and podman name it differently in `info`, and a daemon that is down at boot must not poison the answer, so only a successful lookup is cached.

func (*Driver) List

func (d *Driver) List(ctx context.Context) ([]driver.SlotHandle, error)

List returns every container we own (running or exited) for orphan reaping.

func (*Driver) Maintain

func (d *Driver) Maintain(ctx context.Context)

Maintain runs the driver's upkeep until ctx is cancelled. It re-pulls the runner image because `run` never refreshes a local tag, and GitHub rejects a runner whose version it has deprecated.

func (*Driver) Provision

func (d *Driver) Provision(ctx context.Context, req driver.ProvisionRequest) (driver.SlotHandle, error)

Provision starts a detached runner container. The JIT config carries the runner name, labels, and registration — the controller already baked those in via GenerateOrgJITConfig, so the driver only has to hand it to run.sh.

func (*Driver) ReclaimTiers

func (d *Driver) ReclaimTiers(ctx context.Context) []driver.Tier

ReclaimTiers frees data-root space. What a job creates through the shared docker socket carries none of our labels, so collecting it means deleting objects we can't prove are idle: those steps are drain-gated, and further gated on the operator declaring the daemon ours alone. Without that declaration reclaim is limited to our own build cache and unreferenced layers, and a shared daemon's disk stays the operator's to manage.

func (*Driver) StartedJob

func (d *Driver) StartedJob(ctx context.Context, h driver.SlotHandle) (bool, error)

StartedJob reports whether the runner has begun a job, read from its console log. A gone container counts as not-started (Status reports it Done); the runner's output can land on either stream depending on the image entrypoint, so both are scanned.

func (*Driver) Status

func (d *Driver) Status(ctx context.Context, h driver.SlotHandle) (driver.Status, error)

Status maps the container state to a driver.Status. A gone container (the runner is ephemeral and may have been reaped) is treated as Done; any other docker error is surfaced so the agent's retry budget applies.

type Options

type Options struct {
	Image      string
	Capacity   int
	Runtime    string // "docker" | "podman"; empty autodetects
	Network    string
	Volumes    []string
	ExtraHosts []string
	GroupAdd   []string
	Memory     string
	Entrypoint string
	// Per-repo persistent build cache (docker driver).
	BuildCache        bool
	BuildkitImage     string
	BuildCacheGB      int
	BuildCacheIdleHrs int
	StateDir          string
	// ActionCache is the host action archive cache, mounted read-only.
	ActionCache string
	// Exclusive declares that no workload other than ushr's runners uses this
	// daemon, which is what lets reclaim collect the containers, volumes and
	// images jobs leave behind through the shared socket. Off by default: on a
	// daemon someone else also uses, those objects are not ours to delete.
	Exclusive bool
}

Options configures a Driver. Zero values fall back to Default* constants.

Jump to

Keyboard shortcuts

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