mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:19:41 +01:00
* fix(hardcoded): give every duplicated constant one home A sweep of all 44 repos' default branches for literals that duplicate an existing source of truth. Loki's share, in four groups. WRONG, and live on the public footer. src/config/fleet-site-copy.ts still called the Zürich clinic "VitaReBa", a name retired on 2026-09-10 — its own title says "Vita · Metabolische Psychiatrie & Systemische Longevity". The generated fleet-sites.ts carried it onto loki.orangecat.ch, where it was serving until this commit. Fixed at the copy file, which is the one place that owns a site's own words, and the footer regenerated from it. WOULD HAVE WRITTEN STALE DATA. scripts/seed-fleet-site-urls.ts kept a hand-typed slug → URL map "read 2026-08-06". Two of its fifteen entries pointed at hosts retired since (aoz-wohnen.orangecat.ch, revampit.orangecat.ch), so running it would have filled empty live_url columns with addresses that only 308. It now derives the map from apps.conf — the same register the footer is generated from — which also fixes the six live sites the hand list never had. Verified: 19 sites, zero retired hosts. THE BOX ADDRESS, in seven places. scripts/hetzner/_box-env.sh has been the SSOT for it all along and sixteen scripts source it; four did not, and the shared deploy workflow — reused by ~20 repos — had the IP inline twice, so moving the box meant twenty edits. The workflow now reads the org-level Actions variable HETZNER_IP and fails loudly if it is unset, rather than ssh-ing to an empty string. loki's own deploy.yml had `vars.HETZNER_IP || '<literal>'`, a fallback that guaranteed the variable was never needed and so never noticed if wrong. ONE LAPTOP, baked into shipped code. site-cd-local.ts listed /home/g/.ssh and /home/ubuntu/.ssh as deploy-key candidates beside os.homedir() — which already IS those paths, since loki-app runs as `ubuntu` and a laptop runs as its owner; both spelled one homedir for one named person. install-push-deploy.sh wired hooks to /home/g/dev/loki, link-prod-runtime.ts to /home/g/dev/bitbaum, and scripts/fleet printed an install line only true on one machine: all now DEV_ROOT or the script's own resolved path. The two scripts in scripts/local are INSTALLED BY COPY into ~/.local/bin and run there by systemd timers, so they resolve _box-env.sh beside the real file first, then under DEV_ROOT, and exit loudly if neither exists — a security check that cannot find its target must not look like one that found nothing. Deliberately unchanged: the slug alias map (the mechanism that makes a rename safe), an executed migration's data row, the retired-handle detector's own handle list, and test fixtures reproducing past incidents. Verified: fleet-sites-derived in sync (14 sites), bash -n on every edited script, and the branch's only remaining literals are in scripts/test fixtures. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(push-deploy): the generated hook must not bake one laptop's path install-push-deploy.sh writes the hook body through an UNQUOTED heredoc, so $HERE expanded at generation time and the absolute path of one machine was committed into every repo's .husky/pre-push. kivvi and botsmann both carried it; anyone cloning those repos got a hook pointing into a stranger's home directory, and re-running the installer would have put it straight back after those repos were cleaned. The hook now resolves ${DEV_ROOT:-$HOME/dev}/loki/... at RUN time, so the generator stops re-introducing what the cleanup just removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
145 lines
7.0 KiB
YAML
145 lines
7.0 KiB
YAML
# CI-gated production deploy (DevOps remediation #2).
|
|
#
|
|
# Today the Hetzner deploy fires from the LOCAL pre-push hook, so a red CI still
|
|
# ships and `--no-verify` skips every gate. This workflow makes CI the gate:
|
|
# it runs ONLY after the CI workflow finishes successfully on main, then builds
|
|
# and ships. A failing CI → no deploy.
|
|
#
|
|
# ┌─ BEFORE YOU ENABLE THIS (it is inert until on `main` + secrets exist) ─────┐
|
|
# │ 1. Add repo secret HETZNER_SSH_KEY = a private key whose public half is in │
|
|
# │ the box's root authorized_keys (a deploy-only key, ideally). │
|
|
# │ 2. org variable HETZNER_IP — the box address, set once for the org. │
|
|
# │ 3. DISABLE the local hook or you'll deploy twice: comment out the │
|
|
# │ `>>> loki push-deploy >>>` block in .husky/pre-push. │
|
|
# │ 4. Merge this file to main. First run: watch the "Build" step — it builds │
|
|
# │ against a schema-only Postgres (no seed); if a page pre-renders off real │
|
|
# │ data and fails, add a minimal seed step here. │
|
|
# └────────────────────────────────────────────────────────────────────────────┘
|
|
name: Deploy
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: ["CI"] # the job in ci.yml
|
|
types: [completed]
|
|
branches:
|
|
[main] # a PR's CI is not a ship signal — filter it out
|
|
# here rather than creating a run that only skips
|
|
# Ships whatever is on main right now. Required, not a convenience: a CI run
|
|
# that GITHUB_TOKEN started (the auto-merge re-arm) emits NO workflow_run
|
|
# event, so the chain above never fires for an auto-merged PR — observed
|
|
# 2026-08-05 with three merges live on main and none of them deployed. The
|
|
# sweep dispatches this directly instead — it compares main's tip against the
|
|
# last successful run here and closes the gap. The sweep now lives in
|
|
# bitbaum/dotfiles (scripts/ci/auto-merge-sweep.sh); this repo enables the
|
|
# reconciler by passing `deploy_workflow: deploy.yml` in auto-merge.yml.
|
|
# Removing that input makes merges land and never ship.
|
|
workflow_dispatch: {}
|
|
|
|
# One deploy at a time; never cancel a ship mid-flight.
|
|
concurrency:
|
|
group: deploy-prod
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
deploy:
|
|
# Chained: only a GREEN CI run that was on main. Dispatched: the caller is
|
|
# responsible for the gate (the sweep checks main's CI before dispatching).
|
|
# Kill switch: dormant until you set repo variable DEPLOY_VIA_CI=true. This
|
|
# lets the workflow live on main (green PR, reviewed) WITHOUT deploying until
|
|
# you've added HETZNER_SSH_KEY and disabled the local push-deploy hook. Unset
|
|
# variable → '' → never runs.
|
|
if: >
|
|
vars.DEPLOY_VIA_CI == 'true' &&
|
|
(github.event_name == 'workflow_dispatch' ||
|
|
(github.event.workflow_run.conclusion == 'success' &&
|
|
github.event.workflow_run.head_branch == 'main'))
|
|
runs-on: ubuntu-latest
|
|
|
|
# Build does DB queries during static pre-render, so give it a schema-only
|
|
# Postgres (drizzle-kit push below). No real data — see the seed caveat above.
|
|
services:
|
|
postgres:
|
|
image: postgres:17
|
|
env:
|
|
POSTGRES_PASSWORD: ci
|
|
POSTGRES_DB: loki
|
|
ports: ["5432:5432"]
|
|
options: >-
|
|
--health-cmd pg_isready --health-interval 5s
|
|
--health-timeout 5s --health-retries 10
|
|
|
|
env:
|
|
DATABASE_URL: postgres://postgres:ci@localhost:5432/loki
|
|
HETZNER_IP: ${{ vars.HETZNER_IP }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
# Chained: the exact CI-green commit. Dispatched: the tip of the ref
|
|
# it was dispatched on. Never an empty string — that silently checks
|
|
# out the default branch and would ship something nobody verified.
|
|
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
|
|
|
|
- uses: pnpm/action-setup@v6
|
|
|
|
# setup-pnpm's default store nests inside its own bin dir, which breaks
|
|
# any prepare-building dep (portable-type TS2742) — pin it outside.
|
|
- run: pnpm config set store-dir ~/.pnpm-store --global
|
|
|
|
- uses: actions/setup-node@v7
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
|
|
# Root deps AND the bridge subpackage — bridge/ is its own npm package with
|
|
# its own lockfile (pg, @types/pg). The build step below runs `tsc` in it,
|
|
# so without this the bridge build fails with "Cannot find module 'pg'".
|
|
# One workspace install covers root AND bridge/ (both in
|
|
# pnpm-workspace.yaml) — the separate `npm --prefix bridge ci` is gone.
|
|
- run: pnpm install --frozen-lockfile
|
|
|
|
- name: Push schema to CI Postgres (build needs it)
|
|
run: pnpm exec drizzle-kit push
|
|
|
|
# Next's incremental compiler cache. Every deploy compiled the whole app
|
|
# from cold because the runner is ephemeral — the one part of the pipeline
|
|
# that is genuinely WORK rather than waiting, so it is worth making
|
|
# smaller. Keyed on the lockfile plus the sources, with a lockfile-only
|
|
# fallback so a normal source change still starts from a warm cache.
|
|
# `.next/cache` is compiler state, not output: what ships is
|
|
# `.next/standalone`, rebuilt every run either way.
|
|
- name: Cache Next.js build cache
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: .next/cache
|
|
key: ${{ runner.os }}-next-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('src/**/*.ts', 'src/**/*.tsx') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-next-${{ hashFiles('pnpm-lock.yaml') }}-
|
|
${{ runner.os }}-next-
|
|
|
|
# A NEXT_PUBLIC_* value has two origins: the server reads it at runtime,
|
|
# the browser gets what was inlined HERE, at build time. Anything the box
|
|
# sets at runtime must therefore also be handed to this step, or the two
|
|
# disagree — which is what rendered a notifications bell on the server and
|
|
# nothing on the client, throwing away the tree on every authenticated
|
|
# page (React #418, #488). scripts/test/public-env-inlined.ts enforces it.
|
|
- name: Build (app + bridge)
|
|
env:
|
|
# Public by design — it is compiled into the client bundle and handed
|
|
# to every browser that subscribes. A repo variable, not a secret.
|
|
NEXT_PUBLIC_VAPID_PUBLIC_KEY: ${{ vars.NEXT_PUBLIC_VAPID_PUBLIC_KEY }}
|
|
run: |
|
|
pnpm run build
|
|
pnpm -C bridge run build
|
|
|
|
- name: SSH setup
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "${{ secrets.HETZNER_SSH_KEY }}" > ~/.ssh/id_deploy
|
|
chmod 600 ~/.ssh/id_deploy
|
|
ssh-keyscan -H "$HETZNER_IP" >> ~/.ssh/known_hosts 2>/dev/null
|
|
printf 'Host %s\n IdentityFile ~/.ssh/id_deploy\n IdentitiesOnly yes\n' "$HETZNER_IP" >> ~/.ssh/config
|
|
|
|
- name: Ship to box (reuses deploy-hetzner.sh — flock, rollback, verify)
|
|
run: bash scripts/deploy-hetzner.sh --no-build
|