1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! The Isothrum runner: runs a project folder (a Compose project, a Vagrantfile, a Terraform
//! module) through its own tool, with that tool's own lifecycle, and reads nothing else of it.
//!
//! The format comes from the folder's files ([`Format::detect`]), and each format has one driver
//! that knows its tool: Compose's `up --wait` and `down`, Vagrant's `up`, `suspend`, `halt` and
//! `destroy`, Terraform's `init`, `apply` and `destroy`. The runner adds what only it can know: the
//! run's name, key and private state, one operation per run at a time, journaled in the home's
//! store, the values and secrets the tools get in their environment, the resources each tool
//! reports, and the event stream an embedder (an app, the `isothrum` command line) shows. It
//! depends on no UI and on no generator: any project of a format it runs is a project.
//!
//! # Example
//!
//! Opening a folder detects its format, and nothing runs yet:
//!
//! ```
//! use isothrum_runner::{Format, RunName, Runner, RunnerConfig};
//!
//! let home = tempfile::tempdir()?;
//! let dir = tempfile::tempdir()?;
//! std::fs::write(dir.path().join("compose.yaml"), "services:\n web:\n image: nginx\n")?;
//!
//! let runner = Runner::new(RunnerConfig::new(home.path()))?;
//! let run = runner.open(dir.path(), Some(RunName::new("demo")?))?;
//! assert_eq!(run.project().format, Format::Compose);
//! assert_eq!(run.name().as_str(), "demo");
//! assert!(runner.runs()?.is_empty(), "no operation has run");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! Running it takes its tool (here Docker), and an event sink ([`Events`], implemented for
//! closures):
//!
//! ```no_run
//! # async fn demo(run: &isothrum_runner::Running<'_>) -> isothrum_runner::Result<()> {
//! use isothrum_runner::{Event, Park, RunOptions};
//!
//! let events = |event: &Event| println!("{}", serde_json::to_string(event).unwrap_or_default());
//! let opts = RunOptions::new().with_env("GREETING", "hello");
//! let started = run.up(&opts, &events).await?;
//! let report = run.exec("web", &["true".to_owned()], &opts, &events).await?;
//! run.park(Park::Shutdown, &opts, &events).await?;
//! run.resume(&opts, &events).await?;
//! run.down(&opts, &events).await?;
//! # let _ = (started, report);
//! # Ok(())
//! # }
//! ```
//!
//! # 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: 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. Whether the process holding a lease of the home's store still runs
//! is the system's answer (Unix: signal 0; Windows: `OpenProcess`). The runner's one network
//! client is its own: Proxmox VE's API, for a VM's console and its state on the server, the
//! server's certificate checked by the system's trust store or by the SHA-256 the run pins
//! ([`tls`]).
//!
//! # Inputs
//!
//! Values ([`RunOptions::env`]) and secrets ([`RunOptions::secrets`]) reach the tools only in
//! their environment, never on a command line and never in a file: Compose interpolates `${NAME}`
//! from it, a Vagrantfile reads `ENV`, and Terraform also gets each as `TF_VAR_<NAME>`. Every
//! tool of a run also gets the run's key ([`RUN_KEY_VAR`]). A secret is masked in every event.
//!
//! # Concurrency
//!
//! The runner is **async**, on Tokio, chosen once for the whole crate: every tool runs as an async
//! process with a time limit, 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 Ctrl-C on its own console, then its job ended the same way
//! ([`SystemProcesses`]). 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 home's store ([`store::Store`], SQLite) and the run's lock are
//! a few KB on the local disk, each transaction a few rows, 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` and `driver`, events for each process), never by printing.
pub use Adoption;
pub use port_holder;
pub use ;
pub use ShellCommand;
pub use ;
pub use ;
pub use ;
pub use ;
pub use BoxFuture;
pub use ;
pub use RunName;
pub use FakePorts;
pub use HostPorts;
pub use RunOptions;
pub use ;
pub use fake;
pub use ledger;
pub use process_started_at;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;