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
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/lib/site.ts; `slug` also names the D1 databases (terraform `repo`), the db-migrate parameters and the secret project; `pascal` is the code-identifier form, which nothing here spells (the upstream project is `UptimeFlare`, a different string the rename leaves alone); `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in SOURCE_URL.",
"slug": "uptimeflare",
"pascal": "Uptimeflare",
"productName": "My Status Page",
"domain": "uptimeflare.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
164 changes: 164 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# uptimeflare

A status page that checks itself: lyc8503's
[UptimeFlare](https://github.com/lyc8503/UptimeFlare) — HTTP, HTTPS and TCP
checks every minute, 90 days of uptime bars, latency charts, incident
history, scheduled maintenances, webhook notifications and a JSON API — on
**one Cloudflare Worker**: the status page built by
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare) into Workers +
Static Assets, the checks on the same Worker's **Cron Trigger**, and their
state in a **Cloudflare D1** database that Terraform provisions per
environment and whose schema is applied by migrations before every deploy.

## Live deployment

<!-- 02-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets the site uses into
[ai/context/deployment.md](ai/context/deployment.md); how the site deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 02-docs:end -->

## What is here

| Surface | Where |
|---|---|
| The monitors, links, maintenances and notifications | `apps/web/uptime.config.ts` (every option: `uptime.config.full.ts`) |
| The page's name and source link | `apps/web/lib/site.ts` |
| The status page, the incidents page, their components and translations | `apps/web/pages`, `apps/web/components`, `apps/web/locales` |
| The checker: the checks, incidents, notifications and the stored state | `apps/web/monitor/` |
| The Worker entry: the page's `fetch` + the checker's `scheduled` | `apps/web/worker.ts` |
| The JSON API and the status badge | `apps/web/pages/api/data.ts`, `apps/web/pages/api/badge.ts` |
| The password gate (optional) | `apps/web/proxy.ts` |
| Workers build, trigger, bindings and deploy contract | `apps/web/next.config.mjs`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ `wrangler.jsonc`), `component.yaml` |
| The D1 database (stage, prod) | `infra/terraform/cloudflare-d1` |
| The schema (migrations) and their runner | `packages/db`, applied by `infra/db-migrate` |
| Tests | `tests/web`, `tests/db` (vitest) |

## Configuring the monitors

Everything the page shows is in `apps/web/uptime.config.ts`: `pageConfig`
(title, header links, groups, logo, footer), `workerConfig` (the monitors,
the write cooldown, notifications, callbacks) and `maintenances`. It starts
with three public monitors — Cloudflare and GitHub over HTTPS, Google Public
DNS over TCP — so the page has something to check from its first minute;
replace them with yours. A monitor's `id` keys its history: keep it and the
history stays.

| Monitor kind | `method` | `target` |
|---|---|---|
| HTTP(S), with optional `expectedCodes`, `headers`, `body`, `responseKeyword`, `responseForbiddenKeyword`, `timeout` | `GET`, `HEAD`, `POST`, … | a URL |
| TCP connect | `TCP_PING` | `host:port` |

`globalping://` and `http(s)://` check proxies work; `worker://` proxies
(geo-specific checks in a Durable Object) are not part of this build — such a
monitor says so, or is checked from the Worker with `checkProxyFallback`.
Only each monitor's `id`, `name`, `tooltip`, `statusPageLink` and
`hideLatencyChart` reach the browser. A webhook whose URL embeds a token is a
credential in this file: keep the repository private, or notify from a
`callbacks` function, which receives the Worker's `env`.

## Getting started

```bash
pnpm install
pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next
```

```bash
pnpm --filter @app/web db:migrate:local # create the monitor_state table in wrangler's local D1
pnpm --filter @app/web dev # http://localhost:3000 — the pages, against that D1
pnpm --filter @app/web preview # wrangler dev over the built Worker, same local D1
```

To watch a check run locally, serve the built Worker with a test scheduler
and fire it:

```bash
cd apps/web
pnpm exec wrangler dev --port 8808 --config wrangler.jsonc --test-scheduled
curl "http://127.0.0.1:8808/__scheduled?cron=*+*+*+*+*" # runs the checker once
curl http://127.0.0.1:8808/api/data # the state it wrote
```

## A private status page

Store `user:password` as this repository's Orun secret
`STATUS_PAGE_PASSWORD` for an environment, then redeploy it (below, "Deploy
by hand"): the build hands it to the Worker as a secret, never into a bundle,
and every page and API request then asks for those credentials — the deploy's
own smoke test sends them. Locally, put the same line in `apps/web/.dev.vars`
(see `.dev.vars.example`). Deleting the Orun secret leaves the Worker's copy:
remove that too, with `wrangler secret delete STATUS_PAGE_PASSWORD --name
uptimeflare-web-<env>`.

## How the database is wired

The Worker binds the database as `DB`. Its id is never hand-written:
`apps/web/wrangler.template.jsonc` names it as a wiring token, and
`wrangler.jsonc` is that template rendered — from `wiring.fixture.json`
(placeholder ids) for local work and verification, and on every deploy from
the document the `cloudflare-d1` Terraform root publishes after its apply
(`WIRING_CLOUDFLARE_D1`, per environment). Edit the template, then
`pnpm run wire:fixture` and commit the render with the template.

The schema is `packages/db`'s migrations: each
`src/migrations/<NNN>_<name>/up.sql` is listed in `src/manifest.ts` with its
checksum, and the `db-migrate` component applies the pending ones to each
environment's database before the Worker deploys. The checker keeps one row
in `monitor_state` — the whole compacted state, rewritten when a status
changes and otherwise every three minutes. To change the schema, add a
migration (never edit an applied one — its checksum is recorded), then
`pnpm --filter @saas/db run manifest:fix`.

## How it deploys

Merges to `main` converge through [Orun](https://github.com/sourceplane/orun):
`.github/workflows/ci.yml` plans the changed components and runs each lane
against the workspace in `intent.yaml`. Per environment, the D1 database
applies first, then its migrations, then the Worker builds with that
environment's database id and deploys with its Cron Trigger — to `stage`,
then to `prod` once stage has converged on the same commit; `dev` only
verifies. The Worker is `uptimeflare-web-<env>` on your account's
workers.dev subdomain, and every deploy is smoke-tested: `/api/data` must
carry a check the trigger recorded in the last ten minutes, which only that
Worker, reading its database, can answer. A pull request runs the same
pipeline's verify lanes — the packages type-checked, linted, tested and
built, both test suites, the Worker built and dry-deployed for each
environment — with nothing deployed.

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
Cloudflare tokens (one to deploy, one scoped to D1) and the account id are
brokered per run from the workspace's Cloudflare connection, and the
database ids travel as Orun secrets; nothing provider-shaped is stored in the
repository or in GitHub.

**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run
workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs
`ci.yml` for the environment and components you pick, and each one deploys
exactly as a merge would deploy it. Leave the component blank to redeploy
every component in that environment, with nothing changed: after storing
`STATUS_PAGE_PASSWORD`, say. A component with nothing to run in that
environment (a test suite in `prod`) is left out with a notice.

## Custom domain

The status page answers on workers.dev from its first deploy. To serve it on
your own domain, add the domain to the Cloudflare account the site deploys
into and attach it to the Worker (dashboard → Workers & Pages →
`uptimeflare-web-prod` → Settings → Domains & Routes → Add → Custom
domain). The page renders no absolute link to itself, so nothing else has to
change; the repository names the domain in one place, `BASE_DOMAIN` in
`intent.yaml`, which the site was born with as the reserved placeholder
`uptimeflare.example.com`. Replace it with your domain in the same change
that records it.

## Licence

UptimeFlare is © lyc8503 and its contributors, under the Apache License 2.0
(`apps/web/LICENSE`); the code here derived from it keeps that licence.
30 changes: 30 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole product in one landing. `affects` names COMPONENTS, by
# metadata.name: the phase's retouch hook reads this list to decide which
# component.yaml files get the redeploy marker, so a re-run of the phase has a
# diff and exactly these components are re-planned — the deploy set and the
# task plane's statement of the work are one list.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The product's repository is born and linked, the whole product lands in one pull request, and one convergence applies the D1 database, migrates it and deploys the site on stage and prod
affects:
- cloudflare-d1
- db
- db-migrate
- db-tests
- web
- web-tests
doneWhen:
- repo pushed, main pinned as default, workspace linked
- WIRING_CLOUDFLARE_D1 published on stage and prod
- main convergence green (D1 applied, then migrated, then the site built, deployed and smoke-tested on stage and prod)
- the site answers on both workers.dev URLs
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/02-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 02-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the product's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
152 changes: 152 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by the one product phase,
# that the D1 database's wiring reaches the Worker's config, that a placed
# tree comes up branded and carrying nothing of the factory — and plans the
# database, then its migrations, then the Worker on a merge — and that the
# product it produces installs, builds, migrates, deploys (dry) and serves.
#
# ─── WHY THIS IS NOT IN ci.yml ────────────────────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every site built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a site they
# would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer, wire)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer wire; do
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the site's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what a product would carry, derived by the
# floor too), and the placement tier (the offline bootstrap: both phases
# placed and finished by the blueprint's own hooks, then the product's own
# `orun plan` for the 01-product merge — the D1 apply, then the migrations,
# then the Worker's deploy — under the product's lane pin, below).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
# This job installs nothing either: with no lockfile hook the offline
# bootstrap never runs pnpm, so there is no store, and the pnpm cache
# setup-node v5 turns on by itself (package.json names a packageManager)
# fails the job saving a path that does not exist whenever no earlier
# cache exists for the lockfile.
package-manager-cache: false
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-status \
--set "productname=Acme Status" \
--set githuborg=acme-inc
- name: the leak gate — what a product carries
run: bash testing/leak.test.sh
# The placement tier ENDS with the product's own `orun plan` — what the
# product's ci.yml runs — so it needs an orun at the product's lane pin
# or newer: one older than v2.78.4 plans a pull request with apps/web
# waiting on the D1 and migration plans, because it does not apply a
# dependsOn edge's `modeRules` (advisory on a PR, enforced on main). The
# test refuses an orun older than the pin rather than assert the wrong
# CLI's plan. The offline bootstrap before it reads the blueprint, which
# takes the bootstrap floor (v2.88.0: the task set-up in the background,
# the landings checked in the box), so
# this tier runs the floor, which is newer than the lane pin.
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- name: placement — the offline bootstrap, and the product's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE PRODUCT IT PRODUCES WORKS: its one landing installed, its
# fixture rendered, type-checked, linted, tested and built, the stage lane's own structure check, build
# (the live wiring render included), output check and dry deploy in the tree
# orun stages, the migration lane's plan and apply (against a stand-in D1
# API), and the built Worker served and smoke-tested with the component's
# own smoke command. Pinned at the bootstrap floor (v2.88.0): the offline
# bootstrap reads the blueprint, and the floor is newer than the product's
# lane pin (v2.78.4), which is all the lane steps need.
site:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped product builds, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
Loading
Loading