A disposable machine on a container runtime: the image made from the machine's Containerfile (kept by the hash of its text), the container run with systemd as its first process and the host's network, a key pair made for this run and thrown away with it, sshd set to a free port that only the machine's own address answers, the host key pinned in a file of known hosts, and an executor of Headless that runs a program in it. stop removes the container and the folder of keys whatever happened, and a test that cannot have a runtime says why and is skipped, never passed.
import { runtimeUsable } from"./machine.ts";
// const reason = await runtimeUsable("docker"); // undefined where containers can be run, else why not
type Machine = {
readonly spec: MachineSpec;
readonly container: string;
/** The port sshd listens on, on 127.0.0.…(599 characters)
typeMachine= {
readonlyspec:MachineSpec;
readonlycontainer:string;
/** The port sshd listens on, on 127.0.0.1. */readonlyport:number;
/** The private key made for this run, which every user of the machine accepts. */readonlyidentityFile:string;
/** The host key of the machine, pinned: the file a client checks the machine against. */readonlyknownHostsFile:string;
/** Runs a program in the machine as root, with no shell between. */readonlyexecutor:Executor;
/** Removes the container and the folder of keys; safe to run twice. */stop():Promise<void>;
};
Starts a machine, or says why it could not be: the image is built, the container run, systemd waited for until it is running (or degraded, as a container's usually is), the key and sshd set up and the host key pinned.
type Machine = {
readonly spec: MachineSpec;
readonly container: string;
/** The port sshd listens on, on 127.0.0.…(599 characters)
typeMachine= {
readonlyspec:MachineSpec;
readonlycontainer:string;
/** The port sshd listens on, on 127.0.0.1. */readonlyport:number;
/** The private key made for this run, which every user of the machine accepts. */readonlyidentityFile:string;
/** The host key of the machine, pinned: the file a client checks the machine against. */readonlyknownHostsFile:string;
/** Runs a program in the machine as root, with no shell between. */readonlyexecutor:Executor;
/** Removes the container and the folder of keys; safe to run twice. */stop():Promise<void>;
};
Starts a machine, or says why it could not be: the image is built, the container run, systemd waited for until it is running (or degraded, as a container's usually is), the key and sshd set up and the host key pinned.