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
- CI / Typecheck and bundlesuccess
- CI / Unit tests (1/2)success
- CI / Unit tests (2/2)success
- Deploy / Deploy to CloudflareFailed
- Deploy / Main's current tipsuccess
- End-to-end / End-to-end (agent reviews, tasks, Today)
- End-to-end / End-to-end (git, PRs, Actions)success
- End-to-end / End-to-end (large pushes)
- End-to-end / End-to-end (passkeys, registry, email)
- End-to-end / End-to-end (real histories)
- End-to-end / End-to-end (runner Docker)
- End-to-end / End-to-end (security)
2 files changed+32−1
modifiedHOMEFLARE.md+17−0View file
| @@ -10,6 +10,8 @@ | ||
| 10 | 10 | itself. |
| 11 | 11 | - `scripts/setup.sh` reading the `/login` page before matching it: `curl | grep -q` |
| 12 | 12 | 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)). | |
| 13 | 15 | |
| 14 | 16 | Rebase onto upstream when it moves: |
| 15 | 17 | |
| @@ -60,6 +62,21 @@ | ||
| 60 | 62 | `homeflare-wrangler` reads the Homeflare API token from `~/.config/homeflare/wrangler.env` and sets |
| 61 | 63 | `CLOUDFLARE_API_BASE_URL` itself. Run it again to update. |
| 62 | 64 | |
| 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 | + | |
| 63 | 80 | ## The first administrator |
| 64 | 81 | |
| 65 | 82 | 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 @@ | ||
| 10 | 10 | // the host's last two labels) and sends email from notifications@<host>. |
| 11 | 11 | // --admins sets BOOTSTRAP_ADMINS (comma-separated emails; bootstrap.sh passes what |
| 12 | 12 | // 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, | |
| 14 | 14 | // TURNSTILE_SITE_KEY (scripts/turnstile.sh, through bootstrap) and the GitHub App of GitHub |
| 15 | 15 | // runners: GITHUB_APP_ID, GITHUB_APP_SLUG, GITHUB_APP_CLIENT_ID and GITHUB_APP_URL. |
| 16 | 16 | import { readFileSync, writeFileSync } from "node:fs"; |
| @@ -57,6 +57,20 @@ | ||
| 57 | 57 | delete c.image_build_context; |
| 58 | 58 | } |
| 59 | 59 | } |
| 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 | +} | |
| 60 | 74 | // The site key of the Turnstile widget scripts/turnstile.sh set up for this hostname (not a |
| 61 | 75 | // secret). One set in wrangler.jsonc is the operator's own and wins; turnstile.sh then leaves it alone. |
| 62 | 76 | if (process.env.TURNSTILE_SITE_KEY && !cfg.vars.TURNSTILE_SITE_KEY) cfg.vars.TURNSTILE_SITE_KEY = process.env.TURNSTILE_SITE_KEY; |