documentation/deployment/DEPLOYMENT_STRATEGY.md

150 lines
3.7 KiB
Markdown

# Deployment-Strategie: Dev → Production
*Erstellt: 27. Dezember 2025 | Aktualisiert: 29. Dezember 2025*
## Zusammenfassung
Diese Strategie gewährleistet fehlerfreie Deployments durch:
1. **Automatisierte CI/CD Pipeline** mit obligatorischen Tests
2. **Staging-first-Ansatz** - Änderungen müssen auf Staging erfolgreich sein
3. **Pre-deployment Backup** - Automatische Datenbank-Sicherung
4. **Health Checks** - Automatische Verifizierung nach Deployment
5. **Rollback-Mechanismus** - Schnelle Wiederherstellung bei Fehlern
---
## Umgebungen
| Umgebung | Server | URL | Branch | Zweck |
|----------|--------|-----|--------|-------|
| **Development** | sv-payload (LXC 700) | https://pl.porwoll.tech | `develop` | Entwicklung & Testing |
| **Production** | Hetzner 3 | https://cms.c2sgmbh.de | `main` | Live-System |
---
## Phase 1: Development & Testing (develop)
```bash
git checkout develop
git add . && git commit -m "feat: your feature"
git push origin develop
```
- **Push auf develop:** ESLint, Build Test, Auto-Deploy zu Staging
- **Pull Request:** Volle Test-Suite inkl. E2E
---
## Phase 2: Production Deployment (main)
### Via GitHub Actions (Empfohlen)
```bash
git checkout main && git merge develop && git push origin main
gh workflow run deploy-production.yml
```
Optionen: `skip_tests`, `skip_backup`, `skip_migrations`, `deploy_tag`
### Via Deploy-Script
```bash
ssh payload@162.55.85.18
cd ~/payload-cms
./scripts/deploy-production.sh
./scripts/deploy-production.sh --rollback # Rollback
./scripts/deploy-production.sh --dry-run # Dry-Run
```
---
## Schema-Synchronisation
```bash
pnpm payload migrate # Payload-Migrationen
pnpm exec drizzle-kit push --force # Schema-Sync
```
### Best Practices
1. Nach Collection-Änderungen: `pnpm payload migrate:create` auf DEV
2. Migrations committen: `git add src/migrations/`
3. Vor Deployment testen: `./scripts/sync-schema.sh --dry-run`
---
## Rollback-Strategie
```bash
# Automatischer Rollback
./scripts/deploy-production.sh --rollback
# Zu spezifischem Commit
git log --oneline -10
git reset --hard <commit-sha>
pnpm install --frozen-lockfile && pnpm build
pm2 restart payload
# Datenbank-Rollback
gunzip -c ~/backups/pre-deploy/payload_db_*.sql.gz | psql -U payload -d payload_db
```
---
## Pre-Deployment Checkliste
- [ ] CI-Tests auf develop erfolgreich
- [ ] Staging-Deployment erfolgreich
- [ ] Features auf Staging manuell getestet
- [ ] Keine offenen kritischen Bugs
- [ ] develop in main gemergt
- [ ] Bei DB-Änderungen: Migration auf Staging getestet
---
## GitHub Actions Workflows
| Workflow | Trigger | Geschätzte Dauer |
|----------|---------|------------------|
| CI (Push) | Push develop | ~3 Min |
| CI (PR) | Pull Request | ~15 Min |
| Security | PR + Wöchentlich | ~5 Min |
| Deploy Staging | Push develop | ~5 Min |
| Deploy Production | Manual | ~8 Min |
**Geschätzte monatliche Nutzung:** ~255 Min (von 2.000 kostenlos)
---
## Dateien
| Datei | Beschreibung |
|-------|-------------|
| `.github/workflows/ci.yml` | CI Pipeline |
| `.github/workflows/security.yml` | Security Scanning |
| `.github/workflows/deploy-staging.yml` | Staging-Deployment |
| `.github/workflows/deploy-production.yml` | Production-Deployment |
| `scripts/deploy-staging.sh` | Manuelles Staging-Script |
| `scripts/deploy-production.sh` | Manuelles Production-Script |
| `ecosystem.config.cjs` | PM2 Konfiguration |
---
## Best Practices
### Do's
- Immer erst auf Staging testen
- Backups vor kritischen Änderungen
- Kleine, inkrementelle Deployments
- Rollback-Plan vorbereiten
### Don'ts
- Nie direkt auf main entwickeln
- Nie ohne Tests deployen
- Nie große Schema-Änderungen ohne Backup
- Nie am Freitag Nachmittag deployen
---
*Dokumentation: Complex Care Solutions GmbH | 27.12.2025*