Diffinery

homeflare/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

feat(scripts): CONTAINER_MAX_INSTANCE_TYPE caps the containers' instance types

For a machine smaller than Cloudflare's (Homeflare), where celld reserves a container's whole instance type.
Jason Schwarzenberger authored 1 parent 4bc6992commit 9a5b1237e389934a1ee18b363a356c35c9d1ddf3Browse files
2 files changed+32−1
modifiedHOMEFLARE.md+17−0View file
@@ -10,6 +10,8 @@
1010 itself.
1111 - `scripts/setup.sh` reading the `/login` page before matching it: `curl | grep -q`
1212 fails under `pipefail` when grep stops early.
13+- `CONTAINER_MAX_INSTANCE_TYPE` in `scripts/render-config.mjs`, for a machine smaller than Cloudflare's
14+ ([Container sizes](#container-sizes)).
1315
1416 Rebase onto upstream when it moves:
1517
@@ -60,6 +62,21 @@
6062 `homeflare-wrangler` reads the Homeflare API token from `~/.config/homeflare/wrangler.env` and sets
6163 `CLOUDFLARE_API_BASE_URL` itself. Run it again to update.
6264
65+### Container sizes
66+
67+celld reserves each running container's whole instance type: a large runner (`standard-4`) books 12 GiB
68+and 4 vCPUs, so a few at once fill a home machine. celld starts a container only while the running ones'
69+reservations fit its container budget (`CELLD_CONTAINER_MEMORY_MB` in Homeflare's `homeflare.env`; 80% of
70+the machine's memory by default); past it, a job waits for one to finish. For more jobs at once, raise that
71+budget (reservations are caps, rarely all used), or make the containers smaller:
72+
73+```sh
74+CONTAINER_MAX_INSTANCE_TYPE=standard-3 # in diffinery.env: no container above 2 vCPUs / 8 GiB
75+```
76+
77+Every container class above it (large and medium runners, imports) then runs on it, with its vCPUs too:
78+`standard-2` is 1 vCPU and 6 GiB, so builds slow down. Unset, each class keeps `wrangler.jsonc`'s type.
79+
6380 ## The first administrator
6481
6582 Without Access, the first account comes from open sign-up, which needs Turnstile and email. Deploy once with
modifiedscripts/render-config.mjs+15−1View file
@@ -10,7 +10,7 @@
1010 // the host's last two labels) and sends email from notifications@<host>.
1111 // --admins sets BOOTSTRAP_ADMINS (comma-separated emails; bootstrap.sh passes what
1212 // scripts/bootstrap-admins.sh found). Without it, wrangler.jsonc's value stays.
13-// From the environment it takes RUNNER_IMAGE (scripts/runner-image.sh),
13+// From the environment it takes RUNNER_IMAGE (scripts/runner-image.sh), CONTAINER_MAX_INSTANCE_TYPE,
1414 // TURNSTILE_SITE_KEY (scripts/turnstile.sh, through bootstrap) and the GitHub App of GitHub
1515 // runners: GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_CLIENT_ID and GITHUB_APP_URL.
1616 import { readFileSync, writeFileSync } from "node:fs";
@@ -57,6 +57,20 @@
5757 delete c.image_build_context;
5858 }
5959 }
60+// The largest instance type a container may have, for a machine smaller than Cloudflare's fleet
61+// (Homeflare): a class above it (runners, imports, sandboxes) runs on it instead. celld reserves a running container's whole
62+// instance type, so four 12 GiB large runners fill a 60 GiB machine. The capped class has the smaller
63+// type's vCPU and memory, though src/runner/sizes.ts still names the larger. Unset, nothing changes.
64+const INSTANCE_TYPES = ["lite", "basic", "standard-1", "standard-2", "standard-3", "standard-4"];
65+const typeRank = (t) => INSTANCE_TYPES.indexOf({ dev: "lite", standard: "standard-1" }[t] ?? t);
66+const maxType = process.env.CONTAINER_MAX_INSTANCE_TYPE?.trim();
67+if (maxType) {
68+ if (typeRank(maxType) < 0) throw new Error(`CONTAINER_MAX_INSTANCE_TYPE must be one of ${INSTANCE_TYPES.join(", ")}`);
69+ for (const c of cfg.containers) {
70+ // A custom instance type (an object) is the operator's own choice; leave it.
71+ if (typeof c.instance_type === "string" && typeRank(c.instance_type) > typeRank(maxType)) c.instance_type = maxType;
72+ }
73+}
6074 // The site key of the Turnstile widget scripts/turnstile.sh set up for this hostname (not a
6175 // secret). One set in wrangler.jsonc is the operator's own and wins; turnstile.sh then leaves it alone.
6276 if (process.env.TURNSTILE_SITE_KEY && !cfg.vars.TURNSTILE_SITE_KEY) cfg.vars.TURNSTILE_SITE_KEY = process.env.TURNSTILE_SITE_KEY;