Add a staging environment
Run a staging copy of an instance that redeploys on every push to develop, next to production on main. About 45 minutes; it creates a second Supabase project and fills the -staging Render services.
| Environment | Branch | Web (Vercel) | api and jobs (Render) | Database (Supabase) |
|---|---|---|---|---|
| Local | any | pnpm dev | pnpm dev | local supabase start |
| Staging | develop | Preview deployment | monark-api-staging, monark-cron-*-staging | its own project |
| Production | main | Production deployment | monark-api, monark-cron-* | its own project |
Staging and production never share a database or a secret. Each api migrates its own database in its pre-deploy step, so a migration that fails on staging never reaches production.
Before you start
- Production deployed with the deploy checklist
- Four freshly generated staging secrets (Prepare accounts and secrets, step 1)
Steps
- Create a second Supabase project for staging and collect its URL, keys and both database URLs, as in Prepare accounts and secrets.
- In Render, fill
monark-cron-shared-stagingwith the stagingCRON_SECRETand a placeholderAPI_URL, then fillmonark-api-stagingfrom the staging project, as in Deploy the api to Render. AddEMAIL_ACTION_SECRETunder Environment. The staging api has noBRANDING_*keys in the blueprint; add any you want under Environment. - Once
monark-api-stagingis live, set its URL asAPI_URLinmonark-cron-shared-staging. - In Vercel, open Settings → Git and set Production Branch to
main. Every other branch,developincluded, becomes a Preview deployment. - Give
developa stable host: under Settings → Domains, add a domain such asstaging.<yourdomain>and assign it to thedevelopbranch. Without one, use Vercel's branch alias<project>-git-develop-<team>.vercel.app. - Under Settings → Environment Variables, give each web variable a separate Preview value pointing at staging:
NEXT_PUBLIC_API_URL,NEXT_PUBLIC_APP_URL,NEXT_PUBLIC_SUPABASE_URL,NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY,SUPABASE_URL,SUPABASE_SECRET_KEY, and anyNEXT_PUBLIC_SENTRY_*orNEXT_PUBLIC_BRANDING_*. - Set
WEB_ORIGINandAPP_URLonmonark-api-stagingto the staging web host. - In the staging Supabase project, under Authentication → URL Configuration, set Site URL to the staging web host and add its
/auth/confirmand/auth/callbackURLs. - Push a commit to
developand watch both Render and Vercel deploy it.
Verify
Run the smoke test against the staging host, with the staging DIRECT_URL.
Good to know: every pull request also gets a Vercel preview, and previews share the Preview variables, so they talk to the staging api and database. Treat them as staging clients, not sandboxes.
If something goes wrong
| Symptom | Cause | Fix |
|---|---|---|
| Staging web calls the production api | Preview variables not set, so Vercel used the Production values | Add Preview values for every variable in step 6, then redeploy. |
| Staging confirmation links open production | staging Supabase Site URL still production's | Fix step 8. |
Pushing to develop doesn't redeploy the api | see Deploy the api only after CI passes | Follow its troubleshooting table. |