koru/fly: koruc site.k fly deploy
The deploy used to be a shell pipeline nobody could see: build the site, embed it, write a fly.toml, run flyctl, repeat from memory. It is now declarations in the program that gets deployed. This is the actual site.k serving korulang.org — the deploy description lives in the same file as the server:
import orisha
import std/io
import std/build
import std/package
import koru/fly
[build(linux)]std/build:config {
"target": "x86_64-linux-musl"
}
[build(io-uring)]std/build:config {
"target": "x86_64-linux-musl"
}
koru/fly:config(korulang-site) {
"region": "ams",
"build": "--build=linux --release=fast",
"http_service": {
"internal_port": 3000,
"force_https": true,
"auto_stop_machines": "stop",
"auto_start_machines": true,
"min_machines_running": 0
},
"vm": [{ "size": "shared-cpu-1x", "memory": "256mb" }]
}
orisha:static(site) {
"root": "../../../korulang_org/build",
"fallback": "200.html",
"gzip_only": true,
"disk": ["learn/**", "learn-data/**", "_app/**", "images/**", "fonts/**", "diagrams/**", "*.wasm", "*.png", "*.webp", "*.woff2"],
"embed_max": 524288
}
orisha:handler = orisha:static-router(site)
orisha:serve(port: 3000)
| shutdown s |> std/io:print.ln(s)
| failed f |> std/io:print.ln(f) builds the binary. emits `fly-korulang-site.toml` from the declaration and hands it to flyctl. The config body is a JSON object — the same shape `requires.system` and `command.declare` already speak — and the command translates it: objects become TOML tables, arrays of objects become `[[arrays of tables]]`, scalars become keys. The declaration describes the app in Koru's idiom; fly.toml is a rendering, not the source. Two details in that file did real work in production. The [build(linux)] blocks pin x86_64-linux-musl, which is what lets the artifact run in a FROM scratch image — no libc, no shell, the whole site compiled in or read from /data/static. And the disk/embed_max keys on orisha:static are why the binary stays small at all: the site’s disk tier is ~285 MB (learn/ alone is 205 MB of generated pages), which cannot bake into rodata — the tiers post covers that machinery. What the deploy bought is that none of it needed a second file to describe.
None of the imports in that file are inert, either — this is the part that takes a second to believe. import orisha reaches into lib/index.kz and comes back with ~std/build:requires { exe.linkSystemLibrary("z") } and a zlib requires.system audit: the binary links -lz because a module three directories away asked for it, and reports that check without the app ever naming zlib. requires.npm, requires.system, and build:config declarations all collect transitively through the import graph — the app file shows only what the app itself decided, and the machinery stays in the module that needs it. That is also why the file carries no @korulang/gzip line: Orisha’s compression is its own zlib declarations, and an app that imports the server should not have to know that.
A command is a tor
The mechanism is the one the standard library already ships. std/compiler:command.declare registers a verb; a [comptime|command] tor receives the whole program AST plus argv and runs in the backend phase instead of normal compilation. The fly command walks program.items, finds the fly:config invocations, and treats everything else as noise. Subcommands are argv, passthrough args reach flyctl untouched, and a missing a.out fails loud with the build command rather than deploying a stale artifact.
Declarations are data, commands are verbs
The split is the design. fly:config is [comptime|norun] — a void tor collected from the AST, never executed. Its source: Source parameter is a JSON object the command parses with std.json and re-emits as TOML; reserved keys (region, dockerfile, build, app) are consumed by the command rather than rendered. Same shape as std/build:requires { ... } and std/deps:requires.system { ... }: a Source block of claims the compiler carries and a consumer interprets. The app itself is an Expression parameter — config(korulang-site) binds the bare identifier, which arrives in the AST as a bare argument: had_explicit_label false, the expression text standing in as the arg’s name.
requires.system does one more thing — it declares flyctl itself, with per-platform install hints, so the toolchain audit is part of the same file. collects the declaration transitively through the import and reports:
System dependencies for this project:
zig ✓ (0.15.2)
flyctl ✓ (flyctl v0.5.5 darwin/arm64 ...)
openssl ✓ (4.1.0)
All system dependencies are installed!koru-libs is where wrappers live
fly is a new package in koru-libs, beside docker, curl, and github — the repo whose packages exist to exercise the toolchain and surface its gaps. The import is import koru/fly, resolved through the default koru alias to the sibling checkout; no koru.json, no vendoring. Orisha stays first-class — it is a Koru-native runtime, not a wrapper — while everything that wraps an external tool lives where wrappers belong.
The seams showed immediately, which is the point of the exercise: AST walking needed the module-qualifier spellings (koru.fly, fly, koru/fly all accepted), |zig proc bodies are raw Zig where std.process.Child.run is correct and Koru’s colon syntax does not exist, quoted string args arrive with their quotes — stripQuotes is not optional — and std.json.Value.array is a managed list, so .items is not a detail. Each is a toolchain data point the package was built to surface.
What production taught the cache
The first week on the 256 MB machine produced the deploy’s real lesson, and it was not in the deploy path at all. Disk-tier files are served through a (mtime, size)-keyed cache whose bodies are pinned forever on purpose: body_static responses ride sends as raw-pointer iovecs, so a cached body can never be freed — an in-flight send may still be reading it. That made the cache’s bound a corpus assumption: “the corpus bounds the leak.” The corpus is ~285 MB and the VM’s usable memory is ~210 MB, so Grafana watched memory climb from 51 MB to 97 MB in the first hour and kept going. Crawlers were not leaking connections; they were filling a cache that had no budget.
Eviction was never on the table — you cannot free what a send might still reference. The fix was admission control: the map counts its pinned bytes and stops admitting past STATIC_FILE_CACHE_MAX (48 MB, STATIC_CACHE_MAX_BYTES to override), and over-budget misses take a read-through path that returns an allocated body the pump frees after the send — no eviction needed because nothing is ever pinned. Files past 4 MB still cache regardless, since a body too big for the send buffer cannot take the read-through path; the corpus bounds how many of those exist. The same curve now bends at ~128 MB used and holds, and auto_stop_machines means an idle stop resets it anyway — the memory graph is a sawtooth with a ceiling, not a ramp.
The same program, two substrates
The server description did not have to move when the substrate did. examples/site-unikernel/main.k declares the same orisha static router and orisha:serve — what changes is one build flag: selects a different ~proc run inside orisha/pump and nothing else. wrapper.zig packages the result as libkoruapp.a, and a twenty-line Kraftfile describes the image: no libc, no shell, no OS — just the app and a kernel’s worth of virtio. That artifact runs on Unikraft Cloud. site.k and main.k differ only in what they declare around the same server — Fly gets koru/fly:config, Unikraft gets a Kraftfile — and the application never learns which substrate it is talking to.