Deployment Guide
Contents
Section titled “Contents”1. Local Test Sequence
Section titled “1. Local Test Sequence”Step 1: TypeScript Validation
Section titled “Step 1: TypeScript Validation”# TypeScript 타입 체크pnpm typecheckExpected Result:
✅ TypeScript validation passed (0 errors)If Failed: Fix type errors and rerun
Step 2: Unit Tests
Section titled “Step 2: Unit Tests”# 모든 테스트 실행pnpm test
# 또는 Cloudflare Workers 환경에서 테스트pnpm test:localExpected Result:
✓ test files passed✓ tests passedIf Failed: Identify and fix the cause of the test failure
Step 3: Integrated Validation (Recommended)
Section titled “Step 3: Integrated Validation (Recommended)”# 전체 검증 실행 (TypeScript + 테스트 + 빌드)pnpm run validate:localExpected Result:
🔍 Running complete local validation...==========================================
📝 Step 1: TypeScript type check...✅ TypeScript validation passed
🧪 Step 2: Running tests...✅ All tests passed
🔨 Step 3: Build validation (dry-run)...✅ Build validation passed
✅ All local validations passed!If Failed: Check and fix error messages for each step
Step 4: Local Server Test (Optional)
Section titled “Step 4: Local Server Test (Optional)”# 터미널 1: 로컬 개발 서버 시작pnpm dev:local
# 터미널 2: API 엔드포인트 테스트curl http://localhost:8787/healthcurl http://localhost:8787/api/v1/researchcurl http://localhost:8787/api/v1/seedsExpected Result:
// GET /health{ "status": "healthy", "timestamp": "2026-01-28T03:00:00.000Z", "version": "1.0.0"}2. Server Deployment
Section titled “2. Server Deployment”Environment-Specific Deploy Commands
Section titled “Environment-Specific Deploy Commands”Deploy to Staging Environment
Section titled “Deploy to Staging Environment”# Staging 환경으로 배포pnpm deploy:stagingOr use wrangler directly:
wrangler deploy --env staging --minifyExpected Result:
🌀 Creating the bundle...✨ Success! Uploaded newsfork-seeds-staging📦 Bundle size: 440.65 KiB / gzip: 101.38 KiBProduction Environment Deployment
Section titled “Production Environment Deployment”# Production 환경으로 배포pnpm deploy:productionOr use wrangler directly:
wrangler deploy --env production --minify⚠️ Caution: Proceed with caution when deploying to Production.
Pre-Deploy Checklist
Section titled “Pre-Deploy Checklist”1. Verify Cloudflare Authentication
Section titled “1. Verify Cloudflare Authentication”# Wrangler 로그인 상태 확인wrangler whoami
# 로그인이 안 되어 있다면wrangler login2. Verify Environment Variables and Secrets
Section titled “2. Verify Environment Variables and Secrets”# Staging secrets 확인wrangler secret list --env staging
# Production secrets 확인wrangler secret list --env productionRequired Secrets:
GH_TOKEN: GitHub API TokenGH_OWNER: GitHub Organization/UsernameGH_REPO: GitHub Repository Name
How to Set Secrets:
# 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 production3. Verify Resources
Section titled “3. Verify Resources”# D1 Database 확인wrangler d1 list
# KV Namespace 확인wrangler kv namespace list --env staging
# Queue 확인wrangler queues list
# R2 Bucket 확인wrangler r2 bucket listDeploy via GitHub Actions (Recommended)
Section titled “Deploy via GitHub Actions (Recommended)”Automatic Deployment (When pushing to main branch)
Section titled “Automatic Deployment (When pushing to main branch)”# 1. 로컬에서 모든 검증 완료pnpm run validate:local
# 2. 변경사항 커밋 및 푸시git add .git commit -m "feat: your changes"git push origin mainAutomatic Execution:
- GitHub Actions run automatically
- Follows this sequence:
validate→provision→deploy
Manual Deployment (workflow_dispatch)
Section titled “Manual Deployment (workflow_dispatch)”- GitHub repository → Actions tab
- Select the “Deploy” workflow
- Click “Run workflow”
- Select environment (staging or production)
- Run the workflow
3. Server Verification
Section titled “3. Server Verification”3.1 Basic Health Check
Section titled “3.1 Basic Health Check”Verify Health Endpoint
Section titled “Verify Health Endpoint”# Stagingcurl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/health
# Productioncurl https://newsfork-seeds.YOUR_SUBDOMAIN.workers.dev/healthExpected Response:
{ "status": "healthy", "timestamp": "2026-01-28T03:00:00.000Z", "version": "1.0.0"}Readiness Check
Section titled “Readiness Check”curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/health/readyExpected Response:
{ "ready": true, "timestamp": "2026-01-28T03:00:00.000Z"}Liveness Check
Section titled “Liveness Check”curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/health/liveExpected Response:
{ "alive": true, "timestamp": "2026-01-28T03:00:00.000Z"}3.2 API Endpoint Verification
Section titled “3.2 API Endpoint Verification”Root Endpoint
Section titled “Root Endpoint”curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/Expected Response:
{ "name": "NewsFork Seeds API", "version": "2.0.0", "build": { ... }, "environment": "staging", "endpoints": { ... }}Research API
Section titled “Research API”# Research 목록 조회curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/research
# 특정 Research 조회curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/research/sg/news/2026-01-28Seeds API
Section titled “Seeds API”# Seeds 목록 조회curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/seeds
# 특정 Seed 조회curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/seeds/gov:sg:mom.gov.sg::newsDatasets API
Section titled “Datasets API”# Datasets 목록 조회curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/datasets3.3 Integrated Validation Script
Section titled “3.3 Integrated Validation Script”Automated Validation Script (Optional)
Section titled “Automated Validation Script (Optional)”The script below is an example and is not included in the repository. Create it in your project root if needed.
# scripts/verify-deployment.sh (예시)#!/bin/bashset -e
ENV="${1:-staging}"BASE_URL="https://newsfork-seeds-${ENV}.YOUR_SUBDOMAIN.workers.dev"
echo "🔍 Verifying deployment for ${ENV}..."
# Health checkecho "1. Health check..."if curl -f "${BASE_URL}/health" > /dev/null 2>&1; then echo " ✅ Health check passed"else echo " ❌ Health check failed" exit 1fi
# Readiness checkecho "2. Readiness check..."if curl -f "${BASE_URL}/health/ready" > /dev/null 2>&1; then echo " ✅ Readiness check passed"else echo " ❌ Readiness check failed" exit 1fi
# API endpointsecho "3. API endpoints..."if curl -f "${BASE_URL}/api/v1/research" > /dev/null 2>&1; then echo " ✅ Research API accessible"else echo " ⚠️ Research API not accessible"fi
echo "✅ Deployment verification completed"Usage:
chmod +x scripts/verify-deployment.sh./scripts/verify-deployment.sh staging./scripts/verify-deployment.sh production3.4 Cloudflare Dashboard Check
Section titled “3.4 Cloudflare Dashboard Check”Workers Dashboard
Section titled “Workers Dashboard”- Access the Cloudflare Dashboard
- Workers & Pages → newsfork-seeds-staging (or production)
- Analytics tab: Check request count, error rate
- Logs tab: View real-time logs
- Settings tab: Check environment variables, Secrets
View real-time logs
Section titled “View real-time logs”# Wrangler를 통한 로그 확인wrangler tail --env staging
# 특정 필터링wrangler tail --env staging --format pretty | grep "error"3.5 Queue Status Check
Section titled “3.5 Queue Status Check”Check Queue Status
Section titled “Check Queue Status”# Queue 목록 확인wrangler queues list
# 특정 Queue의 메시지 확인 (Cloudflare Dashboard에서)# Workers & Pages → Queues → newsfork-research-stagingQueue Message Transmission Test
Section titled “Queue Message Transmission Test”# Orchestrator API 호출 (Queue 메시지 생성)curl -X POST https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/api/v1/seeds/orchestrate \ -H "Content-Type: application/json" \ -d '{ "country": "sg", "category": "news", "date": "2026-01-28" }'Expected Response:
{ "status": "queued", "files_found": 10, "messages_sent": 10, "skipped": 0}4. Troubleshooting
Section titled “4. Troubleshooting”4.1 Test Errors (Vitest)
Section titled “4.1 Test Errors (Vitest)”Symptom: this.snapshotClient.startCurrentRun is not a function
Cause: Version compatibility issue between vitest and @cloudflare/vitest-pool-workers.
Action: If TypeScript validation passes, deployment is possible. If necessary, visit pnpm update vitest @cloudflare/vitest-pool-workers or rm -rf node_modules pnpm-lock.yaml && pnpm install and try again.
4.2 When Deploy Fails
Section titled “4.2 When Deploy Fails”Error: “Queue does not exist”
Section titled “Error: “Queue does not exist””# Staging 예시 (실제 이름은 wrangler.jsonc env별 설정 참조)wrangler queues create newsfork-research-stagingwrangler queues create newsfork-contract-stagingwrangler queues create newsfork-liveness-stagingwrangler queues create newsfork-seed-stagingwrangler queues create newsfork-domain-stagingwrangler queues create newsfork-dlq-stagingwrangler queues create newsfork-seed-dlq-stagingwrangler queues create newsfork-domain-dlq-stagingError: “D1 database not found”
Section titled “Error: “D1 database not found””# D1 Database 확인wrangler d1 list
# Database가 없다면 생성 (이름은 wrangler.jsonc의 해당 env와 일치해야 함)wrangler d1 create newsfork-metadata-stagingError: “KV namespace not found”
Section titled “Error: “KV namespace not found””# KV Namespace 생성wrangler kv namespace create DOMAIN_KV --env staging4.3 When Health Check Fails
Section titled “4.3 When Health Check Fails”502 Bad Gateway
Section titled “502 Bad Gateway”Cause: Worker did not start
Resolution:
- Check Worker status in Cloudflare Dashboard
- Check error messages in logs
- Check environment variables and secrets
500 Internal Server Error
Section titled “500 Internal Server Error”Cause: Runtime error
Resolution:
# 실시간 로그 확인wrangler tail --env staging
# 에러 메시지 확인 후 코드 수정4.4 When API Endpoints Fail
Section titled “4.4 When API Endpoints Fail”404 Not Found
Section titled “404 Not Found”Cause: Route not registered
Resolution:
- Verify route registration at
src/routes/index.ts - Verify route mapping at
src/index.ts
401/403 Unauthorized
Section titled “401/403 Unauthorized”Cause: Missing or invalid authentication token
Resolution:
# Secrets 확인wrangler secret list --env staging
# Secret 재설정wrangler secret put GH_TOKEN --env stagingChecklist
Section titled “Checklist”Pre-Deploy Checklist
Section titled “Pre-Deploy Checklist”- Passed local TypeScript validation (
pnpm typecheck) - Passed local tests (
pnpm test) - Passed local build validation (
pnpm run validate:local) - Cloudflare authentication verified (
wrangler whoami) - Required secrets configuration verified
- Resource existence verified (D1, KV, Queue, R2)
Post-Deploy Checklist
Section titled “Post-Deploy Checklist”- Verify Health endpoint response (
/health) - Pass readiness check (
/health/ready) - Liveness check passed (
/health/live) - API endpoints accessible (
/api/v1/research,/api/v1/seeds) - No errors in Cloudflare Dashboard
- No errors in real-time logs
Quick Reference
Section titled “Quick Reference”Key Commands
Section titled “Key Commands”# 검증pnpm typecheck # TypeScript 검증pnpm test # 테스트 실행pnpm run validate:local # 전체 검증
# 배포pnpm deploy:staging # Staging 배포pnpm deploy:production # Production 배포
# 확인curl https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev/healthwrangler tail --env stagingKey URLs
Section titled “Key URLs”- Staging:
https://newsfork-seeds-staging.YOUR_SUBDOMAIN.workers.dev - Production:
https://newsfork-seeds.YOUR_SUBDOMAIN.workers.dev - Health:
/health,/health/ready,/health/live - API:
/api/v1/research,/api/v1/seeds,/api/v1/datasets
Date Created: 2026-01-28
Last Updated: 2026-01-28