From a0ba4a449983d6f896491a759ea5f16bbc5933d5 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Fri, 16 Oct 2026 12:28:12 +0530 Subject: [PATCH 1/3] ci: build and boot the live deploy image CI never built deploy/Dockerfile, the image the live site runs. A new job runs scripts/deploy-image-smoke.sh whenever an app, deploy/ or render.yaml changes: build the image, boot it under 512 MB with the demo reset against a throwaway database, check login, the API and the security headers, then restart it and check the reset. A deliberately broken boot fails it. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/changes.yml | 20 ++++++++ scripts/deploy-image-smoke.sh | 92 +++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100755 scripts/deploy-image-smoke.sh diff --git a/.github/workflows/changes.yml b/.github/workflows/changes.yml index d5511b9..ef4cb55 100644 --- a/.github/workflows/changes.yml +++ b/.github/workflows/changes.yml @@ -29,6 +29,7 @@ jobs: web: ${{ steps.filter.outputs.web }} api: ${{ steps.filter.outputs.api }} tooling: ${{ steps.filter.outputs.tooling }} + deploy: ${{ steps.filter.outputs.deploy }} steps: - name: Check out uses: actions/checkout@v4 @@ -54,6 +55,9 @@ jobs: - 'docker-compose.yml' - 'db/**' - 'prisma/**' + deploy: + - 'deploy/**' + - 'render.yaml' tooling: - '.github/workflows/**' - 'CLAUDE.md' @@ -69,6 +73,7 @@ jobs: echo "| ------- | ----- |" echo "| web (apps/web) | ${{ steps.filter.outputs.web }} |" echo "| api (apps/api) | ${{ steps.filter.outputs.api }} |" + echo "| deploy image | ${{ steps.filter.outputs.deploy }} |" echo "" echo "Shared tooling changed: ${{ steps.filter.outputs.tooling }}" } >> "$GITHUB_STEP_SUMMARY" @@ -85,6 +90,21 @@ jobs: if: needs.detect.outputs.api == 'true' uses: ./.github/workflows/api.yml + # The image the live site runs holds both apps, so any change to either, or to + # the deploy files, must still build and boot it. Render waits for this check + # (autoDeployTrigger: checksPass in render.yaml). + deploy-image: + name: deploy image smoke + needs: detect + if: needs.detect.outputs.api == 'true' || needs.detect.outputs.web == 'true' || needs.detect.outputs.deploy == 'true' + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + + - name: Build and boot deploy/Dockerfile under the host's limits + run: scripts/deploy-image-smoke.sh + # Builds both images and boots the real stack, so a Dockerfile or startup # bug fails here instead of on the first `docker compose up`. compose-smoke: diff --git a/scripts/deploy-image-smoke.sh b/scripts/deploy-image-smoke.sh new file mode 100755 index 0000000..acbf13d --- /dev/null +++ b/scripts/deploy-image-smoke.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +# Builds the live deploy's image (deploy/Dockerfile) and boots it the way the +# host does: 512 MB, the demo reset on, against a throwaway PostgreSQL and +# Redis. Then restarts it, so the reset of a seeded database is exercised too. +# CI runs this before Render may deploy; it runs the same on a laptop. +set -euo pipefail + +cd "$(dirname "$0")/.." + +NAME="labops-deploy-smoke-$$" +IMAGE="${NAME}:test" +PORT="${SMOKE_PORT:-10001}" +# Throwaway credentials for containers that live only for this run. +OPERATOR_PASSWORD="$(openssl rand -hex 16)" + +cleanup() { + docker rm -f "${NAME}-app" "${NAME}-pg" "${NAME}-redis" >/dev/null 2>&1 || true + docker network rm "$NAME" >/dev/null 2>&1 || true + docker image rm "$IMAGE" >/dev/null 2>&1 || true +} +trap cleanup EXIT + +# Captured, then searched: with pipefail, `docker logs | grep -q` fails when +# grep exits at its first match and the writer is cut off. +app_logs() { docker logs "${NAME}-app" 2>&1; } + +fail() { + echo "FAILED: $1" >&2 + docker logs --tail 60 "${NAME}-app" >&2 2>/dev/null || true + exit 1 +} + +echo "==> building deploy/Dockerfile" +docker build -q -f deploy/Dockerfile -t "$IMAGE" . >/dev/null + +docker network create "$NAME" >/dev/null +docker run -d --name "${NAME}-pg" --network "$NAME" \ + -e POSTGRES_USER=labops -e POSTGRES_PASSWORD=labops -e POSTGRES_DB=labops \ + postgres:16-alpine >/dev/null +docker run -d --name "${NAME}-redis" --network "$NAME" \ + redis:7-alpine redis-server --maxmemory-policy noeviction >/dev/null +until docker exec "${NAME}-pg" pg_isready -U labops >/dev/null 2>&1; do sleep 1; done + +echo "==> booting it as the host does (512 MB, demo reset on)" +docker run -d --name "${NAME}-app" --network "$NAME" \ + --memory=512m --memory-swap=512m -p "${PORT}:10000" \ + -e DATABASE_URL="postgresql://labops:labops@${NAME}-pg:5432/labops" \ + -e REDIS_URL="redis://${NAME}-redis:6379" \ + -e RENDER_EXTERNAL_URL="http://localhost:${PORT}" \ + -e SEED_OPERATOR_USERNAME=demo -e SEED_OPERATOR_PASSWORD="$OPERATOR_PASSWORD" \ + -e CREDENTIALS_KEY="$(openssl rand -base64 32)" \ + -e LLM_PROVIDER=fixture -e DEMO_RESET_ON_BOOT=true \ + "$IMAGE" >/dev/null + +# Waits until the boot has seeded the demo `count` times in total. +wait_for_seed() { + local count="$1" + for _ in $(seq 1 120); do + [ "$(docker inspect -f '{{.State.Running}}' "${NAME}-app")" = true ] || fail "the container exited" + logs="$(app_logs)" + if [ "$(grep -c 'demo scenario seeded' <<<"$logs")" -ge "$count" ]; then + return 0 + fi + sleep 2 + done + fail "the demo was not seeded within four minutes" +} + +check_site() { + local status + status="$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:${PORT}/login")" + [ "$status" = 200 ] || fail "the login page answered ${status}" + local page + page="$(curl -s "http://localhost:${PORT}/login")" + grep -Eq 'API: ()?ok' <<<"$page" || fail "the web app cannot reach the API" +} + +wait_for_seed 1 +grep -q '"outcome":"empty"' <<<"$(app_logs)" || fail "the first boot did not see an empty database" +check_site +head="$(curl -sI "http://localhost:${PORT}/login")" +headers="$(grep -ciE '^(x-frame-options|content-security-policy|x-content-type-options|referrer-policy|strict-transport-security):' <<<"$head")" +[ "$headers" = 5 ] || fail "expected 5 security headers, got ${headers}" +echo "ok: first boot seeded, login 200, API ok, 5 security headers" + +echo "==> restarting: the boot must reset the seeded database and come back" +docker restart "${NAME}-app" >/dev/null +wait_for_seed 2 +grep -q '"outcome":"reset"' <<<"$(app_logs)" || fail "the restart did not reset the demo" +check_site +echo "ok: restart reset the demo and the site came back" +echo "ok: $(docker stats --no-stream --format '{{.MemUsage}}' "${NAME}-app") in use" From 8d22e9c4b385f0e64a36822d1c2956e684c7f704 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Fri, 16 Oct 2026 12:28:12 +0530 Subject: [PATCH 2/3] feat(deploy): deploy only after every ci check passes Render deployed on every push to main without looking at CI. With autoDeployTrigger: checksPass a commit goes live only once all its checks, the deploy image smoke included, have passed. Co-Authored-By: Claude Opus 5.5 --- render.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/render.yaml b/render.yaml index 8865f42..24d09c8 100644 --- a/render.yaml +++ b/render.yaml @@ -10,6 +10,9 @@ services: # Keep this and the Key Value region the same as the Neon project's. region: singapore dockerfilePath: ./deploy/Dockerfile + # Deploy only after every CI check on the commit passes, so code that fails + # lint, tests or the deploy image smoke never goes live. + autoDeployTrigger: checksPass dockerContext: . healthCheckPath: /login envVars: From 2868523117caa5c523fe2b103a3238315c2668a1 Mon Sep 17 00:00:00 2001 From: Vishwas Tiwari Date: Fri, 16 Oct 2026 12:28:12 +0530 Subject: [PATCH 3/3] docs: record that deploys wait for ci Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 +++++ ARCHITECTURE.md | 8 +++++--- docs/GAPS.md | 6 ++++-- docs/dev/QUALITY.md | 8 ++++---- docs/dev/SETUP.md | 5 +++-- docs/infra/DEPLOYMENT.md | 9 ++++++--- docs/infra/INFRA.md | 7 ++++--- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f477962..7718e18 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -273,6 +273,11 @@ projects. That rule was broken once, and it is not optional. project otherwise runs stale images (this once produced a false "verified"). Check image build times if in doubt. +7b. **The live image**, whenever an app, `deploy/` or `render.yaml` changed: + `scripts/deploy-image-smoke.sh` builds `deploy/Dockerfile` and boots it + twice under 512 MB against a throwaway database. CI runs the same, and + Render deploys only once every check passes (`checksPass`). + 8. **The browser journey** on a fresh stack (the smoke run used the demo, so reset first): ``` diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 3289394..a2ead11 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -1064,8 +1064,10 @@ whether a commit touched `apps/web`, `apps/api`, or shared root tooling, then dispatches only the matching pipeline via `workflow_call`. A frontend-only change never starts the backend pipeline. Root manifests and the ESLint config map to **both** services, because a shared-tooling change can break either. -Deploy files (`deploy/`, `render.yaml`, `scripts/`) match no filter, so they -start no pipeline, and CI never builds `deploy/Dockerfile`. +A change to `deploy/` or `render.yaml`, or to either app, runs the deploy +image smoke: it builds `deploy/Dockerfile` and boots it under 512 MB against a +throwaway database. Render deploys only once every check passes +(`autoDeployTrigger: checksPass`). `api.yml` — build (`tsc` plus `prisma validate`), lint, unit tests, integration tests against real PostgreSQL and Redis service containers, coverage with @@ -1130,7 +1132,7 @@ Phases refer to `docs/specs/labops-copilot/PLAN.md`. | Compose: postgres, redis, migrate, api, worker, web; opt-in Jaeger override | Done, verified end to end | — | | Pino with shared Fastify instance and key-name redaction | Done | Trace id on API request logs (needs HTTP spans) | | Vitest unit + integration suites, Playwright journey, CI gates | Done (Phase 14) | — | -| CI: change detection, build, lint, tests, coverage, quality gate, compose smoke + e2e | Done | No deploy step: Render redeploys from `main` on its own, and CI never builds the Render image | +| CI: change detection, build, lint, tests, coverage, quality gate, compose smoke + e2e | Done | Render deploys from `main` only after every check passes, including the deploy image smoke | | Deterministic simulator (`modules/labs/simulator.ts`), `training-event` scenario | Done (Phase 2) | — | | Demo scenario endpoint, flag-gated and idempotent | Done (Phase 2) | — | | Event ingestion: validation, redaction at entry, DB dedup, lab transitions | Done (Phase 3) | — | diff --git a/docs/GAPS.md b/docs/GAPS.md index d5eb6bc..2097965 100644 --- a/docs/GAPS.md +++ b/docs/GAPS.md @@ -180,8 +180,10 @@ platform. The *action* would not. `demo` login. - **The demo's AI is the fixture**, not a model (`LLM_PROVIDER=fixture`), so every investigation on the live site is identical by design. -- **Render redeploys on every push to `main`**, gated only by what CI checks, - and CI never builds `deploy/Dockerfile`. +- **Render deploys from `main` only after every CI check passes**, including a + build and boot of `deploy/Dockerfile`. Merging is not gated: `main` has no + branch protection, so a failing PR can still be merged; it just never goes + live. - **A production boot refuses unsafe configuration.** `APP_ENV=production` makes the API fail at startup if the session cookie is not Secure, if no proxy hop count is given, or if demo routes are enabled. A Secure cookie over plain diff --git a/docs/dev/QUALITY.md b/docs/dev/QUALITY.md index a613f18..c0f8074 100644 --- a/docs/dev/QUALITY.md +++ b/docs/dev/QUALITY.md @@ -56,7 +56,7 @@ Workflows under `.github/workflows/`: | Workflow | Role | |---|---| -| `changes.yml` | Runs on pushes and pull requests to `main`. Detects whether a change touched `apps/web` or `apps/api` (the root `package.json`, lockfile and ESLint config count for both; `docker-compose.yml` for the api), dispatches only the matching pipeline, and runs the **compose smoke and e2e** job: build both images, boot the stack, run the smoke script, then reset the stack and run the Playwright journey | +| `changes.yml` | Runs on pushes and pull requests to `main`. Detects whether a change touched `apps/web` or `apps/api` (the root `package.json`, lockfile and ESLint config count for both; `docker-compose.yml` for the api), dispatches only the matching pipeline, runs the **deploy image smoke** job (`scripts/deploy-image-smoke.sh`) builds `deploy/Dockerfile` and boots it under 512 MB, twice, against a throwaway database when an app or `deploy/`/`render.yaml` changed, and runs the **compose smoke and e2e** job: build both images, boot the stack, run the smoke script, then reset the stack and run the Playwright journey | | `api.yml` | Build, lint, unit tests, integration tests (real Postgres + Redis), coverage, schema drift, quality gate | | `web.yml` | Build, lint, unit tests, coverage, quality gate | | `llm-live.yml` | Opt-in, manual only: the one job that calls a real model | @@ -65,9 +65,9 @@ The api and web pipelines each end in a quality gate that runs even when an upst failed (`if: always()`): a secret scan, a dependency audit, and a check that the scripts the pipeline depends on still exist. -A change only to `deploy/`, `render.yaml` or `scripts/` triggers no pipeline, -and CI never builds `deploy/Dockerfile`: -the live deploy's image is built by Render on merge, not in CI. +Render deploys only after every check on the commit passes +(`autoDeployTrigger: checksPass` in `render.yaml`), so nothing that fails CI +goes live. ### Dependency audit diff --git a/docs/dev/SETUP.md b/docs/dev/SETUP.md index cd565f3..da4bcdb 100644 --- a/docs/dev/SETUP.md +++ b/docs/dev/SETUP.md @@ -210,8 +210,8 @@ labops-copilot/ ├── deploy/ Dockerfile and start.sh for the live │ single-container deploy ├── docs/ Overview docs, dev/, infra/, specs/, images -├── scripts/ compose-smoke, clean-db-check, audit-gate, -│ check-required-scripts +├── scripts/ compose-smoke, deploy-image-smoke, clean-db-check, +│ audit-gate, check-required-scripts ├── .github/workflows/ CI pipelines ├── ARCHITECTURE.md System architecture and trade-offs ├── CLAUDE.md, AGENTS.md Rules and context for changing the code @@ -243,6 +243,7 @@ labops-copilot/ | `npm run seed:operator -w @labops/api` | Create or reset the operator from `SEED_OPERATOR_*` | | `npm run seed:demo -w @labops/api` | Ingest the demo scenario where demo routes are off; safe to re-run | | `scripts/clean-db-check.sh` | Integration tests twice on a throwaway database, then drop it | +| `scripts/deploy-image-smoke.sh` | Build the live deploy's image and boot it twice under 512 MB, as CI does before Render may deploy | ### Checks before you commit diff --git a/docs/infra/DEPLOYMENT.md b/docs/infra/DEPLOYMENT.md index 07250a1..7a3eb94 100644 --- a/docs/infra/DEPLOYMENT.md +++ b/docs/infra/DEPLOYMENT.md @@ -26,8 +26,11 @@ can trigger a scenario. The script fixes `APP_ENV`, `SESSION_COOKIE_SECURE`, unreachable from outside), `API_PORT` and `API_INTERNAL_URL` after the platform's environment, so the dashboard cannot contradict the production checks; `CORS_ORIGIN` falls back to Render's `RENDER_EXTERNAL_URL`, and Next.js -listens on Render's `PORT`. Render's health check is `GET /login`. CI never -builds `deploy/Dockerfile`; Render builds it on every push to `main`. +listens on Render's `PORT`. Render's health check is `GET /login`. Render deploys +a commit on `main` only after every CI check on it passes +(`autoDeployTrigger: checksPass`); one of those checks builds `deploy/Dockerfile` +and boots it under 512 MB (`scripts/deploy-image-smoke.sh`). A failed build on +Render also leaves the previous version serving. **Verified live** (2026-10-16): the login page answers 200 over HTTPS and reports `API: ok · PostgreSQL: up`, the five security headers are present, and @@ -146,6 +149,6 @@ The rest is in `docs/GAPS.md`. 1. Read `AGENTS.md` and `CLAUDE.md`. `AGENTS.md` §13 is the current task list. 2. Read `docs/GAPS.md` before describing this project's capabilities to anyone. -3. The deploy redeploys on every push to `main`, and every boot resets the demo. +3. A push to `main` goes live once its CI passes, and every boot resets the demo. 4. The open item is Google sign-in against a real OAuth client (`AGENTS.md` §13a): every test so far stubs Google. diff --git a/docs/infra/INFRA.md b/docs/infra/INFRA.md index 3087dbb..ff217f8 100644 --- a/docs/infra/INFRA.md +++ b/docs/infra/INFRA.md @@ -234,7 +234,7 @@ excludes server components, which only E2E can reach. |---|---|---| | A transaction left open on the database holds back every live update until it finishes (the stream reads below the oldest running transaction) | Keep transactions short (they are). `oldestOpenTransactionMs` in `/api/metrics` now shows it; nothing alerts on it yet | Before production | | Sign-in (5/min) and investigation (10/min) limits are global: every call reaches the API from the web server, which forwards no client address, so `TRUST_PROXY_HOPS` has nothing to act on | Forward `X-Forwarded-For` from the web server and count it as the trusted hop (a blanket trust lets clients spoof it). The API is already unreachable from outside on Render | Before production | -| CI never builds `deploy/Dockerfile`, and a change only to `deploy/`, `render.yaml` or `scripts/` runs no pipeline; Render redeploys every push to `main` | Add those paths to the filters and build the Render image in CI | Before production | +| `main` has no branch protection, so a PR can be merged before or despite failing checks | Require the CI checks in GitHub's branch rules; Render already refuses to deploy a failing commit (`checksPass`) | Owner | | `main` has no branch protection | Require the quality gates before merge | Owner's settings change | | Docs-only changes trigger no pipeline | Intended: `docs/**` is not in any filter | — | @@ -259,8 +259,9 @@ so nobody could sign in), if `TRUST_PROXY_HOPS` is unset, or if `DEMO_ENABLED` is true. `deploy/start.sh` sets all four after the platform's environment, so a dashboard setting cannot contradict the production checks. -**Deploying.** Render redeploys on every push to `main`; there is no manual -step and no image registry. Migrations run at boot, before the processes start, +**Deploying.** Render deploys a push to `main` once every CI check on it +passes, the deploy image smoke included; there is no manual step and no image +registry. Migrations run at boot, before the processes start, which is safe because every boot also starts from an empty demo database. **Backups and secrets.** There are no backups: every boot wipes and reseeds the