3.4 KiB
3.4 KiB
Cloudflare Worker Native Deployment Setup
This guide explains how to set up Cloudflare's native Git integration for automatic worker deployments.
Quick Setup Steps
1. Enable Git Integration in Cloudflare Dashboard
- Go to Cloudflare Dashboard
- Navigate to Workers & Pages → jeffemmett-canvas
- Go to Settings → Builds & Deployments
- Click "Connect to Git" or "Set up Git integration"
- Authorize Cloudflare to access your GitHub repository
- Select your repository:
Jeff-Emmett/canvas-website - Configure:
- Production branch:
main - Build command: Leave empty (wrangler automatically detects and builds from
wrangler.toml) - Root directory:
/(or leave empty)
- Production branch:
2. Configure Build Settings
Cloudflare will automatically:
- Detect
wrangler.tomlin the root directory - Build and deploy the worker on every push to
main - Show build status in GitHub (commit statuses, PR comments)
3. Environment Variables
Set environment variables in Cloudflare Dashboard:
- Go to Workers & Pages → jeffemmett-canvas → Settings → Variables
- Add any required environment variables
- These are separate from
wrangler.toml(which should only have non-sensitive config)
4. Verify Deployment
After setup:
- Push a commit to
mainbranch - Check Cloudflare Dashboard → Workers & Pages → jeffemmett-canvas → Deployments
- You should see a new deployment triggered by the Git push
- Check GitHub commit status - you should see Cloudflare build status
How It Works
- On push to
main: Automatically deploys to production usingwrangler.toml - On pull request: Can optionally deploy to preview environment
- Build status: Appears in GitHub as commit status and PR comments
- Deployments: All visible in Cloudflare Dashboard
Environment Configuration
Production (main branch)
- Uses
wrangler.tomlfrom root directory - Worker name:
jeffemmett-canvas - R2 buckets:
jeffemmett-canvas,board-backups
Development/Preview
- For dev environment, you can:
- Use a separate worker with
wrangler.dev.toml(requires manual deployment) - Or configure preview deployments in Cloudflare dashboard
- Or use the deprecated GitHub Action (see
.github/workflows/deploy-worker.yml.disabled)
- Use a separate worker with
Manual Deployment (if needed)
If you need to deploy manually:
# Production
npm run deploy:worker
# or
wrangler deploy
# Development
npm run deploy:worker:dev
# or
wrangler deploy --config wrangler.dev.toml
Troubleshooting
Build fails
- Check Cloudflare Dashboard → Deployments → View logs
- Ensure
wrangler.tomlis in root directory - Verify all required environment variables are set in Cloudflare dashboard
Not deploying automatically
- Verify Git integration is connected in Cloudflare dashboard
- Check that "Automatically deploy from Git" is enabled
- Ensure you're pushing to the configured branch (
main)
Need to revert to GitHub Actions
- Rename
.github/workflows/deploy-worker.yml.disabledback todeploy-worker.yml - Disable Git integration in Cloudflare dashboard
Benefits of Native Deployment
✅ Simpler: No workflow files to maintain
✅ Integrated: Build status in GitHub
✅ Automatic: Resource provisioning (KV, R2, Durable Objects)
✅ Free: No GitHub Actions minutes usage
✅ Visible: All deployments in Cloudflare dashboard