Expand description
The Isothrum runner: executes the run manifest Isoloom writes next to a target’s generated
files (.isoloom/<target>/run.json), and reads nothing else of them.
The manifest holds the native commands in order, the documented driver actions, readiness,
outputs, check runners, and the slots inputs and secrets travel through. The runner adds what
only it can know: the run’s name and private state, one operation per run at a time, the
values of params and secrets, and the event stream an embedder (an app, the isothrum command
line) shows. It sits between Isoloom (whose
isoloom-manifest crate is the contract) and those embedders, and depends on no UI.
§Example
Opening a manifest reads and checks it, and nothing runs yet:
use isothrum_runner::{RunName, Runner, RunnerConfig};
let home = tempfile::tempdir()?;
let dir = tempfile::tempdir()?;
let manifest = dir.path().join("run.json");
std::fs::write(&manifest, include_str!("../tests/fixtures/web-portal.run.json"))?;
let runner = Runner::new(RunnerConfig::new(home.path()))?;
let run = runner.open(&manifest, Some(RunName::new("demo")?))?;
assert_eq!(run.manifest().environment.name.as_str(), "web-portal");
assert_eq!(run.name().as_str(), "demo");
assert!(runner.runs()?.is_empty(), "no operation has run");Running it takes the tools it names (here Docker), and an event sink (Events, implemented
for closures):
use isothrum_runner::{Event, Park, RunOptions};
let events = |event: &Event| println!("{}", serde_json::to_string(event).unwrap_or_default());
let opts = RunOptions::new().with_param("ISOLOOM_PUBLISH_FIXED", "1");
let started = run.up(&opts, &events).await?;
let report = run.check(&opts, &events).await?;
run.park(Park::Shutdown, &opts, &events).await?;
run.resume(&opts, &events).await?;
run.down(&opts, &events).await?;§Ports
Every outside effect goes through a port: ProcessRunner (the tools), HostPorts (the
host’s ports) and Events (where events go). ProcessRunner and Events are open traits,
since embedders implement them. HostPorts is sealed: RunnerConfig::new binds the
loopback itself, and the fake feature’s FakePorts stands in for it in tests, as its
FakeProcesses does for the tools. Three programs run outside ProcessRunner, each for a
reason of its own: Apple’s nc, the macOS relays’ byte pipe for as long as a connection lasts
(not a tool run to its end), a graphical console’s SSH tunnel (ssh -N -L), for as long as its
Console lives, and on Windows whoami and icacls, which make the home
owner-only when the runner is built (Runner::new), before any operation.
§Deliveries
Params and slot values reach the tools only through the manifest’s deliveries, never on a
command line: env (a step’s variables), tf_var (TF_VAR_<var>, a map_entry making one
JSON object), state_file (an owner-only Terraform variable file in the run’s state folder,
written at up, kept for the destroy, removed by a successful down), and guest over SSH, Isoloom’s delivery into a machine for a cloud with no secret
store (DigitalOcean, Linode): once the step it names (else every up step) succeeded, one
SSH session per machine, to the outputs address_<machine> and ssh_user_<machine> (else
ssh_user; the machine’s name with - and . as _, in lower case), runs a fixed script as root that keeps each value
owner-only under /var/lib/isoloom/secrets/<slot name> and then touches
/var/lib/isoloom/secrets/.delivered, which the machine’s set-up waits for; the values travel
base64-encoded on its standard input, retried while SSH can’t connect (up to 15 minutes),
from an owner-only guest-<machine>.in in the run’s state folder that is removed once
delivered (a removal that fails, fails the delivery) or once the operation is cut short.
§Concurrency
The runner is async, on Tokio, chosen once for the whole crate: every tool runs as an async
process with a time limit (a step’s provider_timeout_s for the run’s provider, else its
timeout_s, else an hour; 25 s for a probe; two minutes for an action’s own Docker calls),
and dropping an operation’s future stops the process trees it started: on Unix each gets
SIGINT (so Terraform saves its state) and SIGKILL once it exited or 30 seconds later; on
Windows each is ended at once (SystemProcesses). The limit counts the time
a tool shows no progress: it is stopped once it printed no new line for that long (a line, on
either stream, that isn’t blank and isn’t one of its last distinct lines; from its start when
it prints nothing), and at the latest six hours after its start, or at its limit when that is
longer (TimedOut says which). The images a Compose up starts are pulled before it, and
the boxes a vagrant up boots downloaded before it (those the manifest lists that Vagrant
hasn’t), each in a step of their own (pull-<step>, boxes-<step>) with no such ceiling: a
download still moving runs as long as it moves, and one that shows no progress for 15 minutes
fails with download_stalled (a download that fails, with download_failed). A step the
manifest marks download runs the same way, its own limit the time it may show no progress. Operations on one run in one Runner wait for each other;
an operation on it from another process (or another runner) fails with locked once it has
waited a second for the run’s lock. Operations on different runs run side by side. One
exception to “no blocking call in async code”: the run’s state files (a record, a lock, the
pinned ports, the event log) are a few KB on the local disk, so they are read and written
inline rather than through spawn_blocking.
§Errors and tracing
Every fallible call returns Result, whose Error has a stable ErrorCode; an
operation also reports its failure as its last event. The runner logs through tracing (spans
run, step and driver, events for each process), never by printing.
Re-exports§
pub use isoloom_manifest;
Modules§
- fake
fake - Scripted processes for tests (feature
fake): every call is recorded and answered from the test’s script, so code that drives docker, vagrant or terraform runs without them and never touches real ones. In this crate’s tests a reply can take time (Reply::after) and print its lines over time (Reply::paced): under Tokio’s paused clock that time passes at once, so timeouts are tested without waiting.
Structs§
- Access
Pick - Which access machine an attach adds, where, from what: as
Running::attachtakes them. - Adoption
- An existing Terraform deployment to adopt as a run (
Runner::adopt): where its local state is, and what the runner can’t read from that state (the params it was applied with, where it is, when it expires). - Attach
Report - What a hot-add produced: the access machine brought up, and where to reach it.
- Captured
- What a process printed, kept: its standard output, and its last standard error lines.
- Check
Report - Every check’s outcome.
- Check
Result - One check’s outcome.
- Console
- A machine’s graphical console the runner reached: where it answers, and how to sign in. A tunnel it opened lives as long as the console: drop it once the viewer is done.
- Console
Offer - What a status says of a machine’s graphical console under the run’s provider: its protocol,
or
noneand why (isoloom_manifest::Console’s, as the manifest says it). - Event
- One event of the stream.
- Event
Log - A run’s logged events (
crate::Runner::events), and how many of the log’s lines it couldn’t read as one: a line another version of the runner wrote (an event kind or a code this one doesn’t know), or one cut short. - Exit
- How a process ended.
- Fake
Ports fake - Ports answered from a test’s setup (feature
fake): the free ones handed out in order. An embedder’s tests script those only; the runner’s own also mark ports taken, addresses answering and binds refused. - LastOp
- The last operation on a run and how it ended.
- Loaded
Manifest - A manifest read from its file.
- Machine
Status - One machine of the manifest, as it stands.
- Native
App - The hypervisor’s own app that shows a running VM’s screen in a window of its own, and what of
it this computer must have (any one of
needs). - Native
Console - What opens a running VM’s screen in its hypervisor’s own app.
- Network
View - A network of the run.
- Orphans
- What a cloud still holds past its expiry that no recorded run covers.
- Output
Value - An output’s value. A sensitive one shows as
***wherever it is written out (its JSON, itsDebug, an event); the runner keeps the value itself for its own use (a guest delivery’s address, masking it in what tools print). - Place
- Where a query looks: the regions (AWS) or the project (Google Cloud); the CLI’s own default when unset.
- Process
Spec - One process to start.
- Proxmox
Vnc - Proxmox VE’s VNC websocket for one VM, opened for one session: connect to
websocketwith theauthorizationheader (TLS unverified wheninsecure), then speak VNC withticketas the password. Every secret is aSecretValue: never print or log one. - Published
Port - A published port: where a machine’s port answers on the host.
- RunName
- A run’s name: 1 to 63 lowercase letters, digits,
-or_, starting with a letter or digit (Compose’s rule for a project name). - RunOptions
- The options of one operation.
- RunRecord
- What the runner keeps about a run (never a secret’s value).
- Runner
- The runner.
- Runner
Config - How a runner is built: its home, and the ports it reaches the world through. Start from
RunnerConfig::newand set a field to change it (config.processes = Arc::new(fake)). - Running
- A run: a manifest under a name, on a runner.
- Secret
Value - A secret’s value. Its
Debugnever shows it. - Secrets
- The values of a run’s secret and input slots, by slot name.
- Shell
Command - The command that opens an interactive console into a machine (a shell in a container,
vagrant ssh, an SSH login): the runner builds it (it alone knows the runtime: the Compose project and files, the Vagrant define, the address and user a module gives), the embedder runs it in its own terminal. Addresses the machine by service or define name, or by the address the run gives it, never a guessed container. - Started
- A run that came up (or resumed).
- Status
- A run as it stands.
- System
Processes - Starts real processes.
SystemProcesses::defaultreads the Docker CLI’s config ($DOCKER_CONFIG/config.json, else~/.docker/config.json) to learn whether the user picked an engine context of their own. - Tagged
- A resource a cloud holds with Isoloom’s tags.
Enums§
- Endpoint
- Where a graphical console answers.
- Error
- Why an operation of the runner failed.
- Error
Code - The stable code of a failure, the same in the Rust API and the event stream (
error.code). - Event
Kind - What happened.
- Machine
State - A machine’s state, as its engine reports it.
- Native
Need - What of a hypervisor’s app must be on this computer for a way to open it.
- Native
Open - One way to open a VM in its hypervisor’s app: what to run, never through a shell.
- Occupied
- What
updoes when the run already exists. - Op
- An operation on a run.
- Park
- How a run is parked: the manifest’s
lifecycle.park.pauseor.shutdownsteps. - Process
Error - Why a process couldn’t run to its end.
- Ready
State - Where a ready condition stands.
- RunState
- Where a run stands.
- Step
State - Where a step stands.
- Stream
- Which output of a tool a line came from.
- Timed
Out - Which limit a step ran into: a timeout’s, also the
errorevent’stimeout. - Warning
Code - What kind of warning a
warningevent is, the same in the Rust API and the event stream.
Constants§
- MANIFEST_
FILE - The file Isoloom writes a target’s run manifest to, in the target’s folder of an outputs
folder (
is_outputs_folder):.isoloom/docker/run.json,.isoloom-2/cloud-vm/aws/run.json.
Traits§
- Events
- Where an operation’s events go. Implemented for closures (
|e: &Event| …). - Host
Ports - The host’s ports. Sealed:
RunnerConfig::newgives the real host’s (sockets on the loopback), and thefakefeature’sFakePortsanswers from a test’s setup; no other implementation is needed, and only the runner asks them anything. - Process
Runner - Starts processes. Dropping the future of
ProcessRunner::runbefore it resolves (a timeout, a cancelled operation) ends the process and everything it started.
Functions§
- capture
- Runs
spec, keeping what it prints. - events_
schema - The JSON Schema of one event.
- every_
name - Every name the unit enum
Tis written as, from its JSON Schema (each variant’sconst, or theenumthat lists them), in the schema’s order: the values a command line offers for a type of Isoloom’s, so a variant added there is offered without a list of its own to keep in step. - from_
wire_ name - The value of the unit enum
Tthat the manifest writes asname(vmware_desktop): the way back fromwire_name.Nonewhen no value ofThas that name. - is_
outputs_ folder - Whether a folder named
name, at a project’s top, is one Isoloom writes the project’s outputs under:OUTPUT_DIR(.isoloom), or an instance’s.isoloom-<n>,nan instance Isoloom takes (isoloom_manifest::Instance::new: 1 to 99) as it writes it (no sign, no leading zero). No other.isoloom*name. Isoloom publishes the way there (isoloom_spec::instance::output_dir) but not this way back; a test holds this copy to the folders Isoloom generates. - load_
manifest - Reads and checks the manifest at
path. - may_
manage_ hyperv - Whether this account may manage Hyper-V, as Vagrant’s Hyper-V provider requires for every
command on its machines (
vagrant statusincluded): its token is elevated, or it is a member of “Hyper-V Administrators”. Read fromwhoami /groups, run throughprocesses(nounsafe).Nonewhenwhoamican’t say (it didn’t run, or failed), which is traced. - rfc3339
timeasYYYY-MM-DDTHH:MM:SSZ(UTC, whole seconds; before 1970 reads as 1970).- status_
schema - The JSON Schema of a run’s status (
isothrum status --json). - vagrant_
plugins - Each plugin
vagrant plugin list --machine-readablenames (itsplugin-namelines), with its version when aplugin-versionline gives one (0.12.2%!(VAGRANT_COMMA) global: the version before Vagrant’s escaped comma). - version_
found - The version
textsays (what a tool prints:Vagrant 2.4.1,v2.29.1,1.0.0-rc.1), as Isoloom’sVersion, so versions compare in its order (a pre-release before its release): its first word that is one, else its first<major>.<minor>[.<patch>](2.3.8.devis 2.3.8, a missing patch 0).Nonewhen it says none: nothing is held back then. The one reading of a version for the runner’s tool probes andisothrum-machine’s minimums. - wire_
name value’s name as the manifest and the event stream write it (a target, a provider, a machine’s role:vmware_desktop), without JSON’s quotes. It is meant for the unit enums serde writes as a string; any other value is named by its JSON text (3), and one serde can’t write by why, so a name is never silently empty.