Machine images
A machine image decides the system a machine runs: its installed software and system files, not its data. It is a recipe of shell steps run as root over the stock Rool system, with files put over the result, kept as numbered revisions. Machine images belong to an account, and a machine follows the default revision of the one it runs.
Revisions are made on a machine: a machine image is checked out as a tree of steps and files in a folder of the machine’s drive, changed by its agent or by hand, and a save there builds the tree into a revision. The SDK lists and administers machine images, moves machines between them, and works with the Rool Hub.
An account’s machine images
Section titled “An account’s machine images”const account = client.account(accountId);
// account.machineImages.watch(({ machineImages }) => ...) keeps a list current.for (const image of await account.machineImages.list()) { console.log(image.name, image.defaultRevision, image.revisions[0].stepCount);}
const image = client.machineImage(machineImageId);console.log((await image.get()).description);const revision = await image.getRevision(2);console.log(revision.recipe, revision.files);
await image.update({ name: "Data" });await image.setDefaultRevision(2);await image.delete();A revision lists its files with their sizes. To show what is in them, open its archive:
const files = await image.files(2);console.log(files.paths); // ["/etc/hosts", "/etc/rool/theme.json"]console.log(await files.text("/etc/hosts"));const picture = await files.read("/etc/rool/icon.webp"); // bytesfiles() downloads a revision’s files as the one compressed archive they are stored in, at most 16 MiB, and keeps it compressed. A file is unpacked when you read it, so keep the result while showing files, and read only what you show. A browser keeps the download and asks the server each time whether it still holds, so opening the same files again costs one small request. A revision without files gives no paths. client.hub.machineImages.files(id) does the same for a listed machine image.
setDefaultRevision() restarts every machine whose system it changes and reports how many. Rolling back is setting an older revision. delete() is refused with machine_image_in_use while machines run the machine image.
The machine image a machine runs
Section titled “The machine image a machine runs”const machine = client.machine(machineId);
await machine.machineImage.use(machineImageId); // null for the stock systemconst state = await machine.machineImage.get();console.log(state.machineImage?.name, state.machineImage?.revision, state.changing, state.error);Every machine in client.listMachines() and account.listMachines() carries machineImage, with the id, name and revision it runs, so an overview needs no call per machine. It is null on the stock system.
use() resolves once the change is asked for; the machine restarts when the revision is built. watch() reports the state now and each time it changes:
const stop = machine.machineImage.watch(({ state }) => { if (!state) return; // not loaded yet if (state.changing) console.log("building"); else if (state.error) console.error(state.error); else console.log("running", state.machineImage?.name ?? "the stock system");});// laterstop();A new machine can start on a machine image with createMachine({ name, machineImageId }).
Making and changing one
Section titled “Making and changing one”Revisions are made on a machine, by its agent or in its shell with rool-machine-image. A machine image is checked out as a tree in a folder of the machine’s drive: steps/, one shell step per file, and files/, which mirrors /. rool-machine-image check builds a tree without saving it, and rool-machine-image save builds it and adds the revision to the tree’s machine image; save-as makes a new machine image from a tree. A save moves no machine: rool-machine-image use <machine-image> <rev> runs a revision on one. Only the machine’s owner can check or save, on a plan that includes it.
A new revision runs nowhere until a machine is moved onto it or setDefaultRevision() moves the machines that follow the default.
A revision’s description is the file /etc/rool/machine-image.txt among its files. A machine image’s description is that of its default revision, so update() renames and cannot change it.
The default theme and icon
Section titled “The default theme and icon”A machine image can carry a theme and an icon, as files under /etc/rool: theme.json, and icon.webp, icon.png or icon.jpg. They are files of its tree like any other, put there by whoever makes it. A revision’s theme and icon hold what its files carry, and a machine’s summary gives those of the revision it runs under machineImage. The machine’s own win:
for (const summary of await client.listMachines()) { const theme = summary.theme ?? summary.machineImage?.theme; const icon = summary.icon ?? summary.machineImage?.icon;}machine.settings.setTheme(null) and setIcon(null) return a machine to its machine image’s.
The Rool Hub
Section titled “The Rool Hub”The Hub lists machine images that accounts have published. Taking one makes a copy in your account, which is yours from then on: nothing changes it but your account. The Hub can be read without signing in, apart from the contents of files.
const listed = await client.hub.machineImages.list();const detail = await client.hub.machineImages.get(listed[0].id);console.log(detail.recipe, detail.files);
const copy = await account.machineImages.copyFromHub(detail.id);await machine.machineImage.use(copy.id);A listed machine image has the address publisher.handle/slug, which getBySlug(handle, slug) reads. publisher also has the name it publishes under and since, when its account was made; official marks Rool’s own. copies counts the other accounts that took it, machines the machines running their copies. Use iconUrl(id) in an <img> when hasIcon is set.
When the machine image a copy was made from publishes a newer revision, the copy’s copiedFromPublishedRevision is higher than the copiedFromRevision of its revisions. updateCopy() adds that revision to the copy. The default revision stays, so machines move when you set it:
const { revision } = await client.machineImage(copy.id).updateCopy();await client.machineImage(copy.id).setDefaultRevision(revision);Changes made to the copy itself are not merged into the new revision.
Publish to the Hub
Section titled “Publish to the Hub”const image = client.machineImage(machineImageId);await image.submit({ handle: "crafts", publisherName: "The Crafts" });
await image.submit({ revision: 3 }); // the default revision when left outAn account’s first submission needs a handle and a publisherName; account.machineImages.getPublisher() says what it has. A handle is 3 to 30 lower-case letters, digits and hyphens, and unique across Rool; some names are reserved. It is held while a submission waits, given back when the first is rejected or withdrawn, and fixed once one is approved. The publisher name can change with any submission, and is listed as reviewed. A machine image’s slug is fixed by its first submission, made from its name unless you pass one.
Rool reviews each submitted revision. Each revision in account.machineImages.list() carries its review: pending, approved, or rejected with a note saying why. An approved revision is listed under the name and description the machine image had when it was submitted, and anyone can read its recipe and files, so keep secrets out of a revision you submit.
One submission waits at a time. unlist() takes the machine image off the Hub and withdraws a waiting submission; copies already made stay.