Documentation
¶
Overview ¶
Package backend abstracts the launching of one ephemeral runner instance. Each backend manages a specific container daemon (WSL2 Linux or standalone Windows dockerd); a future VM backend can implement the same interface.
Index ¶
- func CacheHost(env map[string]string) string
- func PickDockerHost(ctx context.Context, osType string) string
- func RewriteCacheHost(env map[string]string, host string) map[string]string
- type Backend
- func NewContainerdWindows(nerdctlPath, address, namespace, isolation string) (Backend, error)
- func NewDockerLinux(host string) (Backend, error)
- func NewDockerLinuxTLS(host string, tls DockerTLSConfig) (Backend, error)
- func NewDockerWindows(host, isolation string) (Backend, error)
- func NewDockerWindowsTLS(host, isolation string, tls DockerTLSConfig) (Backend, error)
- type ContainerSettings
- type DockerEndpoint
- type DockerTLSConfig
- type LaunchRequest
- type Mount
- type OwnedRunner
- type OwnedRunnerStore
- type RunnerHandle
- type RunnerOwnership
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CacheHost ¶
CacheHost returns the hostname in the cache URL (ACTIONS_RESULTS_URL) that must resolve to the host running the cache server, or "" if there is no cache redirect or the host is already a bare IP (no mapping needed). Container backends map it to the host gateway; the VM backend rewrites it to the SLIRP host alias so the self-hosted cache is reachable from inside the runner.
func PickDockerHost ¶
PickDockerHost returns the reachable endpoint that runs osType containers, or "" when none does. It is what turns discovery into a value a config can hold.
func RewriteCacheHost ¶
RewriteCacheHost returns a copy of env with the cache URLs' hostname replaced by host (preserving the port). Used by backends where the configured cache hostname won't resolve from inside the runner (the VM rewrites it to the SLIRP alias; containerd rewrites it to the container network's host gateway, since nerdctl can't add hosts on Windows).
Types ¶
type Backend ¶
type Backend interface {
// Name is a human-readable identifier, e.g. "docker-linux".
Name() string
// Ping verifies the backend is reachable.
Ping(ctx context.Context) error
// OSType returns the daemon's container OS ("linux" or "windows").
OSType(ctx context.Context) (string, error)
// EnsureImage makes sure the runner image is present (pull if missing).
EnsureImage(ctx context.Context, imageRef string) error
// Launch starts one ephemeral runner and returns immediately with a handle.
// If it cannot prove that a failed launch left no live instance, it returns
// both a cleanup-capable handle and an error. Callers must terminate that
// handle before releasing the runner registration.
Launch(ctx context.Context, req LaunchRequest) (RunnerHandle, error)
// Close releases backend resources (daemon client connections).
Close() error
}
Backend creates and manages ephemeral runner instances on one daemon.
func NewContainerdWindows ¶
NewContainerdWindows builds a Windows-container backend on containerd/runhcs. isolation "" or "auto" picks process on Windows Server, hyperv on client.
func NewDockerLinux ¶
NewDockerLinux creates a backend bound to a Linux Docker daemon (typically Docker Engine inside WSL2, reachable at tcp://127.0.0.1:2375). Linux containers use the daemon default isolation.
func NewDockerLinuxTLS ¶
func NewDockerLinuxTLS(host string, tls DockerTLSConfig) (Backend, error)
NewDockerLinuxTLS creates a Linux Docker backend using mutual-TLS client credentials.
func NewDockerWindows ¶
NewDockerWindows creates a backend bound to a Windows Docker daemon (a standalone dockerd.exe in Windows-container mode, typically on a custom named pipe such as npipe:////./pipe/docker_engine_windows). On a local Windows controller, isolation "" or "auto" picks process on Windows Server and hyperv on client editions. Remote and non-Windows controllers must select "process" or "hyperv" explicitly because their local registry cannot describe the daemon host.
func NewDockerWindowsTLS ¶
func NewDockerWindowsTLS(host, isolation string, tls DockerTLSConfig) (Backend, error)
NewDockerWindowsTLS creates a Windows Docker backend using mutual-TLS client credentials.
type ContainerSettings ¶
type ContainerSettings struct {
// CPUCount limits the runner to this many CPUs.
CPUCount int64
// MemoryBytes is the hard memory limit.
MemoryBytes int64
// MemorySwapBytes is the total memory plus swap limit. It is supported only
// by Linux Docker.
MemorySwapBytes int64
// DNS contains validated IP addresses used as the container's resolvers.
DNS []string
}
ContainerSettings contains normalized resource and network controls for one container. Zero values preserve the backend's defaults.
type DockerEndpoint ¶
DockerEndpoint is a container daemon that answered a ping, and the container OS it runs. OSType is what decides whether a pool can use it: a Windows daemon cannot run a linux pool however reachable it is.
func DiscoverDockerHosts ¶
func DiscoverDockerHosts(ctx context.Context) []DockerEndpoint
DiscoverDockerHosts probes the endpoints a Docker-compatible daemon commonly listens on and returns the ones that answer. It exists so an unreachable docker.host can be reported with the endpoints that do work on this machine, rather than leaving the reader to guess which of Docker Desktop, Podman, WSL2 or rootless they have.
It never returns an error: an endpoint that does not answer is simply absent.
func PickDockerEndpoint ¶
func PickDockerEndpoint(ctx context.Context, osType string) DockerEndpoint
PickDockerEndpoint retains the selected daemon's OS and architecture for the starter pool, rather than assuming it runs the local machine's architecture.
type DockerTLSConfig ¶
DockerTLSConfig identifies the mutual-TLS client files for one Docker daemon.
type LaunchRequest ¶
type LaunchRequest struct {
// Name uniquely identifies this runner instance for this provisioning cycle.
Name string
// Image is the runner container image to launch.
Image string
// EncodedJITConfig is the base64 blob from GitHub's generate-jitconfig.
EncodedJITConfig string
// WorkFolder is the runner work directory inside the container.
WorkFolder string
// Labels are the runner labels (informational; already baked into the JIT config).
Labels []string
// Env is injected into the container (JIT_CONFIG, cache redirect, tool cache, ...).
Env map[string]string
// Mounts are tool-cache volumes, docker socket (DinD), git mirror, etc.
Mounts []Mount
// Container contains normalized resource and network controls. Zero values
// preserve the backend's defaults.
Container ContainerSettings
// Index is the slot number within the pool (0-based), for naming/logging.
Index int
// Ownership identifies a scale-set runner strongly enough for a restarted
// multirunner instance to reclaim only its own backend resources.
Ownership RunnerOwnership
}
LaunchRequest carries everything needed to start one ephemeral runner slot.
type Mount ¶
type Mount struct {
Source string // host path (bind) or volume name (volume)
Target string // path inside the container
ReadOnly bool
Volume bool // true => named volume, false => host bind mount
}
Mount describes a bind or named-volume mount into a runner container.
type OwnedRunner ¶
OwnedRunner identifies one backend resource proven to match an ownership boundary.
type OwnedRunnerStore ¶
type OwnedRunnerStore interface {
ListOwnedRunners(ctx context.Context, ownership RunnerOwnership) ([]OwnedRunner, error)
RemoveOwnedRunner(ctx context.Context, resourceID string) error
}
OwnedRunnerStore is an optional backend capability used to find and remove scale-set resources left behind by a previous process.
func OwnedRunnerStoreFor ¶
func OwnedRunnerStoreFor(be Backend) OwnedRunnerStore
OwnedRunnerStoreFor returns the optional reconciliation capability without exposing backend implementations to lifecycle coordinators.
type RunnerHandle ¶
type RunnerHandle interface {
// Wait blocks until the runner exits and returns its exit code.
Wait(ctx context.Context) (exitCode int, err error)
// Logs returns a reader for the runner's combined stdout/stderr.
Logs(ctx context.Context) (io.ReadCloser, error)
// Kill forcibly terminates the runner (used during shutdown).
Kill(ctx context.Context) error
// ID returns the backend-specific identifier (container ID) for logging.
ID() string
}
RunnerHandle represents one running ephemeral runner instance.
type RunnerOwnership ¶
type RunnerOwnership struct {
Instance string
Target string
Pool string
ScaleSetID int
RunnerID int64
}
RunnerOwnership is persisted as backend metadata for restart reconciliation. An empty Instance means the launch is not eligible for reconciliation.
func (RunnerOwnership) IsZero ¶
func (o RunnerOwnership) IsZero() bool
IsZero reports whether a request belongs to a provisioning mode that does not use restart reconciliation.
func (RunnerOwnership) Validate ¶
func (o RunnerOwnership) Validate() error
Validate rejects partial ownership, which would preserve a resource without leaving enough metadata to reclaim it safely.