Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ updates:
# init and analyze must be the same release: CodeQL fails when they differ, so a PR that
# bumps one alone can never pass (#270, #272).
codeql-action: { patterns: ["github/codeql-action", "github/codeql-action/*"] }
# The self-host image's workerd (ADR-0047): the version and every platform's checksum in one
# weekly PR, which docker.yml gates (store conformance, the docker, Swarm and Helm smokes, the
# cluster failover test). Not the Miniflare pin of the test suites (ADR-0012), which lives in the
# root workspace.
- package-ecosystem: npm
directory: /deploy/docker/workerd
schedule: { interval: weekly }
allow:
- dependency-name: workerd
commit-message: { prefix: "build(docker)" }
# The self-host image's base image and the compose file's Caddy (docs/guides/self-host.md).
- package-ecosystem: docker
directory: /deploy/docker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Docker image

# The official self-host image, ghcr.io/cloudhal-dev/cloudhal (RFC-0047, docs/guides/self-host.md):
# the release bundle's site and admin Workers on a pinned workerd (deploy/docker/workerd-version),
# the release bundle's site and admin Workers on a pinned workerd (deploy/docker/workerd, bumped weekly by Dependabot: ADR-0047),
# a cluster instance on an S3 store. A release image is built from the npm release and the GitHub
# release's signed bundle, never from the tree, so it is exactly what was released.
# Three jobs, so that no release tag moves before the gates pass (#166):
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ node scripts/release-bundle.ts build|verify … # RFC-0046 release bundle: det
- `packages/core-ts` — `SiteGraphStore` (CAS on `rev`, snapshots, diff, publish, rollback). Behavioural suite in `src/testing.ts` runs on sqlite and Miniflare D1. `./local` opens the offline store; `seedStarterSite` seeds a demo. `./surfaces` is RFC-0020's generative UI: the catalog (primitives + block types), eval-free surface checks, bindings, repairs, JSON Patch (`patchPage`), `catalogPrompt`; `./interop` converts A2UI v0.9 and json-render to and from surfaces; `./design` is RFC-0021's DESIGN.md lint and guidance. `./fields` is RFC-0041's typed custom fields (definition and value checks, `resolveFields`, `formatFieldValue`, the agents' JSON Schema, the conversion table); `src/fields-operations/` runs rename/retype/localize/remove. `search.ts` is RFC-0019's FTS5 site search (index written with the publish batch; articles, pages, terms and authors, RFC-0029); `search-provider.ts` is RFC-0029's `SearchProvider` (`fts5`, `memory`, `withFallback`), set with `SiteGraphStoreOptions.search`; `search-ai.ts` is the experimental Cloudflare AI Search provider (`hybridProvider`, `searchProviderFromEnv`, `cloudhal.json` `search`, docs/guides/search.md).
- `packages/schedules` — RFC-0008: time model (only `temporal-polyfill/implementation`, `now` injected, never `Temporal.Now`), RRULE subset, release model (`rl1:`), automation/run state, taint and budgets, `runDue`; `./sql` is `SqlScheduleStore`, `./engine` the Temporal-free part core-ts and the site Worker use. Worker-safe; conformance suites in `src/testing.ts` on sqlite and Miniflare D1.
- `packages/astro-renderer` — `GraphSource` (live/snapshot), `cloudhal()` integration (virtual config + dev route-cache watcher), `.astro` section components (`Surface.astro` for RFC-0020 surfaces; `./surfaces` renders them, `./kit` has the table of contents and reading time; `./fields` and `EntryFields.astro` render typed field values, RFC-0041). `./status-page` is RFC-0043's status pages (`statusPage(state, input) → Response`, served by the Site Worker entry before Astro and by `cloudhal dev` at `/__cloudhal/status/<state>`; the optional `statusPage` theme hook; the catalog in `src/status-strings/` where only `en.ts` is hand-edited and the other languages come from `pnpm i18n:import`). Routes live in starters, not here.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard and the first site; `deploy/docker/workerd-version` pins workerd, `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cli` — the `cloudhal` CLI (`init`, `dev`, `studio`, `mcp`, `deploy`, `push`, `pull`, `export`, `import`, …; every command is in `src/cli/help.ts`, which `cloudhal --help` prints and the docs site's CLI reference is generated from); TS bin run by Node 24 type stripping. `src/cli.ts` parses flags and dispatches through `COMMANDS`, built from `src/cli/commands-{local,remote,content,ops,site}.ts` (a new command is one handler plus one line in `src/cli/help.ts`). `src/archive/` is RFC-0039's `.cloudhal` container (tar, gzip, manifest, limits), read and written by `src/commands/export.ts` and `import*.ts` (`archive-bundle.ts`, `archive-reassemble.ts`); the starter demo archive `test/fixtures/site-archives/starter-blog.cloudhal` is written by `pnpm demo:archive`, and `pnpm check` fails when it is stale. E2E test spawns the bin (Astro disables dev middleware under `VITEST`). Cloudflare tests run both Workers on workerd via wrangler's `createTestHarness`; test files run serially (shared starter caches). `src/commands/deploy/release/` is RFC-0046 §11b's `deploy --release`: the signed key and yank lists (`trust.ts`, the yank memory in `~/.cloudhal/release-trust.json`), the release lookup and download, the theme check against the CLI's starter (`theme-check.ts`; recheck its build-input list on every Astro or Vite major), the build keys of `src/config-build-keys.ts`, extraction and the `no_bundle` wrangler configs; tests use `@cloudhal/release-verify`'s synthetic bundle (`test/fixtures/release-deploy.ts`), never the network. `src/selfhost/` is RFC-0047's self-host image on workerd (`cloudhal selfhost fetch|check|config|secrets|start`): the settings (`_FILE` secrets), the generated Cap'n Proto config (Durable Object `uniqueKey`s are constants, never change them), the bundle check, the Node-volume guard and the first site; `deploy/docker/workerd/` pins workerd (an npm lockfile Dependabot bumps weekly, ADR-0047; never the Miniflare pin), `scripts/docker-smoke.ts` runs it on SeaweedFS.
- `packages/cloudflare` — the admin Worker (`createAdminWorker`); `./playground` is RFC-0036's playground Worker (`createPlaygroundWorker`, the `PlaygroundSite` Durable Object, signed session cookies). Generated entries must import `@cloudhal/cloudflare/workerd-prelude` first (ADR-0012).
- `packages/agent-runtime` / `packages/mcp-server` — policy, skills, audit; MCP tools and transports (ADR-0011). `@cloudhal/mcp-server/render` is RFC-0021's `render_page` core: a small DevTools client, the in-page checks and limits; the CLI drives local Chrome with it (`render-chrome.ts`), the admin Worker Browser Rendering (`browser-render.ts`).
- `starters/blog` — the theme boundary: `src/pages/[...path].astro`, `src/layouts`, `src/theme.ts`.
Expand Down
1 change: 1 addition & 0 deletions deploy/docker/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Caddyfile
.env.example
.env
.DS_Store
workerd/node_modules
2 changes: 1 addition & 1 deletion deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Built from the npm release and the GitHub release's signed bundle (`CLOUDHAL_VERSION`), or for
# the nightly `edge` tag from packed tarballs in `tarballs/` and this ref's bundle in `bundle/`
# (.github/workflows/docker.yml). workerd's version is pinned in `workerd-version`.
# (.github/workflows/docker.yml). workerd is pinned, with every platform's checksum, in `workerd/` (ADR-0047).

FROM node:24-bookworm-slim AS build
ARG CLOUDHAL_VERSION=""
Expand Down
3 changes: 2 additions & 1 deletion deploy/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

The official self-host image, `ghcr.io/cloudhal-dev/cloudhal`, built from each release ([RFC-0047](../../docs/rfcs/0047-self-host-on-workerd.md)). It runs the release bundle's site and admin Workers on a pinned workerd, as a cluster instance whose state lives in an S3 store. The guide is [docs/guides/self-host.md](../../docs/guides/self-host.md); this folder holds what it refers to:

- **`Dockerfile`:** two stages. The build stage (`node:24-bookworm-slim`) runs `install.mjs`, which installs `@cloudhal/cli` and workerd (`workerd-version`) and lays out the runtime. The final stage is `debian:bookworm-slim` with that runtime only: the `node` binary, the compiled `selfhost` entry (Node built-ins only), the workerd binary and the bundle. It is about 410 MB on disk and 135 MB to download.
- **`Dockerfile`:** two stages. The build stage (`node:24-bookworm-slim`) runs `install.mjs`, which installs `@cloudhal/cli` and workerd and lays out the runtime. The final stage is `debian:bookworm-slim` with that runtime only: the `node` binary, the compiled `selfhost` entry (Node built-ins only), the workerd binary and the bundle. It is about 410 MB on disk and 135 MB to download.
- On linux-arm64, `workerd-no-tcmalloc` can pin a community build of workerd without tcmalloc, for 39-bit kernels such as Raspberry Pi OS's 4 KiB ones. The build checks its SHA-256, and the entrypoint takes it only where the official binary cannot start.
- The release bundle lives under `/opt/cloudhal/bundle`. For a release it is downloaded and verified by `cloudhal selfhost fetch`; for edge it comes from `bundle/` (scripts/selfhost-edge-bundle.ts).
- Runs as non-root with a read-only root, and `/data` and `/tmp` are the only writable paths.
- Ports 8787 (Studio, the API, `/mcp`), 8788 (the site) and 7000 (the cluster).
- **`workerd/`:** the image's workerd, an npm package of its own. `package.json` pins the version, and `package-lock.json` holds the SHA-512 of every platform's binary, which `npm ci` checks at build. Dependabot bumps both weekly, and `docker.yml` gates the PR on the new binary (ADR-0047). It is separate from the Miniflare pin the test suites use (ADR-0012).
- **`bin/entrypoint`:** `cloudhal-selfhost start` by default; `secrets`, `config` and `check` are the other `cloudhal-selfhost` commands (`bin/cloudhal-selfhost`). The CLI itself is not in the image. `start` does these steps:
1. reads the settings (`_FILE` secrets too);
2. refuses a volume of the Node image;
Expand Down
42 changes: 33 additions & 9 deletions deploy/docker/install.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* The image's build stage (Dockerfile, RFC-0047 §9). It installs `@cloudhal/cli` and the pinned
* workerd with plain npm (npm checks each package against the registry's integrity hash), puts the
* The image's build stage (Dockerfile, RFC-0047 §9). It installs `@cloudhal/cli` with plain npm and
* the pinned workerd with `npm ci` from `workerd/package-lock.json`, which holds the SHA-512 of
* every platform's package (ADR-0047: Dependabot bumps the version and the checksums together, and
* npm refuses a tarball that does not match). It puts the
* release bundle of the image's version under `<target>/runtime/bundle` and checks it file by
* file, then lays out `<target>/runtime`, the only thing the last stage copies:
*
Expand All @@ -26,7 +28,11 @@ import path from "node:path";

const [ctx = "/ctx", target = "/opt/cloudhal"] = process.argv.slice(2);
const version = process.env.CLOUDHAL_VERSION?.trim() || undefined;
const workerd = readFileSync(path.join(ctx, "workerd-version"), "utf8").trim();
const workerdDir = path.join(ctx, "workerd");
const workerd = JSON.parse(readFileSync(path.join(workerdDir, "package.json"), "utf8")).dependencies
.workerd;
if (!/^\d+\.\d{8}\.\d+$/.test(workerd))
throw new Error(`workerd/package.json must pin an exact workerd version (got ${workerd})`);
const index = path.join(ctx, "tarballs", "index.json");
const runtime = path.join(target, "runtime");

Expand All @@ -47,7 +53,7 @@ function specs() {
}

const all = specs();
const dependencies = { "@cloudhal/cli": all["@cloudhal/cli"], workerd };
const dependencies = { "@cloudhal/cli": all["@cloudhal/cli"] };
const overrides = Object.fromEntries(
Object.entries(all).filter(([name]) => !(name in dependencies)),
);
Expand Down Expand Up @@ -94,12 +100,26 @@ cpSync(path.join(target, "node_modules/@cloudhal/cli/dist/src/selfhost"), selfho
});
writeFileSync(path.join(selfhost, "package.json"), '{ "type": "module" }\n');

// 3. workerd: the platform binary itself, not npm's launcher
// 3. workerd: the platform binary itself, not npm's launcher, installed from the lockfile (its
// integrity hashes are the checksum pin; no install scripts run)
const platform = { x64: "linux-64", arm64: "linux-arm64" }[process.arch];
if (!platform) throw new Error(`workerd has no Linux build for ${process.arch}`);
execFileSync(
"npm",
["ci", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund", "--loglevel=error"],
{ cwd: workerdDir, stdio: "inherit" },
);
const installed = JSON.parse(
readFileSync(
path.join(workerdDir, `node_modules/@cloudflare/workerd-${platform}/package.json`),
"utf8",
),
).version;
if (installed !== workerd)
throw new Error(`workerd/package-lock.json installs ${installed}, package.json pins ${workerd}`);
mkdirSync(path.join(runtime, "bin"), { recursive: true });
cpSync(
path.join(target, `node_modules/@cloudflare/workerd-${platform}/bin/workerd`),
path.join(workerdDir, `node_modules/@cloudflare/workerd-${platform}/bin/workerd`),
path.join(runtime, "bin/workerd"),
);
chmodSync(path.join(runtime, "bin/workerd"), 0o755);
Expand All @@ -111,9 +131,13 @@ const pin = Object.fromEntries(
.filter((l) => l.includes("=") && !l.startsWith("#"))
.map((l) => [l.slice(0, l.indexOf("=")).trim(), l.slice(l.indexOf("=") + 1).trim()]),
);
if (process.arch === "arm64" && pin.version) {
if (pin.version !== workerd)
throw new Error(`workerd-no-tcmalloc pins ${pin.version}, but workerd-version is ${workerd}`);
// A weekly workerd bump (ADR-0047) does not wait for the community build: until one of the new
// version is pinned, the arm64 image carries no fallback, and a 39-bit kernel gets the message.
if (process.arch === "arm64" && pin.version && pin.version !== workerd)
console.warn(
`warning: workerd-no-tcmalloc pins ${pin.version}, not workerd ${workerd}: no fallback for 39-bit kernels in this image`,
);
else if (process.arch === "arm64" && pin.version) {
if (!/^[0-9a-f]{64}$/.test(pin.sha256 ?? "") || !pin.url?.startsWith("https://"))
throw new Error("workerd-no-tcmalloc: version, sha256 and an https url are all required");
const res = await fetch(pin.url);
Expand Down
7 changes: 4 additions & 3 deletions deploy/docker/workerd-no-tcmalloc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# The tcmalloc-free linux-arm64 workerd for 39-bit kernels (Raspberry Pi OS's 4 KiB kernels;
# cloudflare/workerd#5020), from the community builds at github.com/pdragun/workerd-no-tcmalloc
# (upstream source, `use_tcmalloc=False`). Used only where the official build cannot start, and
# only when its version equals workerd-version. Fill in all three lines when that release exists:
# the SHA-256 is checked at image build. Empty: the arm64 image carries no fallback, and a 39-bit
# kernel gets a message saying what to do.
# only when its version equals the image's workerd (workerd/package.json). Fill in all three lines
# when that release exists: the SHA-256 is checked at image build. Empty, or behind a weekly bump
# (ADR-0047): the arm64 image carries no fallback, and a 39-bit kernel gets a message saying what to
# do.
version=
sha256=
url=
1 change: 0 additions & 1 deletion deploy/docker/workerd-version

This file was deleted.

Loading