Environment Guide
🏗️ Production-Grade Environment Architecture
섹션 제목: “🏗️ Production-Grade Environment Architecture”This project implements Silicon Valley-standard environment isolation with legal compliance and data governance in mind.
🎯 Core Principle
섹션 제목: “🎯 Core Principle”Environment is in the configuration, not in variables
Each environment has completely separate Cloudflare resources (R2, D1, KV, Queues) to prevent contamination and ensure legal compliance.
📁 Environment Structure
섹션 제목: “📁 Environment Structure”Cloudflare Resources (Per Environment)
섹션 제목: “Cloudflare Resources (Per Environment)”Development:├── Workers: newsfork-seeds-dev├── R2: newsfork-datasets-dev, newsfork-metadata-dev├── D1: newsfork-metadata-dev├── KV: DOMAIN_KV (dev namespace)└── Queues: newsfork-research-dev, newsfork-contract-dev, newsfork-liveness-dev
Staging:├── Workers: newsfork-seeds-staging├── R2: newsfork-datasets-staging, newsfork-metadata-staging├── D1: newsfork-metadata-staging├── KV: DOMAIN_KV (staging namespace)└── Queues: newsfork-research-staging, newsfork-contract-staging, newsfork-liveness-staging
Production:├── Workers: newsfork-seeds-prod├── R2: newsfork-datasets-prod, newsfork-metadata-prod├── D1: newsfork-metadata-prod├── KV: DOMAIN_KV (prod namespace)└── Queues: newsfork-research-prod, newsfork-contract-prod, newsfork-liveness-prodData Storage
섹션 제목: “Data Storage”R2 (Raw Data):├── research/datasets/country=*/category=*/*.json├── research/liveness/country=*/*.json├── research/blocked/country=*/*.json└── research/dead/country=*/*.json
D1 (Metadata):├── dataset_metadata├── task_batches├── task_items├── domain_cache└── liveness_results
GitHub (Audit Trail):├── metadata/snapshot.json└── seeds/**/*.json🚦 Environment Details
섹션 제목: “🚦 Environment Details”🧪 Development (dev)
섹션 제목: “🧪 Development (dev)”Purpose: Safe experimentation and feature development
- Safety: ✅ Completely safe
- Data: Can be deleted/recreated freely
- Impact: Zero impact on staging/production
- Retention: 7 days
🎭 Staging (staging)
섹션 제목: “🎭 Staging (staging)”Purpose: Pre-production testing and integration validation
- Safety: ⚠️ Mirror of production
- Data: Should match production patterns
- Impact: No production impact
- Retention: 30 days
🏭 Production (production)
섹션 제목: “🏭 Production (production)”Purpose: Legal evidence and compliance records
- Safety: 🚨 CRITICAL - Legal implications
- Data: Immutable timestamped files
- Impact: Legal/compliance consequences
- Retention: 7 years (legal compliance)
🚀 Deployment Methods
섹션 제목: “🚀 Deployment Methods”Method 1: Wrangler CLI
섹션 제목: “Method 1: Wrangler CLI”# Development (local)pnpm run devpnpm run dev:local
# Development (remote)pnpm run dev:remote
# Staging deploymentpnpm run deploy:staging
# Production deploymentpnpm run deploy:productionMethod 2: GitHub Actions
섹션 제목: “Method 2: GitHub Actions”- Staging: Automatic on push to
mainbranch (whensrc/**,package.json, orwrangler.jsoncchanges) - Production: Manual trigger via
workflow_dispatchwith environment selection
Database Migrations
섹션 제목: “Database Migrations”# Apply migrations to devpnpm db:migrate
# Apply migrations to stagingpnpm db:migrate:staging
# Apply migrations to productionpnpm db:migrate:production🔧 Configuration
섹션 제목: “🔧 Configuration”Environment Variables (wrangler.jsonc)
섹션 제목: “Environment Variables (wrangler.jsonc)”| Variable | Dev | Staging | Production |
|---|---|---|---|
CF_ENV | dev | staging | production |
DATA_PATH_PREFIX | dev | staging | prod |
ENVIRONMENT | development | staging | production |
Cloudflare Resources
섹션 제목: “Cloudflare Resources”| Resource | Dev | Staging | Production |
|---|---|---|---|
| R2 Datasets | newsfork-datasets-dev | newsfork-datasets-staging | newsfork-datasets-prod |
| R2 Metadata | newsfork-metadata-dev | newsfork-metadata-staging | newsfork-metadata-prod |
| D1 Database | newsfork-metadata-dev | newsfork-metadata-staging | newsfork-metadata-prod |
| Research Queue | newsfork-research-dev | newsfork-research-staging | newsfork-research-prod |
| Contract Queue | newsfork-contract-dev | newsfork-contract-staging | newsfork-contract-prod |
| Liveness Queue | newsfork-liveness-dev | newsfork-liveness-staging | newsfork-liveness-prod |
| Seed Queue | newsfork-seed-dev | newsfork-seed-staging | newsfork-seed-prod |
| Domain Queue | newsfork-domain-dev | newsfork-domain-staging | newsfork-domain-prod |
| DLQ | newsfork-dlq-dev | newsfork-dlq-staging | newsfork-dlq-prod |
| Seed DLQ | newsfork-seed-dlq-dev | newsfork-seed-dlq-staging | newsfork-seed-dlq-prod |
| Domain DLQ | newsfork-domain-dlq-dev | newsfork-domain-dlq-staging | newsfork-domain-dlq-prod |
Queue Configuration
섹션 제목: “Queue Configuration”현재 wrangler.jsonc 기준, 모든 Queue는 max_batch_size=1 (파일 단위 처리):
| Queue | Max Batch Size | Max Batch Timeout | Max Retries | DLQ |
|---|---|---|---|---|
| Research | 1 | 30s | 3 | Yes |
| Contract | 1 | 30s | 3 | Yes |
| Liveness | 1 | 10s | 3 | Yes |
| Seed | 1 | 30s | 3 | Yes |
| Domain | 1 | 30s | 3 | Yes |
Queue Processing Flow:
- API creates batch → Messages enqueued
- Queue consumer processes messages in batches
- Failed messages retry up to 3 times
- Permanently failed messages → Dead Letter Queue (DLQ)
Secrets (per environment)
섹션 제목: “Secrets (per environment)”# Developmentwrangler secret put GH_TOKENwrangler secret put GH_OWNERwrangler secret put GH_REPO
# Stagingwrangler secret put GH_TOKEN --env stagingwrangler secret put GH_OWNER --env stagingwrangler secret put GH_REPO --env staging
# Productionwrangler secret put GH_TOKEN --env productionwrangler secret put GH_OWNER --env productionwrangler secret put GH_REPO --env production🛡️ Safety Rules
섹션 제목: “🛡️ Safety Rules”⚠️ Production Protection
섹션 제목: “⚠️ Production Protection”- Resource Isolation: Completely separate R2, D1, KV, Queues
- Manual Deployment: Production requires manual GitHub Actions trigger
- Immutability: Production data is write-once, read-many
- Audit Trail: All changes synced to GitHub for compliance
📋 Compliance Rules
섹션 제목: “📋 Compliance Rules”- Production data has 7-year retention
- All production operations are auditable via GitHub sync
- Metadata files committed to GitHub for transparency
- Queue DLQ preserves failed tasks for investigation
🧪 Testing Each Environment
섹션 제목: “🧪 Testing Each Environment”Development Testing
섹션 제목: “Development Testing”# Run local Workerspnpm run dev:local
# Test APIcurl http://localhost:8787/healthcurl http://localhost:8787/api/v1/datasetsStaging Testing
섹션 제목: “Staging Testing”# Deploy to stagingpnpm run deploy:staging
# Test APIcurl https://newsfork-seeds-staging.workers.dev/healthProduction Testing
섹션 제목: “Production Testing”# Full test suite firstpnpm test
# Deploy to production (requires confirmation)pnpm run deploy:production
# Test APIcurl https://newsfork-seeds-prod.workers.dev/health🚨 Emergency Procedures
섹션 제목: “🚨 Emergency Procedures”Production Issue Response
섹션 제목: “Production Issue Response”- Stop: Pause all Queue consumers if needed
- Assess: Check Cloudflare Dashboard for errors
- Document: Review DLQ for failed tasks
- Notify: Alert compliance team if data affected
- Preserve: Maintain audit trail in GitHub
Environment Contamination
섹션 제목: “Environment Contamination”- Identify: Locate affected R2/D1 data
- Quarantine: Disable affected environment
- Restore: Recover from R2 versioning or backups
- Validate: Verify data integrity via metadata snapshot
- Update: Strengthen access controls
📚 Best Practices
섹션 제목: “📚 Best Practices”Development
섹션 제목: “Development”- ✅ Experiment freely
- ✅ Use local mode (
pnpm run dev:local) - ✅ Delete/recreate resources as needed
- ✅ Test new features with Queue batches
Staging
섹션 제목: “Staging”- ✅ Mirror production patterns
- ✅ Run integration tests
- ✅ Validate Queue processing
- ✅ Test metadata sync to GitHub
Production
섹션 제목: “Production”- ⚠️ Manual deployment confirmation
- ⚠️ Full test suite must pass
- ⚠️ Legal compliance validation
- ⚠️ Monitor Queue DLQ
🔗 참고
섹션 제목: “🔗 참고”- Wrangler 설정: 프로젝트 루트
wrangler.jsonc - 마이그레이션: 기획·분석 → infra
- 배포 절차: 배포 절차
Production은 법적·컴플라이언스 경계이므로 수동 배포와 검증 후에만 사용하세요.