Skip to content

First Deployment

Deploy your first FireBreak instance to Cloudflare staging environment.

Prerequisites

Before deploying, ensure you have:

  • Completed Installation
  • Cloudflare account (free tier works)
  • Wrangler authenticated (wrangler login)
  • All tests passing locally

Step 1: Authenticate with Cloudflare

# Login to Cloudflare
wrangler login

# Verify authentication
wrangler whoami

This will open your browser to authenticate with Cloudflare.

Step 2: Create Cloudflare Resources

Create D1 Database

cd backend

# Create staging database
wrangler d1 create firestorm-staging

# Note the database ID from output
# Add it to wrangler.jsonc under env.staging.d1_databases

Create KV Namespace

# Create KV namespace for caching
wrangler kv:namespace create CACHE --env staging

# Note the namespace ID
# Add it to wrangler.jsonc under env.staging.kv_namespaces

Create R2 Bucket

# Create R2 bucket for photos
wrangler r2 bucket create firestorm-photos-staging

# Verify
wrangler r2 bucket list

Step 3: Configure Staging Environment

Edit backend/wrangler.jsonc:

{
  "env": {
    "staging": {
      "name": "firestorm-backend-staging",
      "vars": {
        "ENVIRONMENT": "staging",
        "API_VERSION": "v1",
        "DEBUG": "false"
      },
      "d1_databases": [
        {
          "binding": "DB",
          "database_name": "firestorm-staging",
          "database_id": "<YOUR_D1_DATABASE_ID>"
        }
      ],
      "kv_namespaces": [
        {
          "binding": "CACHE",
          "id": "<YOUR_KV_NAMESPACE_ID>"
        }
      ],
      "r2_buckets": [
        {
          "binding": "PHOTOS",
          "bucket_name": "firestorm-photos-staging"
        }
      ]
    }
  }
}

Step 4: Set Secrets

Set API keys and secrets for staging:

cd backend

# Set OpenAI API key (optional for testing)
wrangler secret put OPENAI_API_KEY --env staging

# Set Anthropic API key
wrangler secret put ANTHROPIC_API_KEY --env staging

# Set Google API key
wrangler secret put GOOGLE_API_KEY --env staging

# Set Cloudflare credentials
wrangler secret put CLOUDFLARE_ACCOUNT_ID --env staging
wrangler secret put CLOUDFLARE_API_TOKEN --env staging

# Verify secrets
wrangler secret list --env staging

Using Test API Keys

For staging, you can use test/development API keys. Save production keys for the production environment.

Step 5: Deploy Backend

cd backend

# Deploy to staging
wrangler deploy --env staging

# Watch for deployment output
# You should see: "Published firestorm-backend-staging"

Expected output:

Total Upload: 512 KiB / gzip: 128 KiB
Uploaded firestorm-backend-staging (2.3 sec)
Published firestorm-backend-staging (0.8 sec)
  https://firestorm-backend-staging.<YOUR_SUBDOMAIN>.workers.dev

Step 6: Verify Backend Deployment

Test the deployed backend:

# Test health endpoint
curl https://firestorm-backend-staging.<YOUR_SUBDOMAIN>.workers.dev/api/v1/health

# Expected response:
# {
#   "status": "healthy",
#   "version": "v1",
#   "environment": "staging",
#   "service": "firestorm-backend"
# }

Step 7: Configure Custom Domain (Optional)

Add Custom Route

  1. Go to Cloudflare Dashboard → Workers & Pages
  2. Select your worker: firestorm-backend-staging
  3. Go to Settings → Triggers
  4. Add custom route: api-staging.firebreakrisk.com/*

Or via wrangler.jsonc:

{
  "env": {
    "staging": {
      "routes": [
        {
          "pattern": "api-staging.firebreakrisk.com/*",
          "zone_name": "firebreakrisk.com"
        }
      ]
    }
  }
}

Then redeploy:

wrangler deploy --env staging

Verify Custom Domain

curl https://api-staging.firebreakrisk.com/api/v1/health

Step 8: Deploy Frontend

cd frontend/core

# Build for staging
npm run build

# Deploy to Cloudflare Pages
npx wrangler pages deploy dist --project-name=firestorm-frontend-staging

# Or set up automatic deployment:
# Connect your GitHub repo to Cloudflare Pages
# Configure build settings:
# - Build command: npm run build
# - Build output directory: dist
# - Branch: develop → staging environment

Step 9: Run Post-Deployment Tests

cd qa

# Run smoke tests against staging
STAGING_URL=https://api-staging.firebreakrisk.com npx playwright test --grep smoke

# Run API tests
pytest tests/integration/ --env=staging -v

Step 10: Monitor Deployment

View Logs

cd backend

# Tail logs in real-time
wrangler tail --env staging

# Filter for errors
wrangler tail --env staging --status error

Check Analytics

  1. Go to Cloudflare Dashboard → Workers & Pages
  2. Select firestorm-backend-staging
  3. View Metrics tab for:
  4. Request rate
  5. Error rate
  6. CPU time
  7. Duration

Deployment Checklist

After deployment, verify:

  • Health endpoint returns 200 OK
  • API endpoints respond correctly
  • Frontend loads and can connect to backend
  • No errors in logs (check wrangler tail)
  • Database connections work
  • R2 storage accessible
  • KV cache operational
  • Secrets loaded correctly

Rollback

If you need to rollback:

cd backend

# View deployment history
wrangler deployments list --env staging

# Rollback to previous version
wrangler rollback --env staging

# Select the version to rollback to from the interactive prompt

Next Steps

Now that your first deployment is complete:

  1. Local Development Setup - Set up your development workflow
  2. Deployment Guide - Learn advanced deployment patterns
  3. Monitoring - Set up monitoring and alerts
  4. Troubleshooting - Common deployment issues

Common Issues

Issue: "Unauthorized" Error

Make sure you're logged in:

wrangler login
wrangler whoami

Issue: Database Not Found

Verify D1 database exists and ID is correct:

wrangler d1 list
# Update wrangler.jsonc with correct database_id

Issue: Secrets Not Working

Check secrets are set:

wrangler secret list --env staging

Re-set if needed:

wrangler secret put OPENAI_API_KEY --env staging

Issue: CORS Errors

Verify CORS headers in backend response. Check browser console for specific errors.

Security Notes

  • Use different API keys for staging vs production
  • Enable debug mode only in staging
  • Regularly rotate secrets (every 90 days)
  • Monitor logs for suspicious activity
  • Set up rate limiting for API endpoints

Additional Resources