Perform comprehensive pre-flight checks and deploy Cloudflare Workers safely using wrangler
Performs comprehensive pre-deployment checks and safely deploys Cloudflare Workers using wrangler. Use this before any production deployment to validate configuration, code quality, security, and build integrity.
/plugin marketplace add hirefrank/hirefrank-marketplace/plugin install edge-stack@hirefrank-marketplace<command_purpose> Perform comprehensive pre-flight checks and deploy Cloudflare Workers safely using wrangler with multi-agent validation. </command_purpose>
<role>Cloudflare Deployment Specialist with expertise in Workers deployment, wrangler CLI, and production readiness validation</role>
This command performs thorough pre-deployment validation, runs all necessary checks, and safely deploys your Worker to Cloudflare's edge network.
<deployment_target> #$ARGUMENTS </deployment_target>
Supported targets:
--env staging - Deploy to staging environment--env preview - Deploy to preview environment--dry-run - Perform all checks without deploying<critical_requirement> ALL pre-flight checks must pass before deployment. No exceptions. </critical_requirement>
Checks to perform:
Verify wrangler.toml exists
if [ ! -f wrangler.toml ]; then
echo "❌ CRITICAL: wrangler.toml not found"
exit 1
fi
Validate required fields
remote = true configured for developmentCheck authentication
wrangler whoami
# Verify logged in to correct account
SKILL-based Continuous Validation (Already Active During Development):
Agent-based Comprehensive Analysis (Run for deployment validation):
Critical Checks (Must Pass):
Task workers-runtime-guardian(current code)
Task cloudflare-security-sentinel(current code)
Task binding-context-analyzer(current code)
Important Checks (Warnings):
Task edge-performance-oracle(current code)
Task cloudflare-pattern-specialist(current code)
Clean previous builds
rm -rf dist/ .wrangler/
Install dependencies
npm ci # Clean install from lock file
Type checking
npm run typecheck || tsc --noEmit
Linting
npm run lint
Run tests
npm test
Build Worker
wrangler deploy --dry-run --outdir=./dist
Analyze bundle size
du -h ./dist/*.js
# Warn if > 100KB, error if > 500KB
Ask user: "Run local testing with wrangler dev? (recommended, y/n)"
If yes:
curl http://localhost:8787/
# Verify 200 response
## Deployment Pre-Flight Summary
**Target Environment**: [production/staging/preview]
**Worker Name**: [from wrangler.toml]
**Account**: [from wrangler whoami]
### ✅ Configuration
- wrangler.toml: Valid
- Bindings: [X] configured
- KV: [list]
- R2: [list]
- D1: [list]
- DO: [list]
- Compatibility Date: [date] (✅ recent / ⚠️ outdated)
### ✅ Code Quality
- Runtime Compatibility: [PASS/FAIL]
- Issues: [X] Critical, [Y] Important
- Security: [PASS/FAIL]
- Issues: [X] Critical, [Y] Important
- Binding Validation: [PASS/FAIL]
- Mismatches: [count]
### ✅ Build
- TypeScript: [PASS/FAIL]
- Linting: [PASS/FAIL]
- Tests: [PASS/FAIL] ([X] passed, [Y] failed)
- Bundle Size: [size] (✅ < 100KB / ⚠️ > 100KB / ❌ > 500KB)
### 🔍 Performance Analysis
- Cold Start (estimated): [X]ms
- Heavy Dependencies: [list if any]
- Warnings: [count]
### ⚠️ Blocking Issues (Must Fix)
[List any P1 issues that prevent deployment]
### ⚠️ Warnings (Recommended to Fix)
[List any P2 issues]
---
**Decision**: [READY TO DEPLOY / ISSUES MUST BE FIXED]
<critical_requirement> Always require explicit user confirmation before deploying. </critical_requirement>
If blocking issues exist:
❌ Cannot deploy - [X] critical issues must be fixed:
1. [Issue description]
2. [Issue description]
Run /triage to create todos for these issues.
If only warnings exist:
⚠️ Ready to deploy with [X] warnings:
1. [Warning description]
2. [Warning description]
Deploy anyway? (yes/no/show-details)
If all checks pass:
✅ All checks passed. Ready to deploy.
Deploy to [environment]? (yes/no)
If user confirms YES:
Create git tag (if production)
if [ "$environment" = "production" ]; then
timestamp=$(date +%Y%m%d-%H%M%S)
git tag -a "deploy-$timestamp" -m "Production deployment $timestamp"
fi
Deploy with wrangler
# For default/production
wrangler deploy
# For specific environment
wrangler deploy --env $environment
Capture deployment output
Verify deployment
# Test deployed Worker
curl -I $worker_url
# Verify 200 response
Run quick smoke tests:
Health check
curl $worker_url/health || curl $worker_url/
# Expect 200 status
Verify bindings accessible (if applicable)
Check Cloudflare dashboard
wrangler tail --format json | head -n 5
# Show first 5 requests/logs
## 🚀 Deployment Complete
**Environment**: [production/staging/preview]
**Deployed At**: [timestamp]
**Worker URL**: [url]
**Custom Domain**: [domain] (if configured)
### Deployment Details
- Worker Name: [name]
- Bundle Size: [size]
- Deployment ID: [id]
- Git Tag: [tag] (if production)
### Verification
- Health Check: [✅ PASS / ❌ FAIL]
- Response Time: [X]ms
- Status Code: [code]
### Next Steps
1. Monitor logs: `wrangler tail`
2. View analytics: https://dash.cloudflare.com
3. Test endpoints: [list key endpoints]
### Rollback (if needed)
```bash
# View previous deployments
wrangler deployments list
# Rollback to previous version
wrangler rollback [deployment-id]
Status: ✅ Deployment Successful
## Emergency Rollback
If deployment fails or issues are detected:
1. **Immediate rollback**
```bash
wrangler deployments list
wrangler rollback [previous-deployment-id]
❌ Deployment rolled back to previous version
Reason: [failure reason]
Investigate issues:
- Check logs: wrangler tail
- Review errors: [error details]
Issue: "Error: Could not find binding {name}"
Solution: Run Task binding-context-analyzer to verify wrangler.toml
Issue: "Error: Bundle size too large"
Solution: Run Task edge-performance-oracle for optimization recommendations
Issue: "Error: Authentication failed"
Solution: Run wrangler login to re-authenticate
Issue: "Error: Worker exceeded CPU limit" Solution: Check for blocking operations, infinite loops, or heavy computation
✅ Deployment considered successful when:
Remember: It's better to fail pre-flight checks than to deploy broken code. Every check exists to prevent production issues.