From 4b57902f1e968cc8f15ec2fa17b88e10a6dede63 Mon Sep 17 00:00:00 2001 From: Erik Goins Date: Thu, 19 Nov 2026 13:33:38 -0500 Subject: [PATCH 1/2] fix: block deploys that bake .env values into the Worker; record first prod deploy The OpenNext build copies apps/web/.env* into .open-next/cloudflare/next-env.mjs, and the Worker loads them into process.env. The first production build baked the development .env.local (secret, tunnel URL, EMAIL_TRANSPORT=console); it was caught before deploy. scripts/check-worker-env.sh now fails cf:deploy when the bundle has baked variables. cf:deploy takes WRANGLER_CONFIG so a git-ignored *.local.jsonc can hold the real D1 id. Decision 034 records the workers.dev URL and the pending sending domain; STATE points at the next step. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T7sHyaEvdoSPjkLy7T1aaz Signed-off-by: Erik Goins --- .gitignore | 3 ++ apps/web/package.json | 2 +- docs/INDEX.md | 1 + docs/STATE.md | 15 ++++---- docs/decisions/034-first-production-deploy.md | 36 +++++++++++++++++++ docs/self-host/README.md | 10 ++++++ scripts/check-worker-env.sh | 18 ++++++++++ 7 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 docs/decisions/034-first-production-deploy.md create mode 100755 scripts/check-worker-env.sh diff --git a/.gitignore b/.gitignore index 7058fa7..4e129fc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ CLAUDE.local.md skills-lock.json .DS_Store + +# Private deploy config with real resource IDs (see docs/self-host/README.md) +*.local.jsonc diff --git a/apps/web/package.json b/apps/web/package.json index d29d691..fe98bc4 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -13,7 +13,7 @@ "predev": "pnpm db:migrate", "db:migrate": "tsx ../../packages/db/src/migrate-cli.ts", "cf:migrate:local": "wrangler d1 migrations apply DB --local", - "cf:deploy": "pnpm cf:build && wrangler d1 migrations apply DB --remote && opennextjs-cloudflare deploy", + "cf:deploy": "pnpm cf:build && bash ../../scripts/check-worker-env.sh .open-next && wrangler d1 migrations apply DB --remote ${WRANGLER_CONFIG:+-c $WRANGLER_CONFIG} && opennextjs-cloudflare deploy ${WRANGLER_CONFIG:+-c $WRANGLER_CONFIG}", "cf:typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts", "test:e2e": "playwright test" }, diff --git a/docs/INDEX.md b/docs/INDEX.md index 517c392..14a48ba 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -43,6 +43,7 @@ | 031 | [Linear features out of scope for v1](decisions/031-v1-scope.md) | | 032 | [Triage is linked-repo issues not on the board](decisions/032-triage.md) | | 033 | [Sync by snapshot ETag, not a change table; no IndexedDB yet](decisions/033-snapshot-etag-sync.md) | +| 034 | [First production deploy: workers.dev URL, sending domain pending](decisions/034-first-production-deploy.md) | ## Features diff --git a/docs/STATE.md b/docs/STATE.md index cffed48..33de7e5 100644 --- a/docs/STATE.md +++ b/docs/STATE.md @@ -1,16 +1,17 @@ # State -Last updated: 2026-11-10 +Last updated: 2026-11-19 ## Resume here - PRs #5–#11 are on `main` (2026-11-10). #9 and #10 landed through #11. Plan: `docs/roadmap.md`, decisions 023–033. -- **Next: first deploy to Cloudflare** (owner approved 2026-11-10: Cloudflare for hosting and - email; instance admins `erikgoins@gmail.com`, `erik@flywheel.so`). Steps in - `docs/self-host/README.md` → Cloudflare. Waiting on the owner for: `wrangler login`, the Workers - Paid plan, and a domain onboarded to Cloudflare Email Service. The deploy doubles as the live - GitHub check: a public URL, no tunnel. +- **Production is deployed** (2026-11-19, decision 034): `https://gitwork.erik-edf.workers.dev`, + D1 `gitwork`, secrets set, health OK. **Sign-in is blocked on email:** no domain is onboarded to + Cloudflare Email Service (`flywheel.so` is on Namecheap DNS). Next: the owner onboards a domain on + Cloudflare DNS → set `EMAIL_FROM` in `apps/web/wrangler.production.local.jsonc` → deploy with + `WRANGLER_CONFIG=wrangler.production.local.jsonc pnpm deploy:cf` (no `apps/web/.env*` present) → + sign in → `/setup` → Create GitHub App on one test repo. That is the live GitHub check. - **iCloud copies files in this repo**, even inside `.git`. Fix: turn off iCloud Desktop & Documents sync, or move the whole `~/Documents/Flywheel` tree (not only `gitwork`: CLAUDE.md discovery and the `../../conventions` import depend on it) and copy the Claude memory folder to the new path key. @@ -20,7 +21,7 @@ Last updated: 2026-11-10 ## In Progress -First Cloudflare deploy (blocked on the owner's account steps, above). +Live GitHub check on production (blocked on the sending domain, above). ## Completed diff --git a/docs/decisions/034-first-production-deploy.md b/docs/decisions/034-first-production-deploy.md new file mode 100644 index 0000000..d4df095 --- /dev/null +++ b/docs/decisions/034-first-production-deploy.md @@ -0,0 +1,36 @@ +# 034 — First production deploy: workers.dev URL, sending domain pending + +Date: 2026-11-19 · Status: accepted + +## Context + +The owner wanted Gitwork running in production, so the GitHub App points at a stable URL and no +tunnel is needed. Production needs a URL (the GitHub App stores it at creation) and a domain on +Cloudflare Email Service for sign-in codes. + +## Decision + +- **URL:** `https://gitwork.erik-edf.workers.dev` (owner's choice over a custom subdomain). +- **Sending domain:** the owner chose a mail subdomain such as `mail.flywheel.so`. Cloudflare Email + Service requires the domain to use Cloudflare DNS, and `flywheel.so` is on Namecheap DNS with + Google Workspace mail. Until a domain on Cloudflare DNS is onboarded, production cannot send + sign-in codes, so nobody can sign in. `EMAIL_FROM` stays a placeholder. +- **Private deploy config:** the real D1 id lives in `apps/web/wrangler.production.local.jsonc` + (git-ignored). `WRANGLER_CONFIG` points `pnpm deploy:cf` at it. +- **Env guard:** the OpenNext build bakes `apps/web/.env*` into the Worker. The first build did so + with the development `.env.local`; it was caught before deploy. `scripts/check-worker-env.sh` now + blocks `pnpm deploy:cf` when the bundle has baked variables. + +## Alternatives considered + +- **Move `flywheel.so` DNS to Cloudflare.** Unblocks `mail.flywheel.so`, but risks company email for + one sender. Not done without the owner's go. +- **A domain already on Cloudflare DNS** (`erikgoins.com`, `ulink.ly`, possibly `gitwork.dev`). + Works today; the owner has not picked one. +- **Console email on Workers.** Rejected: production auth must not log sign-in codes. + +## Consequences + +- Production is deployed and healthy (`/api/v1/health` reports `d1`), but sign-in waits on the + sending domain. Then: set `EMAIL_FROM` in the private config, redeploy, sign in, `/setup`. +- Rollback: `wrangler delete gitwork` and `wrangler d1 delete gitwork`. diff --git a/docs/self-host/README.md b/docs/self-host/README.md index d6eafad..d3ae9eb 100644 --- a/docs/self-host/README.md +++ b/docs/self-host/README.md @@ -85,6 +85,16 @@ pnpm exec wrangler secret put INSTANCE_ADMIN_EMAILS cd ../.. && pnpm deploy:cf # build, migrate D1, deploy ``` +**Build from a checkout without `apps/web/.env*` files** (`.env.example` is fine). The OpenNext build +copies every `.env` value into the Worker, so a development `.env.local` would ship its secret, its +URL, and `EMAIL_TRANSPORT=console`. `pnpm deploy:cf` refuses to deploy such a bundle +(`scripts/check-worker-env.sh`). Move the file aside for the build and put it back after. + +To keep your D1 id out of a public fork, copy `wrangler.jsonc` to `wrangler.production.local.jsonc` +(git ignores `*.local.jsonc`), put the real id there, and deploy with +`WRANGLER_CONFIG=wrangler.production.local.jsonc pnpm deploy:cf`. Pass the same file to +`wrangler secret put -c` and `wrangler tail -c`. + `pnpm deploy:cf` runs D1 migrations before each deploy, so upgrades are `git pull` and `pnpm deploy:cf`. D1 keeps 30 days of point-in-time history (Time Travel) for restores. Reconcile runs from the Cron Trigger in `wrangler.jsonc`. diff --git a/scripts/check-worker-env.sh b/scripts/check-worker-env.sh new file mode 100755 index 0000000..20b0a80 --- /dev/null +++ b/scripts/check-worker-env.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Fails if an OpenNext build baked .env* values into the Worker. `opennextjs-cloudflare build` copies +# every variable from apps/web/.env, .env.local, .env.production, ... into +# .open-next/cloudflare/next-env.mjs, and the Worker loads them into process.env. A developer's +# .env.local would ship its secret, its URL and EMAIL_TRANSPORT=console to production. +# Prints variable names only, never values. +set -euo pipefail +dir="${1:?usage: check-worker-env.sh }" +file="$dir/cloudflare/next-env.mjs" +[ -f "$file" ] || { echo "check-worker-env: $file not found. Run the OpenNext build first." >&2; exit 1; } +keys=$(grep -oE '"[A-Za-z_][A-Za-z0-9_]*":' "$file" | tr -d '":' | sort -u | tr '\n' ' ' || true) +if [ -n "$keys" ]; then + echo "check-worker-env: the Worker bundle contains values from a .env file: $keys" >&2 + echo "Move apps/web/.env* (except .env.example) out of the way and build again. Workers read" >&2 + echo "secrets from 'wrangler secret put' and vars from the wrangler config." >&2 + exit 1 +fi +echo "check-worker-env: $file has no baked variables" From bc43a4c10cb7b9a007f7c8583b72ab7d551c1c95 Mon Sep 17 00:00:00 2001 From: Erik Goins Date: Thu, 19 Nov 2026 13:51:46 -0500 Subject: [PATCH 2/2] docs: production sends email from email.crongent.com (decision 034) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T7sHyaEvdoSPjkLy7T1aaz Signed-off-by: Erik Goins --- docs/INDEX.md | 2 +- docs/STATE.md | 9 ++++----- docs/decisions/034-first-production-deploy.md | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/INDEX.md b/docs/INDEX.md index 14a48ba..a1114e8 100644 --- a/docs/INDEX.md +++ b/docs/INDEX.md @@ -43,7 +43,7 @@ | 031 | [Linear features out of scope for v1](decisions/031-v1-scope.md) | | 032 | [Triage is linked-repo issues not on the board](decisions/032-triage.md) | | 033 | [Sync by snapshot ETag, not a change table; no IndexedDB yet](decisions/033-snapshot-etag-sync.md) | -| 034 | [First production deploy: workers.dev URL, sending domain pending](decisions/034-first-production-deploy.md) | +| 034 | [First production deploy: workers.dev URL, email from email.crongent.com](decisions/034-first-production-deploy.md) | ## Features diff --git a/docs/STATE.md b/docs/STATE.md index 33de7e5..8cb1e37 100644 --- a/docs/STATE.md +++ b/docs/STATE.md @@ -7,11 +7,10 @@ Last updated: 2026-11-19 - PRs #5–#11 are on `main` (2026-11-10). #9 and #10 landed through #11. Plan: `docs/roadmap.md`, decisions 023–033. - **Production is deployed** (2026-11-19, decision 034): `https://gitwork.erik-edf.workers.dev`, - D1 `gitwork`, secrets set, health OK. **Sign-in is blocked on email:** no domain is onboarded to - Cloudflare Email Service (`flywheel.so` is on Namecheap DNS). Next: the owner onboards a domain on - Cloudflare DNS → set `EMAIL_FROM` in `apps/web/wrangler.production.local.jsonc` → deploy with - `WRANGLER_CONFIG=wrangler.production.local.jsonc pnpm deploy:cf` (no `apps/web/.env*` present) → - sign in → `/setup` → Create GitHub App on one test repo. That is the live GitHub check. + D1 `gitwork`, email from `no-reply@email.crongent.com`. Deploy with + `WRANGLER_CONFIG=wrangler.production.local.jsonc pnpm deploy:cf` and no `apps/web/.env*` present. + **Next: the live GitHub check.** The owner signs in, opens `/setup`, creates the GitHub App under + FlywheelStudio, and installs it on one test repo. - **iCloud copies files in this repo**, even inside `.git`. Fix: turn off iCloud Desktop & Documents sync, or move the whole `~/Documents/Flywheel` tree (not only `gitwork`: CLAUDE.md discovery and the `../../conventions` import depend on it) and copy the Claude memory folder to the new path key. diff --git a/docs/decisions/034-first-production-deploy.md b/docs/decisions/034-first-production-deploy.md index d4df095..06eedcb 100644 --- a/docs/decisions/034-first-production-deploy.md +++ b/docs/decisions/034-first-production-deploy.md @@ -1,4 +1,4 @@ -# 034 — First production deploy: workers.dev URL, sending domain pending +# 034 — First production deploy: workers.dev URL, email from email.crongent.com Date: 2026-11-19 · Status: accepted @@ -13,8 +13,8 @@ Cloudflare Email Service for sign-in codes. - **URL:** `https://gitwork.erik-edf.workers.dev` (owner's choice over a custom subdomain). - **Sending domain:** the owner chose a mail subdomain such as `mail.flywheel.so`. Cloudflare Email Service requires the domain to use Cloudflare DNS, and `flywheel.so` is on Namecheap DNS with - Google Workspace mail. Until a domain on Cloudflare DNS is onboarded, production cannot send - sign-in codes, so nobody can sign in. `EMAIL_FROM` stays a placeholder. + Google Workspace mail. For now the owner chose `no-reply@email.crongent.com` (already onboarded, + on Cloudflare DNS). Move to a Flywheel domain later by changing `EMAIL_FROM` and redeploying. - **Private deploy config:** the real D1 id lives in `apps/web/wrangler.production.local.jsonc` (git-ignored). `WRANGLER_CONFIG` points `pnpm deploy:cf` at it. - **Env guard:** the OpenNext build bakes `apps/web/.env*` into the Worker. The first build did so @@ -31,6 +31,6 @@ Cloudflare Email Service for sign-in codes. ## Consequences -- Production is deployed and healthy (`/api/v1/health` reports `d1`), but sign-in waits on the - sending domain. Then: set `EMAIL_FROM` in the private config, redeploy, sign in, `/setup`. +- Production is deployed and healthy (`/api/v1/health` reports `d1`), and sends sign-in codes. + Next: sign in, `/setup`, create the GitHub App under FlywheelStudio. - Rollback: `wrangler delete gitwork` and `wrangler d1 delete gitwork`.