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
1 change: 1 addition & 0 deletions specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace.

| Epic | Cluster | Status | What it is |
|------|---------|--------|------------|
| [`microcms-blog/`](./microcms-blog/) | **MC** | In progress (MC0) | Vercel's Next.js Blog with microCMS on Cloudflare Workers + Static Assets through OpenNext, the service and its key read per request from the Worker, deployable before a microCMS service exists, and an Orun baseline that instantiates it in one landing (MC2) |

As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
11 changes: 11 additions & 0 deletions specs/epics/microcms-blog/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# microcms-blog — implementation status

| Milestone | State | Landed |
|---|---|---|
| MC0 — the spec | ✅ | the repository's first commit, MC-1 |
| MC1 — the blog on Workers | planned | MC-2 |
| MC2 — a baseline | planned | MC-3 |

## Departures from the upstream template

Recorded as they land, from MC1 on.
34 changes: 34 additions & 0 deletions specs/epics/microcms-blog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# microcms-blog — Vercel's Next.js Blog with microCMS on Cloudflare Workers

**microCMS's Simple Blog, rendered on request by one Cloudflare Worker from a
microCMS service — its static assets beside it, the service and its key the
Worker's secrets — deployed by Orun to stage and prod on every merge, live
before its owner has a service at all, and the baseline that makes a copy of
it somebody else's blog in one landing.**

| | |
|---|---|
| Status | In progress — MC0 on main |
| Upstream | [microcmsio/simple-blog-with-microcms](https://github.com/microcmsio/simple-blog-with-microcms) (MIT, © 2023 microCMS), at `4077da9` (2026-11-11) — Vercel's "Next.js Blog with microCMS" template |
| Reference | [cms-contentful](https://github.com/sourceplane/cms-contentful) — the same scaffolding, tests, bootstrap and unconnected sample mode; [algolia-search](https://github.com/sourceplane/algolia-search) — keys pushed to the Worker after the build and read per request |
| Key | `MC` |

## Read in this order

1. [design.md](design.md) — the template, how each Vercel piece maps to
Cloudflare, what the spike proved, the unconnected blog, the repository and
the build, and the alternatives rejected.
2. [implementation-plan.md](implementation-plan.md) — the milestones and
what each one lands.
3. [risks-and-open-questions.md](risks-and-open-questions.md) — what is not
proven, and what was accepted.
4. [IMPLEMENTATION-STATUS.md](IMPLEMENTATION-STATUS.md) — what shipped, and
every departure from the upstream template.

## Milestones

| Milestone | What it lands | Task |
|---|---|---|
| MC0 — the spec | the repository, its intent, CI, tooling and spec index; this doc set | MC-1 |
| MC1 — the blog on Workers | the template in `apps/web`, built by OpenNext into one Worker, the keys read per request, its unconnected sample mode; `tests/web` | MC-2 |
| MC2 — a baseline | the console card, the build document, the context pack and the baseline's tests | MC-3 |
100 changes: 100 additions & 0 deletions specs/epics/microcms-blog/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# microcms-blog — design

## 1. The template

Vercel's "Next.js Blog with microCMS" is microCMS's own
[Simple Blog](https://github.com/microcmsio/simple-blog-with-microcms)
(Next.js 16 App Router, React 19, CSS Modules): a blog whose content is in a
microCMS service's three **list** APIs — `tags` (a name), `writers` (name,
profile, image) and `blog` (title, description, rich-text content,
thumbnail, tags, writer), exported in `microcms-template.json`. The home page
and `/p/<n>` list ten posts a page; `/blogs/<id>` renders one, its rich-text
HTML's code blocks highlighted on the server with highlight.js through
cheerio, with its writer and tags; `/tags/<id>` and `/search?q=` (microCMS's
full-text search) list posts with their own pages. Every read goes through
`microcms-js-sdk` (`libs/microcms.ts`), which threw at module load without
`MICROCMS_SERVICE_DOMAIN` and `MICROCMS_API_KEY`. A draft opens at
`/blogs/<id>?dk=<draft key>`. `next.config.js` sets `CDN-Cache-Control`
(60 s, then 300 s stale) on every route, and a Node `proxy.ts` (Next 16's
middleware) replaced it with `no-store` on a draft.

## 2. How it maps to Cloudflare

| Vercel | Here | Why |
|---|---|---|
| Next.js hosting | One Worker built by `@opennextjs/cloudflare` (`output: 'standalone'`), `public/` and the client chunks in its Static Assets, the static-assets incremental cache | Nothing in the Worker is revalidated |
| Env vars read by the build and the server; pages pre-rendered from the service at build | The service and its key: optional Orun secrets, unset for the build (`env -u`), pushed to the Worker as secrets after it (`tooling/wire/worker-secrets.mjs`) and read per request from `getCloudflareContext().env`; the layout `force-dynamic` | No bundle carries a key; a key stored or rotated later reaches the Worker on the next deploy without a build seeing it |
| `proxy.ts` (Node runtime) | A second `headers()` rule (`/blogs/:path*` with `has: query dk`), after the template's catch-all | OpenNext builds a Node proxy only experimentally ("not officially maintained"), and under it the proxy's header was appended to the catch-all's (`no-store, must-revalidate, public, s-maxage=60, …`); the later `headers()` rule replaces it |
| Vercel's CDN honours `CDN-Cache-Control` | The header is kept; nothing caches on workers.dev | A Worker's responses are not cached by Cloudflare's CDN on workers.dev; microCMS's CDN fronts its content API |
| `next/image` for three local files | `images.unoptimized` | No optimiser in the Worker; microCMS's images keep their image-API query strings |
| `BASE_URL` in the dashboard | `BASE_URL` inlined at build by `next.config.js`, set per environment by the deploy (`SITE_URL` or the workers.dev URL) | The origin is no secret, and every page needs it |

**What the spike proved** (Next 16.4.5, OpenNext 1.20.16, `wrangler dev`):
OpenNext 1.20.16's peer range is `>=15.5.29 <16 || >=16.4.5`, so the
template's 16.4 line stays, at 16.4.5. cheerio 1.2 and highlight.js 11 run on
workerd. The SDK client created per request reads a stand-in's list, detail,
tag filter, search and draft key, with the key in `X-MICROCMS-API-KEY`. The
Worker is 1.9 MiB gzipped, inside Workers Free's 3 MiB.

## 3. The unconnected blog

The platform brokers Cloudflare, not microCMS, so a bootstrap deploys a blog
whose owner has no service yet. Upstream would throw at module load and
every page would be a 500. Here, while the Worker lacks either value,
`libs/microcms.ts` hands every read to `libs/sample.ts`: a client with the
SDK's `getList` and `getListDetail` over three posts, two tags and a writer
in the template's API shapes (limit, offset, the tag filter and the search
included, an unknown id a 404). The layout shows a "not connected" notice
(`data-microcms-notice="unconnected"`), and the first post is the connect
steps. cms-contentful's pattern, kept to the same shape: the e2e tier and the
deployment record read the notice.

## 4. The repository

cms-contentful's shape (turso v8): `apps/web` (type
`cloudflare-workers-assets-turbo`, lane `isolated`) and `tests/web` (type
`turbo-package`, a vitest suite run on the `dev` rung). No infrastructure:
microCMS is a hosted service. The blog's name is one seam, `SITE_NAME` in
`app/site.ts`, read by the title template, the Open Graph title, the logo's
alt text and the footer. The upstream template's links name microCMS but not
this slug, so the rename engine needs no protection for them.

## 5. The build

`next build` (Turbopack), `opennextjs-cloudflare build --skipBuild`, then
`populateCache local`; the component's build step then runs
`worker-secrets.mjs`, which is a no-op in a verify lane (no Cloudflare
credential) and pushes the resolved secrets in a deploy lane.
`repo-blueprint.yaml` is cms-contentful's: one landing (`01-product`)
places, brands and lands the whole tree, one convergence builds and deploys
stage and prod side by side, and `02-docs` records what went live. The smoke
checks the home page renders (its footer) and a missing article is a 404.

## 6. Testing the connected blog

microcms-js-sdk (3.5 and 3.6) builds `https://<service>.microcms.io/api/v1`
itself and calls the global `fetch`, with no host or fetch option. The
product keeps the SDK untouched; the e2e tier serves the SAME build behind
its own entry (`testing/lib/e2e-worker.mjs`), which wraps the global fetch
before the Worker's modules load and sends `*.microcms.io` requests to a
local stand-in (`testing/lib/fake-microcms.py`, the three APIs as microCMS
answers them, the key checked). `tests/web` covers the same reads with a
stubbed fetch.

## 7. Out of scope

- A cache in the Worker (OpenNext's R2 incremental cache, or the Cache API
on a custom domain): an upgrade for a busy blog (risk MC-C).
- Creating the microCMS service or its APIs in the bootstrap: no platform
connection holds microCMS credentials.

## 8. The alternatives rejected

- **Keys at build, pages pre-rendered (as on Vercel).** A build would need
the service, which a fresh product lacks, and the key would sit in the
bundle; a published post would need a rebuild to appear.
- **Keeping `proxy.ts`.** Experimental on OpenNext, and wrong there: its
header was appended, not set.
- **A test seam in the product** (an env var pointing the SDK elsewhere).
The SDK has no such option, and patching the product's fetch for tests
would ship test code; the e2e's own entry does it outside the product.
32 changes: 32 additions & 0 deletions specs/epics/microcms-blog/epic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# The epic's declaration. metadata.name equals the directory name; metadata.key
# is the task-key prefix this epic reserves (MC → MC-1, MC-2, …). Owner, target
# date and health are the platform's — never written here.
apiVersion: orun.io/v1
kind: Epic
metadata:
name: microcms-blog
key: MC
spec:
title: "Vercel's Next.js Blog with microCMS on Cloudflare Workers"
summary: "Vercel's Next.js Blog with microCMS — microCMS's Simple Blog template: posts, tags and writers read through microCMS's SDK, code highlighted on the server, posts by tag, full-text search, pages of ten and drafts by their draft key — runs on Cloudflare Workers + Static Assets through @opennextjs/cloudflare, the service and its key read per request from the Worker and never built in, inside the Cirrus baseline's repository conventions, and becomes an Orun baseline that takes a new blog from nothing to live on stage and prod in one landing, serving sample posts until its owner connects a service."
state: started
milestones:
- name: "MC0 — the spec"
exitCriteria:
- "the repository is born with its intent, CI, tooling and spec index, and this doc set and the task contracts are on main"
tasks: [MC-1]
- name: "MC1 — the blog on Workers"
exitCriteria:
- "apps/web is the upstream template, built by next build, then by OpenNext into one Worker with Static Assets, every page rendered on request"
- "the service and its key are read per request from the Worker; with neither the blog serves sample posts under a notice that says how to connect"
- "the template's proxy.ts rule is a headers() rule: a draft (?dk=) is never cached, everything else keeps the template's CDN-Cache-Control"
- "`pnpm typecheck`, `pnpm lint`, `pnpm test` and `pnpm build` are green"
- "`wrangler dev` serves the home page, every sample post, a tag, a search, a second page and the 404s, and — connected to a local stand-in for microCMS's content API — the service's posts, an article with its writer, a draft and a tag"
- "the README says how to run, test, preview, connect and deploy it, and how every Vercel piece maps to Cloudflare"
tasks: [MC-2]
- name: "MC2 — a baseline"
exitCriteria:
- "blueprint.yaml (the console card) and repo-blueprint.yaml (the build) take a new blog from nothing to live on stage and prod in one landing, then record it"
- "a blog built from it carries the blog only, renamed throughout to its own name, repository and Worker, with the template's links and microCMS's variable names intact"
- "Baseline CI is green: contract tests (the deployment record rendered without PyYAML among them), generated component docs, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the end-to-end tier"
tasks: [MC-3]
45 changes: 45 additions & 0 deletions specs/epics/microcms-blog/implementation-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# microcms-blog — implementation plan

Three milestones, each one reviewed pull request (MC0 is the repository's
first commit), each green before it merges.

## MC0 — the spec (MC-1)

The repository is born: `intent.yaml` with the placeholder workspace
`ws_CHANGE_ME`, `ci.yml` (byte for byte turso-starter's, which plans nothing
until the workspace is set), the shared TypeScript and ESLint configuration,
the spec index, this doc set and the task contracts.

## MC1 — the blog on Workers (MC-2)

- The template's `app/`, `components/`, `constants/`, `libs/`, `public/`,
`microcms-template.json`, ESLint and TypeScript configuration and LICENSE
in `apps/web`; Next pinned to 16.4.5 with `@opennextjs/cloudflare` 1.20.16
and `wrangler`.
- `next.config.js`: `output: 'standalone'`, the workspace root for the trace,
`images.unoptimized`, `BASE_URL` inlined; the template's `headers()` kept
and `proxy.ts`'s rule moved in. `open-next.config.ts` with the
static-assets incremental cache; `wrangler.jsonc`; `cloudflare-env.d.ts`.
- `libs/microcms.ts`: the service and key read per request, the SDK client
per request, the sample client when either is missing; the layout
`force-dynamic`.
- The unconnected sample mode: `libs/sample.ts`, `public/sample`,
`components/ConnectMicroCMS`.
- `SITE_NAME` in `app/site.ts`.
- `component.yaml`: the deploy contract, the service's optional secret refs
unset for the build and pushed by `tooling/wire/worker-secrets.mjs`, and
the smoke. `tests/web`: the reads and their fallback, the highlighting,
the components, the cache headers and the sample content.
- The README's "How it maps to Vercel".

## MC2 — a baseline (MC-3)

cms-contentful's machinery, renamed: `blueprint.yaml`, `repo-blueprint.yaml`,
`.baseline/` (identity, the product's README with "Connect microCMS", task
contracts), `tooling/rebrand`, `tooling/bootstrap`,
`hooks/render-deployment-docs.sh` (standard library only; probing `/` and a
missing article, and recording whether each blog reads a service yet) with
`testing/render.test.sh`, `docs/phases/`, the context pack, `testing/` (the
leak and placement gates on this tree's files; the e2e tier reading every
route unconnected and then connected to `testing/lib/fake-microcms.py`
through `testing/lib/e2e-worker.mjs`) and `baseline.yml` / `tag.yml`.
15 changes: 15 additions & 0 deletions specs/epics/microcms-blog/risks-and-open-questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# microcms-blog — risks and open questions

| ID | Risk | State | Notes |
|---|---|---|---|
| MC-A | `baseline-v1` is not yet proven live | OPEN | Proven offline in Baseline CI: the offline bootstrap with the blueprint's own hooks, the stage lane's own steps in a staged job tree (with the microCMS secrets set and kept out of the build), the blog served by `wrangler dev` and smoke-tested with the component's own command. A console bootstrap closes it, including the first `wrangler secret bulk` from a deploy lane |
| MC-B | No real microCMS service has been read | OPEN | The connected path is proven against a local stand-in in the shapes `microcms-template.json` defines (list, detail, tag filter, search, draft key, the key checked). The first connected product closes it |
| MC-C | Every page view is a content-API request | ACCEPTED | The layout reads the tags and each page its posts; microCMS's CDN answers them, and its plan's limits apply. Cloudflare does not cache a Worker's responses on workers.dev; a busy blog's upgrade is a cache in the Worker or a custom domain with the Cache API |
| MC-D | Setting a secret redeploys nothing | ACCEPTED | The deploy is what pushes the secrets to the Worker; the owner redeploys by hand or with the `# orun: redeploy` stamp in `apps/web/component.yaml` (README, "Connect microCMS") |
| MC-E | The API key is a Worker secret | ACCEPTED | Read per request by server code only; no bundle or browser carries it (the e2e greps the build for it). Use a key with GET permission only, as microCMS's default key is |
| MC-F | A draft's `no-store` depends on Next's header precedence | ACCEPTED | The later `headers()` rule wins for the same key; `tests/web` pins the rules and the e2e reads the header, unconnected and connected |
| MC-G | Next 16.4.5 and @opennextjs/cloudflare 1.20.16 move together | WATCH | Each OpenNext release raises its Next floor (1.20.16: `>=16.4.5` on the 16 line); bump both in one change |
| MC-H | A wrong service ID or key makes every page the 404 page | ACCEPTED | As upstream: the SDK's refused read is `notFound()`, and the layout reads `tags` on every page. BOOTSTRAP.md's troubleshooting names the causes |
| MC-I | stack-tectonic 0.19.0, not 0.20.0 | ACCEPTED | 0.20.0's lane-shared install links each job's `node_modules` out of its tree, which Turbopack refuses |
| MC-J | The e2e's entry relies on Next capturing the global fetch when its server starts | WATCH | Test-only: if OpenNext changes how it loads the server, `testing/lib/e2e-worker.mjs` follows; the connected checks fail loudly if the stand-in sees nothing |
| MC-K | The local tiers ran on Node 26 | ACCEPTED | Homebrew's node@22 is broken on the build machine; Baseline CI runs Node 22, and the template's packages all admit it |
15 changes: 15 additions & 0 deletions tasks/MC-1.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: MC-1
title: "The spec"
spec:
goal: The microcms-blog repository is born with its intent, CI, tooling and spec index, and the microcms-blog epic — declaration, doc set and task contracts — is on main
affects:
- specs/epics/microcms-blog
- specs/epics/README.md
- tasks
doneWhen:
- epic.yaml, README, design, implementation plan, risks and status are on main
- the three task contracts exist
gates: []
19 changes: 19 additions & 0 deletions tasks/MC-2.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: MC-2
title: "The blog on Workers"
spec:
goal: Vercel's Next.js Blog with microCMS runs on Cloudflare Workers + Static Assets through OpenNext, the service and its key read per request from the Worker, deployable before a microCMS service exists, with its tests and a README that says how it maps to Vercel
affects:
- apps/web
- tests/web
- tooling/wire
- pnpm-lock.yaml
- pnpm-workspace.yaml
- README.md
- .gitignore
doneWhen:
- pnpm typecheck, lint, test and build are green
- wrangler dev serves the home page, every sample post, a tag, a search and the 404s with no service behind it, and the service's posts, an article and a draft from a local stand-in
gates: []
29 changes: 29 additions & 0 deletions tasks/MC-3.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: orun.io/v1
kind: TaskContract
metadata:
name: MC-3
title: "microcms-blog becomes an Orun baseline"
spec:
goal: blueprint.yaml and repo-blueprint.yaml take a new microCMS-backed blog from nothing to live on stage and prod in one landing, held by Baseline CI
affects:
- blueprint.yaml
- repo-blueprint.yaml
- BOOTSTRAP.md
- .baseline
- .github/workflows/baseline.yml
- .github/workflows/tag.yml
- ai/context
- docs/phases
- hooks
- testing
- tooling/rebrand
- tooling/bootstrap
- tooling/catalog
- apps/web/docs
- tests/web/docs
- specs/epics/microcms-blog
- README.md
doneWhen:
- every Baseline CI tier is green
- a blog placed from it carries the blog only, branded, with the template's links and microCMS's variable names intact
gates: []
Loading