Diffinery

homeflare/celldpublic

celld/HOMEFLARE.md
57 lines · 6.0 KBRaw History

celld for Homeflare

A fork of denoland/celld with the patches Homeflare's runtimes need. Upstream stopped at v0.6.3 when celld began merging into workerd, so fixes for gaps Homeflare apps hit land here.

Branches

main is upstream's v0.6.3 plus the patches below, one commit each, so a patch can be dropped once the merged workerd covers it. Rebase onto upstream when it moves:

git remote add upstream https://github.com/denoland/celld.git
git fetch upstream && git rebase upstream/main

Patches

PatchWhy
node:net isIP / isIPv4 / isIPv6; node:dns and node:dns/promises lookup()Fedify checks a URL's host with both before fetching it, so palm's remote lookups failed with node:net.isIP is not implemented in celld. lookup() uses the node's resolver through a new __dns_lookup op, with connect()'s egress rules.
Response.clone() on a streaming bodycelld threw Cannot clone a streaming response before consumption; workerd tees the body, as celld's Request.clone() already did. palm's media proxy returns a fetched image and caches response.clone().
node:url (all but the legacy parse / resolve)celld had no node:url; Fedify's WebFinger handler calls domainToASCII and domainToUnicode. Both run Node's own steps (the input set as a ws://x hostname) through new host ops on the url crate.
node:process as the global processThe module was the throwing stub while globalThis.process existed, so Fedify's User-Agent (Node.js/${process.versions.node}, taken when the global has a Node version) threw on every outgoing request. Found by listing palm's bundle imports.
media binding (Media Transformations)palm makes video thumbnails with env.MEDIA_TRANSFORMS.input(stream).transform(...).output({ mode: "frame" }). The Wrangler media key becomes a binding (config → manifest → WorkerConfig::with_media → __makeMediaBinding) that reads the input and posts it, with both option objects in the x-media-transform header, to CELLD_MEDIA_URL/transform: Homeflare's homeflare-media (ffmpeg). Its answers and {code, message} errors (as MediaError) are the binding's. Without CELLD_MEDIA_URL a result rejects with code 9500.
version_metadata bindingUpstream celld had none, so Homeflare passed the version ID as a plain string. The binding is now Cloudflare's frozen { id, tag, timestamp }. The config may set all three (Homeflare passes its own version ID, tag and time, so they match its Dashboard and wrangler versions); otherwise the id is the deployment's version, the tag is empty and the timestamp is the deploy time.
ratelimits bindingDiffinery limits sign-ins and API calls with env.RL_*.limit({ key }). Each entry becomes a binding counted on the node by a __ratelimit op: fixed windows of the period (10 or 60 s), keyed by namespace id and key and shared by the node's isolates, as each Cloudflare location counts on its own.
send_email binding (Email Sending)Diffinery sends sign-up codes, invitations and notifications with env.EMAIL.send({ from, to, subject, html, text }). The binding checks the message and the binding's allowed_sender_addresses / destination_address / allowed_destination_addresses, then posts it in the REST API's shape ({address, name}, reply_to, base64 attachments) to CELLD_EMAIL_URL/send with CELLD_EMAIL_TOKEN as a bearer. Homeflare relays it to Cloudflare's Email Sending API. The result is { messageId, delivered, queued, permanent_bounces, suppressed_recipients }; API errors become the binding's E_* codes. The legacy raw EmailMessage isn't supported (celld has no cloudflare:email).
Container images in partscelld deploy read the whole docker save output into memory and wrote it in one PUT, which has to finish within the bucket client's 30 s; Diffinery's multi-GB runner image timed out against RustFS, failing every redeploy. The save now streams into a multipart upload of 16 MiB parts (Bucket::put_large), completed only once the save exits successfully. A node loading the image downloads it in 16 MiB ranges to a temporary file (Bucket::get_large) and streams that to the engine's images/load (Docker::post_file). Test: CELLD_TEST_S3_ENDPOINT=... cargo test -p celld --lib large_object_round_trip -- --ignored against any S3 (moto_server works).
Fence in another network namespace (CELLD_FENCE_NETNS)Under rootless Podman the fence's --network host container can't load nftables rules (netlink: Operation not permitted), and the container bridges aren't in the host's namespace anyway: they're in Podman's rootless-netns, which the user owns. With CELLD_FENCE_NETNS=<path> the fence joins that namespace (ns:<path>) and loads FENCE_RULES_NETNS: as FENCE_RULES, plus ct state established,related accept in forward (the node is another container there, so its replies are forwarded) and port 53 to the bridge gateways (aardvark-dns). Unset keeps upstream's behaviour.
homeflare: line in celld --versionLists what this build adds (HOMEFLARE_FEATURES in lib.rs), so Homeflare sends a config key only to a celld that accepts it. Add a feature there with each patch.

Building

Homeflare builds this repo into its runtime image: set HOMEFLARE_CELLD_SOURCE=https://github.com/jason-s13r/celld.git in homeflare.env (see Homeflare's README). By hand, with Podman:

podman build -t localhost/homeflare-celld:dev \
  --build-arg CELLD_COMMIT="$(git rev-parse HEAD)" .

The Dockerfile is upstream's: the image builds only if cargo test and cargo clippy -D warnings pass. --build-arg CELLD_PROFILE=lab swaps fat LTO for thin, which builds much faster.

Smoke tests

Each folder in homeflare/smoke/ is a Worker whose GET / reports its checks as JSON; a paths.txt beside it adds requests that must answer 200 with the given text. With a built celld and esbuild on PATH:

cargo build -p celld
homeflare/smoke/run.sh            # target/debug/celld