Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ The Cartesi CLI drives Docker for most of its commands (`cartesi build`, `cartes
registration (`setup-qemu`) also runs through Docker. GitHub-hosted Linux runners already provide
Docker, so this action never installs it there.

### QEMU registration is verified, not just run

The `tonistiigi/binfmt` installer exits `0` even when it fails to register anything — it only logs
the error. Rather than trust that exit code, the action checks
`/proc/sys/fs/binfmt_misc/qemu-riscv64` directly afterwards and fails the step with an explanatory
message if it's missing, instead of reporting success while `docker buildx`/`cartesi build` are
left unable to run RISC-V images.

## Security

- The action only ever downloads from a fixed set of hardcoded sources: the `cartesi/machine-emulator`,
Expand Down
16 changes: 16 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/qemu.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { access } from "node:fs/promises";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { BINFMT_IMAGE, QEMU_ARCH } from "./constants.js";
import type { Platform } from "./platform.js";

/**
* Where the kernel exposes a registered handler once `--install` succeeds.
* Checked directly after running the installer, because that tool's process
* exits 0 even when it fails to register anything (it only logs the error).
*/
const BINFMT_ENTRY = `/proc/sys/fs/binfmt_misc/qemu-${QEMU_ARCH}`;

async function binfmtRegistered(): Promise<boolean> {
try {
await access(BINFMT_ENTRY);
return true;
} catch {
return false;
}
}

/**
* Registers the QEMU emulator for `QEMU_ARCH` with the kernel's binfmt_misc
* via the same `tonistiigi/binfmt` image `docker/setup-qemu-action` uses,
Expand All @@ -29,4 +46,13 @@ export async function setupQemu(platform: Platform): Promise<void> {
"--install",
QEMU_ARCH,
]);

if (!(await binfmtRegistered())) {
throw new Error(
`the ${QEMU_ARCH} QEMU emulator was not registered: ${BINFMT_ENTRY} does not exist ` +
"after running the installer. This runner's kernel may not support binfmt_misc " +
"registration from a container. Set 'setup-qemu: false' to skip this step.",
);
}
core.info(`${QEMU_ARCH} QEMU emulator registered`);
}
Loading