✅ Updated All Docker Compose References: - package.json: docker:compose and docker:down scripts - scripts/deploy.sh: All compose commands and checks - scripts/monitor.sh: All compose commands - DEPLOYMENT.md: Documentation examples - .github/workflows/ci-cd.yml: CI/CD pipeline �� Benefits: - Compatible with newer Docker versions (docker compose) - No more 'command not found' errors - Consistent syntax across all files - Successful deployment and monitoring 📝 Changed: - 'docker-compose' → 'docker compose' (new syntax) - Updated command availability checks - Fixed all script references
5.8 KiB
5.8 KiB
Portfolio Deployment Guide
Übersicht
Dieses Portfolio verwendet ein optimiertes CI/CD-System mit Docker für Production-Deployment. Das System ist darauf ausgelegt, hohen Traffic zu bewältigen und automatische Tests vor dem Deployment durchzuführen.
🚀 Features
✅ CI/CD Pipeline
- Automatische Tests vor jedem Deployment
- Security Scanning mit Trivy
- Multi-Architecture Docker Builds (AMD64 + ARM64)
- Health Checks und Deployment-Verifikation
- Automatische Cleanup alter Images
⚡ Performance-Optimierungen
- Multi-Stage Docker Build für kleinere Images
- Nginx Load Balancer mit Caching
- Gzip Compression und optimierte Headers
- Rate Limiting für API-Endpoints
- Resource Limits für Container
🔒 Sicherheit
- Non-root User im Container
- Security Headers (HSTS, CSP, etc.)
- SSL/TLS Termination mit Nginx
- Vulnerability Scanning in CI/CD
📁 Dateistruktur
├── .github/workflows/
│ └── ci-cd.yml # CI/CD Pipeline
├── scripts/
│ ├── deploy.sh # Deployment-Skript
│ └── monitor.sh # Monitoring-Skript
├── docker-compose.prod.yml # Production Docker Compose
├── nginx.conf # Nginx Konfiguration
├── Dockerfile # Optimiertes Dockerfile
└── env.example # Environment Template
🛠️ Setup
1. Environment Variables
# Kopiere die Beispiel-Datei
cp env.example .env
# Bearbeite die .env Datei mit deinen Werten
nano .env
2. GitHub Secrets & Variables
Konfiguriere in deinem GitHub Repository:
Secrets:
GITHUB_TOKEN(automatisch verfügbar)GHOST_API_KEYMY_PASSWORDMY_INFO_PASSWORD
Variables:
NEXT_PUBLIC_BASE_URLGHOST_API_URLMY_EMAILMY_INFO_EMAIL
3. SSL-Zertifikate
# Erstelle SSL-Verzeichnis
mkdir -p ssl
# Kopiere deine SSL-Zertifikate
cp your-cert.pem ssl/cert.pem
cp your-key.pem ssl/key.pem
🚀 Deployment
Automatisches Deployment
Das System deployt automatisch bei Push auf den production Branch:
# Code auf production Branch pushen
git push origin production
Manuelles Deployment
# Lokales Deployment
./scripts/deploy.sh production
# Oder mit npm
npm run deploy
Docker Commands
# Container starten
npm run docker:compose
# Container stoppen
npm run docker:down
# Health Check
npm run health
📊 Monitoring
Container Status
# Status anzeigen
./scripts/monitor.sh status
# Oder mit npm
npm run monitor status
Health Check
# Application Health
./scripts/monitor.sh health
# Oder direkt
curl http://localhost:3000/api/health
Logs anzeigen
# Letzte 50 Zeilen
./scripts/monitor.sh logs 50
# Live-Logs folgen
./scripts/monitor.sh logs 100
Metriken
# Detaillierte Metriken
./scripts/monitor.sh metrics
🔧 Wartung
Container neustarten
./scripts/monitor.sh restart
Cleanup
# Docker-Ressourcen bereinigen
./scripts/monitor.sh cleanup
Updates
# Neues Image pullen und deployen
./scripts/deploy.sh production
📈 Performance-Tuning
Nginx Optimierungen
- Gzip Compression aktiviert
- Static Asset Caching (1 Jahr)
- API Rate Limiting (10 req/s)
- Load Balancing bereit für Skalierung
Docker Optimierungen
- Multi-Stage Build für kleinere Images
- Non-root User für Sicherheit
- Health Checks für automatische Recovery
- Resource Limits (512MB RAM, 0.5 CPU)
Next.js Optimierungen
- Standalone Output für Docker
- Image Optimization (WebP, AVIF)
- CSS Optimization aktiviert
- Package Import Optimization
🚨 Troubleshooting
Container startet nicht
# Logs prüfen
./scripts/monitor.sh logs
# Status prüfen
./scripts/monitor.sh status
# Neustarten
./scripts/monitor.sh restart
Health Check schlägt fehl
# Manueller Health Check
curl -v http://localhost:3000/api/health
# Container-Logs prüfen
docker compose -f docker-compose.prod.yml logs portfolio
Performance-Probleme
# Resource-Usage prüfen
./scripts/monitor.sh metrics
# Nginx-Logs prüfen
docker compose -f docker-compose.prod.yml logs nginx
SSL-Probleme
# SSL-Zertifikate prüfen
openssl x509 -in ssl/cert.pem -text -noout
# Nginx-Konfiguration testen
docker compose -f docker-compose.prod.yml exec nginx nginx -t
📋 CI/CD Pipeline
Workflow-Schritte
- Test - Linting, Tests, Build
- Security - Trivy Vulnerability Scan
- Build - Multi-Arch Docker Image
- Deploy - Automatisches Deployment
Trigger
- Push auf
main- Build nur - Push auf
production- Build + Deploy - Pull Request - Test + Security
Monitoring
- GitHub Actions - Pipeline-Status
- Container Health - Automatische Checks
- Resource Usage - Monitoring-Skript
🔄 Skalierung
Horizontal Scaling
# In nginx.conf - weitere Backend-Server hinzufügen
upstream portfolio_backend {
least_conn;
server portfolio:3000 max_fails=3 fail_timeout=30s;
server portfolio-2:3000 max_fails=3 fail_timeout=30s;
server portfolio-3:3000 max_fails=3 fail_timeout=30s;
}
Vertical Scaling
# In docker-compose.prod.yml - Resource-Limits erhöhen
deploy:
resources:
limits:
memory: 1G
cpus: '1.0'
📞 Support
Bei Problemen:
- Logs prüfen:
./scripts/monitor.sh logs - Status prüfen:
./scripts/monitor.sh status - Health Check:
./scripts/monitor.sh health - Container neustarten:
./scripts/monitor.sh restart