Deployment ve CI/CD
Cloudflare Workers'a deploy, production yapılandırması, environment variables ve deployment best practices.
Achidemy, Cloudflare Workers üzerinde çalışır ve Wrangler CLI ile deploy edilir. Bu sayfa deployment sürecini, production yapılandırmasını ve best practices’i açıklar.
Deployment Süreci
Section titled “Deployment Süreci”1. Build
Section titled “1. Build”npm run buildİşlemler:
- React Router build (
react-router build) - TypeScript type checking (
react-router typegen) - Client ve server bundle’ları oluşturulur
- Output:
build/client/vebuild/server/
2. Deploy
Section titled “2. Deploy”npm run deploy# veyanpm run build && wrangler deployİşlemler:
build/client/static assets olarak deploy edilirbuild/server/worker code olarak deploy edilirworkers/app.tsworker entry point olarak kullanılır
Production Yapılandırması
Section titled “Production Yapılandırması”Environment Variables
Section titled “Environment Variables”Public Variables: wrangler.toml içinde [vars] bölümünde tanımlanır.
[vars]BASE_URL = "https://achidemy.net"BETTER_AUTH_URL = "https://achidemy.net"GOOGLE_CLIENT_ID = "..."BUNNY_LIBRARY_ID = "..."# vb.Secret Variables: CLI ile eklenir (git’e commit edilmez).
# Veritabanıwrangler secret put DATABASE_URL
# Stripewrangler secret put STRIPE_SECRET_KEYwrangler secret put STRIPE_WEBHOOK_SECRET
# Exchange Rate API (kur botu için)wrangler secret put EXCHANGE_API_KEY
# Better Authwrangler secret put BETTER_AUTH_SECRET
# Resend (e-posta)wrangler secret put RESEND_API_KEY
# Bunnywrangler secret put BUNNY_API_KEYwrangler secret put BUNNY_STORAGE_KEYwrangler secret put BUNNY_VIDEO_SECURITY_KEYHyperdrive Configuration
Section titled “Hyperdrive Configuration”Production: Hyperdrive ID wrangler.toml içinde tanımlıdır.
[[hyperdrive]]binding = "HYPERDRIVE"id = "59c4a12da58e45d3993436576a163c85"localConnectionString = "postgresql://..." # Sadece yerel içinNot: Production’da Hyperdrive üzerinden bağlantı sağlanır; yerel geliştirmede localConnectionString kullanılır (Neon pooler URL’si ile aynı veritabanına işaret etmelidir).
Custom domain ve rotalar (Achidemy)
Section titled “Custom domain ve rotalar (Achidemy)”Worker, apex ve B2B wildcard için aynı uygulamayı sunar. wrangler.toml örneği:
[[routes]]pattern = "achidemy.net/*"zone_name = "achidemy.net"
[[routes]]pattern = "*.achidemy.net/*"zone_name = "achidemy.net"DNS’te achidemy.net ve *.achidemy.net için Cloudflare proxy kayıtları bu Worker’a yönlendirilir; SSL için wildcard sertifika kullanılır.
Durable Objects
Section titled “Durable Objects”Production: Durable Object binding’leri wrangler.toml içinde tanımlıdır.
[[durable_objects.bindings]]name = "CHAT_ROOM"class_name = "ChatRoom"
[[migrations]]tag = "v1"new_sqlite_classes = ["ChatRoom"]Pre-Deployment Checklist
Section titled “Pre-Deployment Checklist”1. Environment Variables
Section titled “1. Environment Variables”- Tüm secret’lar Cloudflare’de tanımlı mı?
- Public variable’lar
wrangler.tomliçinde güncel mi? -
BASE_URLveBETTER_AUTH_URLproduction URL’ine ayarlı mı?
2. Database
Section titled “2. Database”- Migration’lar production DB’ye uygulandı mı?
- Hyperdrive ID doğru mu?
- Connection string test edildi mi?
3. Stripe
Section titled “3. Stripe”- Production Stripe key’leri kullanılıyor mu?
- Webhook endpoint production URL’ine ayarlı mı?
- Webhook secret production için güncel mi?
4. Build
Section titled “4. Build”-
npm run buildhatasız çalışıyor mu? - TypeScript type errors yok mu?
- React Router typegen çalışıyor mu?
5. Testing
Section titled “5. Testing”- Yerel testler geçiyor mu? (
npm run start) - Critical path’ler test edildi mi? (login, payment, course creation)
Deployment Komutları
Section titled “Deployment Komutları”Full Deploy
Section titled “Full Deploy”npm run deployAdımlar:
npm run build— Build işlemiwrangler deploy— Cloudflare’e deploy
Manual Deploy
Section titled “Manual Deploy”# 1. Buildnpm run build
# 2. Type check (opsiyonel ama önerilir)npm run typecheck
# 3. Deploywrangler deployPreview Deploy
Section titled “Preview Deploy”wrangler deploy --env previewKullanım: Production’a deploy etmeden önce test için.
CI/CD Pipeline (Gelecek)
Section titled “CI/CD Pipeline (Gelecek)”GitHub Actions Örneği
Section titled “GitHub Actions Örneği”name: Deploy to Cloudflare
on: push: branches: [main]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '18' - run: npm ci - run: npm run build - run: npm run typecheck - uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}Gereksinimler:
CLOUDFLARE_API_TOKEN— GitHub Secrets’a eklenmeliCLOUDFLARE_ACCOUNT_ID— GitHub Secrets’a eklenmeli
Rollback Stratejisi
Section titled “Rollback Stratejisi”Önceki Versiyona Dönme
Section titled “Önceki Versiyona Dönme”# Son deployment'ı görüntülewrangler deployments list
# Belirli bir deployment'a rollbackwrangler rollback [deployment-id]Database Rollback
Section titled “Database Rollback”Migration geri alma:
# Migration dosyasını geri al# Örnek: Drizzle migration'ı geri almak için SQL script çalıştırpsql $DATABASE_URL < rollback_script.sqlNot: Database rollback dikkatli yapılmalıdır; veri kaybına yol açabilir.
Monitoring ve Alerts
Section titled “Monitoring ve Alerts”Cloudflare Dashboard
Section titled “Cloudflare Dashboard”- Workers Logs:
wrangler tailveya Cloudflare Dashboard - Analytics: Request sayısı, error rate, response time
- Durable Objects: Chat room sayısı, WebSocket bağlantıları
Error Tracking
Section titled “Error Tracking”Önerilen: Sentry entegrasyonu
// Production'da error tracking aktif etif (import.meta.env.PROD) { Sentry.captureException(error);}Uptime Monitoring
Section titled “Uptime Monitoring”Önerilen: UptimeRobot, Pingdom veya Cloudflare Uptime Monitoring
- Ana sayfa:
https://achidemy.net - Health check endpoint:
/api/health(gelecekte eklenebilir)
Performance Optimization
Section titled “Performance Optimization”1. Asset Optimization
Section titled “1. Asset Optimization”- Image Optimization: Bunny CDN kullanılır
- Code Splitting: React Router otomatik code splitting yapar
- Bundle Size:
npm run buildile bundle analizi yapılabilir
2. Caching
Section titled “2. Caching”- Static Assets: Cloudflare CDN cache
- API Responses: Cache-Control header’ları kullanılabilir
- Database: Hyperdrive connection pooling
3. Edge Caching
Section titled “3. Edge Caching”- Cloudflare Cache: Static sayfalar için edge cache
- Cache Rules:
wrangler.tomlveya Cloudflare Dashboard’dan yapılandırılabilir
Troubleshooting
Section titled “Troubleshooting”Deployment Hatası
Section titled “Deployment Hatası”Sorun: wrangler deploy başarısız oluyor.
Çözümler:
- Cloudflare API token kontrolü
- Account ID kontrolü
wrangler.tomlsyntax kontrolü- Build output kontrolü (
build/klasörü var mı?)
Runtime Hatası
Section titled “Runtime Hatası”Sorun: Production’da uygulama çalışmıyor.
Çözümler:
- Worker logs kontrolü:
wrangler tail - Environment variables kontrolü:
wrangler secret list - Database bağlantısı kontrolü
- Error tracking servisine bak (Sentry vb.)
İlgili Dosyalar
Section titled “İlgili Dosyalar”wrangler.toml— Worker yapılandırmasıpackage.json— Build ve deploy script’leriworkers/app.ts— Worker entry point.dev.vars— Yerel geliştirme için environment variables (git’e eklenmez)