Aller au contenu principal

Rules: deploy-safety

Every deployment must be validated before execution. Never deploy dev config to production.

Affected files

These rules apply to files matching the following patterns:

  • **/docker-compose*.yml
  • **/docker-compose*.yaml
  • **/Dockerfile*
  • **/deploy*
  • **/scripts/deploy*
  • **/.env*
  • **/nginx*
  • **/middleware.*
  • **/proxy.*
  • **/sw.js
  • **/service-worker*
  • **/layout.tsx
  • **/layout.jsx
  • **/+layout.svelte

Detailed rules

Deploy Safety

Principle

Every deployment must be validated before execution. Never deploy dev config to production.

CRITICAL: High-risk files

These files can break production silently (no error in dev):

FileRiskMandatory test
middleware.ts/proxy.tsCSP can block scripts → blank pagenpm run build && npm start, check CSP headers with curl
layout.tsxheaders() breaks SSG → 500 on static pagesnpm run build must pass without error
sw.jsHTML cache → broken hydration after deployTest in real browser with DevTools > Application > SW
docker-compose.production.ymlread_only breaks framework cachedocker compose up locally before deploy
DockerfileCorrupted imageBuild + run locally before transfer

IMPORTANT: Tests in dev mode (npm run dev, next dev, vite dev) do NOT detect production bugs (CSP, SSG, SW, Docker).

Absolute rule: REVERT FIRST

If prod is broken, REVERT to the last stable state BEFORE trying to understand. Never chain cascading hotfixes.

# Quick revert
git checkout <last-known-good-tag> -- <broken-file>
./scripts/deploy.sh deploy
# THEN investigate in a separate branch

NEVER chain more than 2 hotfixes in prod. On the 2nd failure → REVERT.

Mandatory pre-deployment checklist

CheckCommandBlocking
Prod build succeedsnpm run build / go build / docker build .Yes
Tests passnpm test / pytest / go testYes
Types OK (if applicable)npx tsc --noEmit / mypy .Yes
Lint OKnpm run lint / ruff check . / golangci-lint runYes
No hardcoded secretsgrep -rn "password|secret|api_key" docker-compose*.ymlYes
DB migrations up to dateprisma migrate status / equivalentYes
CSP headers verifiedcurl -sI localhost:3000 | grep cspIf middleware modified
SW does not cache HTMLCheck navigate handler in sw.jsIf SW modified
Docker worksdocker compose -f docker-compose.production.yml up locallyIf Docker modified
DB backup doneBackup scriptYes

Red Flags — STOP immediately

SignalReaction
headers() or cookies() in root layoutSTOP — breaks SSG, use middleware
read_only: true in Docker without complete tmpfsSTOP — frameworks need writable cache
strict-dynamic CSP without nonce on inline scriptsSTOP — blocks scripts, blank page
SW that caches request.mode === "navigate"STOP — breaks hydration after deploy
Deploying without local prod buildSTOP — dev bugs ≠ prod bugs
2nd cascading hotfix that failsSTOP — REVERT and investigate
Copying docker-compose.yml (dev) to the serverSTOP — use docker-compose.production.yml
Env variables with dev default valuesSTOP — check production values
DB migration with --force without backupSTOP — backup first

Environments

EnvCSPSWDockerDebugTest method
DevPermissiveNot activeNoYesnpm run dev
Local buildProdActive if registeredNoNonpm run build && npm start
StagingProdActiveYesNoVia deploy script
ProdStrictActiveYesNoVia deploy script

Rules

IMPORTANT: Always check that the docker-compose used is the PRODUCTION one before deploying.

IMPORTANT: NEVER deploy without having checked that all environment variables are configured for production.

NEVER copy a dev configuration file to production without explicit verification.

NEVER deploy with pending DB migrations without having run or checked them.

NEVER deploy a change to middleware, layout, sw.js, or Docker without testing in a local prod build.

Automatic application

These rules are automatically applied by Claude during:

  • Reading the matching files
  • Modifying code
  • Suggestions and fixes

See also