diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..41ea57e --- /dev/null +++ b/README.md @@ -0,0 +1,156 @@ +# aur-build + +A build server for AUR packages: it watches recipes, shows a human what changed, +and publishes a signed pacman repository containing **only what a human +approved**. One process, no async runtime, no external services. + +The design is in [`DESIGN.md`](DESIGN.md). The invariants it must never violate +are in [`docs/INVARIANTS.md`](docs/INVARIANTS.md), each mapped to a named test. +Judgement calls where the design left an opening are in +[`docs/DECISIONS.md`](docs/DECISIONS.md). + +## The rule everything else follows + +Nothing reaches a consumer without an `approval` row behind it (I1). Every other +behaviour is downstream of that: the review page freezes the exact bytes a human +looked at and hashes them, the approve request must echo both hashes, the build +re-checks the recipe pin and the resolved version before it runs, and publish +refuses if the accepted pointer moved underneath it. + +## Quick start + +```sh +cargo build --release +target/release/aur-build --root /var/lib/aur-build init --repo aur +sudo -u aurbuild target/release/aur-build --root /var/lib/aur-build serve +``` + +Then subscribe and drive a package through once by hand: + +```sh +aur-build subscribe some-pkg +aur-build detect some-pkg # or wait for the watcher +aur-build reviews # candidate ids +aur-build show 12 # the diff panels + the two hashes +aur-build approve 12 --yes # approves exactly what was just rendered +aur-build build 12 # enqueue; the dispatcher picks it up on serve +aur-build packages # what the index is serving +``` + +`serve` runs the watcher, the HTTP UI, the dispatcher and the reaper in one +process. The CLI and the UI drive the same code paths, so anything the web +interface can do, an operator can do from a shell at 3am. + +## Layout + +``` +src/ + main.rs CLI: init, subscribe, detect, reviews, show, approve, reject, + build, rebuild, run, builds, status, packages, serve, audit, + metrics, gc, backup + config.rs one config file at <root>/config.json + db/ SQLite: migrations, model rows, queries, build state machine + mod.rs single writer actor + thread-local read-only readers + watch/ detection: scheduler, cheap/expensive polls, upstream probes, + source digests, staleness derivation + review/ candidates, diff panels, risk scoring, approval + pipeline/ the step machine, the dispatcher + worker pool, publishing + pkgver/ vercmp and the dependency-string grammar + pkginfo.rs .PKGINFO / .BUILDINFO parsing (no libalpm) + http/ tiny_http server: routes, render, auth, SSE log tail + ops.rs retention, metrics, VACUUM INTO backups + shims/ the fake toolchain that makes the pipeline testable +testcorpus/ the fixture packages the tests build for real +templates/ askama templates, server-rendered +static/ app.css and one vendored htmx +docs/ DECISIONS.md, INVARIANTS.md +``` + +## Testing without root, network, or a real chroot + +`cargo test` runs the whole thing on an ordinary user account. Two mechanisms +make that possible (§16a): + +* **PATH shims.** `src/bin/` contains `makepkg`, `makechrootpkg`, `mkarchroot`, + `repo-add`, `gpg` and `pacman`. Pointing `path_prepend` at the directory cargo + built them into makes the *unmodified* pipeline drive a fake toolchain: it + still runs real subprocesses, still reads their stdout and exit codes, still + gets real `.pkg.tar.zst` files with real `.PKGINFO` and `.BUILDINFO` inside + them, and still signs them with a fake key. The step machine cannot tell it is + not in a chroot, which is the point. +* **The fixture corpus.** `testcorpus/` holds ~20 synthetic packages, each with + a `PKGBUILD` and a manifest describing what the shims should emit: a split + pkgbase, a build that fails, a recipe whose payload drifts under a `SKIP` + checksum, a VCS package with a local upstream repo, a downgrade, an epoch bump, + a package with an unsatisfiable dependency. Tests drive the real code against + these rather than against mocks of the code. + +Crash tests are real: `shim_kill_parent` makes a shim `SIGKILL` the pipeline +process mid-step, and a separate test spawns the compiled binary and kills *it*, +then asserts a fresh process resumes from the step checkpoints with no duplicate +work and the old index still byte-identical. + +Some tests are gated on the host and skip themselves with a printed note rather +than failing: + +* `versions::vercmp_matches_the_system_oracle` needs pacman's `vercmp` on `PATH` + and compares the hand-written comparator against it over ~1100 pairs. +* The real-chroot tier needs root, network and devtools. It is recorded as + skipped in `docs/DECISIONS.md` rather than silently absent. + +## Operations + +```sh +aur-build metrics # Prometheus text, same as GET /metrics +aur-build gc --keep 3 # evict files beyond the retention window +aur-build gc --keep 3 --dry-run # show what would go +aur-build backup /backups/aur.db # VACUUM INTO; refuses to overwrite +``` + +Retention never deletes a row. An evicted artifact keeps its digest, size and +provenance and gains a `purged_at`, so the database says "these bytes existed and +were dropped at T" instead of continuing to claim a file that is gone. The +currently accepted release and anything still backing an index entry are never +evicted, however old they are. + +Metrics are computed from live state on every scrape — there are no counters +incremented at event sites, because a counter maintained by every code path is a +counter that quietly drifts the first time a code path is added. + +## Web UI + +Server-rendered HTML with at most one vendored JavaScript file (htmx, ~15.6 KB +gzipped on the wire) and no build step. The review surface ships no JavaScript +at all; a test greps the rendered page for `<script` to keep it that way. + +| Surface | Path | +|---|---| +| Inbox (reviews) | `/`, `/reviews`, `/reviews/:id` | +| Builds | `/builds`, `/builds/:id`, `/builds/:id/log.txt`, `/builds/:id/log.stream` | +| Attention | `/attention` | +| Index | `/packages`, `/packages/:name` | +| Subscriptions | `/subscriptions` | +| Ops / audit | `/audit`, `/settings`, `/metrics`, `/healthz` | + +Approve is a POST carrying `identity_hash` and `diff_digest`. If either no +longer matches what the candidate became while the reviewer was reading, the +server answers **409** and re-renders the current state, so a reviewer can never +approve bytes they did not see (§7.1a). Every POST requires a CSRF token bound +to the session; the whole site is gated behind a password by default. + +## Constraints this codebase keeps + +From §14, and they are not suggestions: + +* No `async`/`await`, no tokio. Threads and crossbeam channels; blocking HTTP + with `tiny_http`, outbound HTTP with `ureq`. +* SQLite in WAL with exactly one writer thread reached over a channel. Readers + are thread-local and read-only — asserted by a test. No transaction spans a + build step. +* Git by shelling out; no libgit2. +* `vercmp` and the dependency grammar are hand-written; no libalpm. They are + checked against pacman's own `vercmp` where that binary exists. +* Fail closed. A pin that does not match, a recipe hash that drifted, a package + with no signature, a symlink in the srcdir: the build stops and says why. A + change that is real but not publishable becomes a `notice` — never a candidate, + never silently dropped (I11). |
