Deployment Guide
How to deploy changes to staging and production.
Deployment Pipeline
┌───────── ────┐ ┌─────────────┐ ┌─────────────┐
│ dev │────▶│ staging │────▶│ production │
│ branch │ │ preview │ │ (main) │
└─────────────┘ └─────────────┘ └─────────────┘
Branch Strategy
dev Branch
- Active development
- All commits go here first
- Auto-deploys to staging previews
main Branch
- Production-ready code
- Merged from
devafter testing - Auto-deploys to production
Important
Never push directly to main. All changes must go through dev first.
Frontend Deployments
Frontends are deployed via Cloudflare Pages with Git integration.
Automatic Deployment
Push to trigger automatic deployment:
# Deploy to staging
git checkout dev
git add .
git commit -m "feat: add new feature"
git push origin dev
# → Deploys to preview URL (*.pages.dev)
# Deploy to production (via merge)
git checkout main
git merge dev
git push origin main
# → Deploys to production (emuy.gg)
Preview URLs
Each push to dev creates a unique preview:
https://abc123.emuy-pages.pages.dev
Check the GitHub commit or Cloudflare dashboard for the exact URL.
Manual Deploy via Dashboard
- Go to DevOps Page
- Find the project in "Deploy" tab
- Click "Deploy to Production"
- Confirm the merge
Worker Deployments
Workers are deployed via Wrangler CLI.
Deploy to Production
cd auth-api
npx wrangler deploy
Deploy with Specific Environment
# Production
npx wrangler deploy --env production
# Staging (if configured)
npx wrangler deploy --env staging
Rollback
If something goes wrong:
# List recent deployments
npx wrangler deployments list
# Rollback to previous
npx wrangler rollback
Database Migrations
D1 Migrations
# Apply migration to production
npx wrangler d1 execute auth-db --file=migrations/001_add_column.sql
# Apply to local first for testing
npx wrangler d1 execute auth-db --local --file=migrations/001_add_column.sql
Migration Best Practices
- Always backup first
- Test locally before production
- Use transactions where possible
- Small, incremental changes are safer
Environment Configuration
Frontend (.env)
# .env.production
VITE_API_URL=https://api.emuy.gg
VITE_AUTH_URL=https://api.emuy.gg/auth
Workers (wrangler.jsonc)
{
"name": "auth-api",
"vars": {
"ENVIRONMENT": "production"
},
"d1_databases": [
{
"binding": "DB",
"database_name": "auth-db",
"database_id": "xxx-xxx-xxx"
}
]
}
Staging Environments
Accessing Staging
Staging sites require view_devops permission:
- Visit the
*.pages.devpreview URL - Login with Discord
- If authorized, you'll see the staging banner
Staging Auth Flow
Staging uses a modified auth flow:
- JWT passed via URL parameter (not cookie)
- Stored in localStorage
- Works across different domains
Deployment Checklist
Before deploying to production:
- All changes tested locally
- Tested on staging preview
- No console errors
- Database migrations applied (if any)
- Environment variables configured
- Documentation updated (if needed)
Monitoring
Cloudflare Dashboard
- Workers: Analytics, errors, invocations
- Pages: Build logs, deployment history
- D1: Query analytics, storage usage
Health Checks
# Check all services
curl https://api.emuy.gg/health
# Check specific service
curl https://api.emuy.gg/auth/health
Logs
# Tail worker logs
npx wrangler tail auth-api
# Filter errors only
npx wrangler tail auth-api --status error
Rollback Procedures
Frontend Rollback
- Go to Cloudflare Pages dashboard
- Find the project
- Go to Deployments
- Click "Rollback" on a previous deployment
Or via Git:
git revert HEAD
git push origin main
Worker Rollback
npx wrangler rollback
Database Rollback
For D1, you'll need to run a reverse migration:
-- migrations/001_add_column_rollback.sql
ALTER TABLE users DROP COLUMN new_column;
Emergency Procedures
Site Down
- Check Cloudflare status
- Check worker logs:
npx wrangler tail - Check D1 connectivity
- Rollback if recent deployment
Database Issues
- Check D1 dashboard for errors
- Verify bindings in wrangler.jsonc
- Test with simple query
- Contact Cloudflare support if persistent