Skip to main content

Crate isothrum_runner

Crate isothrum_runner 

Source
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. A few 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, on Windows whoami and icacls, which make the home owner-only when the runner is built (Runner::new), before any operation, and, only for a tool a killed operation left running, ps (Windows: PowerShell) to tell it is still that tool, and on Windows taskkill to end it.

§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§

fakefake
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§

AccessPick
Which access machine an attach adds, where, from what: as Running::attach takes 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).
AttachReport
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.
CheckReport
Every check’s outcome.
CheckResult
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.
ConsoleOffer
What a status says of a machine’s graphical console under the run’s provider: its protocol, or none and why (isoloom_manifest::Console’s, as the manifest says it).
Event
One event of the stream.
EventLog
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.
FakePortsfake
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.
LoadedManifest
A manifest read from its file.
MachineStatus
One machine of the manifest, as it stands.
NativeApp
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).
NativeConsole
What opens a running VM’s screen in its hypervisor’s own app.
NetworkView
A network of the run.
Orphans
What a cloud still holds past its expiry that no recorded run covers.
OutputValue
An output’s value. A sensitive one shows as *** wherever it is written out (its JSON, its Debug, 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.
ProcessSpec
One process to start.
ProxmoxVnc
Proxmox VE’s VNC websocket for one VM, opened for one session: connect to websocket with the authorization header (TLS unverified when insecure), then speak VNC with ticket as the password. Every secret is a SecretValue: never print or log one.
PublishedPort
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.
RunnerConfig
How a runner is built: its home, and the ports it reaches the world through. Start from RunnerConfig::new and set a field to change it (config.processes = Arc::new(fake)).
Running
A run: a manifest under a name, on a runner.
SecretValue
A secret’s value. Its Debug never shows it.
Secrets
The values of a run’s secret and input slots, by slot name.
ShellCommand
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.
SystemProcesses
Starts real processes. SystemProcesses::default reads 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.
ErrorCode
The stable code of a failure, the same in the Rust API and the event stream (error.code).
EventKind
What happened.
MachineState
A machine’s state, as its engine reports it.
NativeNeed
What of a hypervisor’s app must be on this computer for a way to open it.
NativeOpen
One way to open a VM in its hypervisor’s app: what to run, never through a shell.
Occupied
What up does when the run already exists.
Op
An operation on a run.
Park
How a run is parked: the manifest’s lifecycle.park.pause or .shutdown steps.
ProcessError
Why a process couldn’t run to its end.
ReadyState
Where a ready condition stands.
RunState
Where a run stands.
StepState
Where a step stands.
Stream
Which output of a tool a line came from.
TimedOut
Which limit a step ran into: a timeout’s, also the error event’s timeout.
WarningCode
What kind of warning a warning event 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| …).
HostPorts
The host’s ports. Sealed: RunnerConfig::new gives the real host’s (sockets on the loopback), and the fake feature’s FakePorts answers from a test’s setup; no other implementation is needed, and only the runner asks them anything.
ProcessRunner
Starts processes. Dropping the future of ProcessRunner::run before 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 T is written as, from its JSON Schema (each variant’s const, or the enum that 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 T that the manifest writes as name (vmware_desktop): the way back from wire_name. None when no value of T has 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>, n an 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 status included): its token is elevated, or it is a member of “Hyper-V Administrators”. Read from whoami /groups, run through processes (no unsafe). None when whoami can’t say (it didn’t run, or failed), which is traced.
rfc3339
time as YYYY-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-readable names (its plugin-name lines), with its version when a plugin-version line gives one (0.12.2%!(VAGRANT_COMMA) global: the version before Vagrant’s escaped comma).
version_found
The version text says (what a tool prints: Vagrant 2.4.1, v2.29.1, 1.0.0-rc.1), as Isoloom’s Version, 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.dev is 2.3.8, a missing patch 0). None when it says none: nothing is held back then. The one reading of a version for the runner’s tool probes and isothrum-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.

Type Aliases§

BoxFuture
A boxed future that can be sent between threads.
OnLine
Receives each line a process prints, with the output it came from.
Result
The runner’s Result: its error is a Error unless said otherwise.