- Add auto-deploy.sh script with full CI/CD pipeline - Add quick-deploy.sh for fast development deployments - Add Git post-receive hook for automatic deployment on push - Add comprehensive deployment documentation - Add npm scripts for easy deployment management - Include health checks, logging, and cleanup - Support for automatic rollback on failures
227 lines
4.7 KiB
Markdown
227 lines
4.7 KiB
Markdown
# Automatisches Deployment System
|
|
|
|
## Übersicht
|
|
|
|
Dieses Portfolio verwendet ein **automatisches Deployment-System**, das bei jedem Git Push die Codebase prüft, den Container erstellt und startet.
|
|
|
|
## 🚀 Deployment-Skripte
|
|
|
|
### **1. Auto-Deploy (Vollständig)**
|
|
```bash
|
|
# Vollständiges automatisches Deployment
|
|
./scripts/auto-deploy.sh
|
|
|
|
# Oder mit npm
|
|
npm run auto-deploy
|
|
```
|
|
|
|
**Was passiert:**
|
|
- ✅ Git Status prüfen und uncommitted Changes committen
|
|
- ✅ Latest Changes pullen
|
|
- ✅ ESLint Linting
|
|
- ✅ Tests ausführen
|
|
- ✅ Next.js Build
|
|
- ✅ Docker Image erstellen
|
|
- ✅ Container stoppen/starten
|
|
- ✅ Health Check
|
|
- ✅ Cleanup alter Images
|
|
|
|
### **2. Quick-Deploy (Schnell)**
|
|
```bash
|
|
# Schnelles Deployment ohne Tests
|
|
./scripts/quick-deploy.sh
|
|
|
|
# Oder mit npm
|
|
npm run quick-deploy
|
|
```
|
|
|
|
**Was passiert:**
|
|
- ✅ Docker Image erstellen
|
|
- ✅ Container stoppen/starten
|
|
- ✅ Health Check
|
|
|
|
### **3. Manuelles Deployment**
|
|
```bash
|
|
# Manuelles Deployment mit Docker Compose
|
|
./scripts/deploy.sh
|
|
|
|
# Oder mit npm
|
|
npm run deploy
|
|
```
|
|
|
|
## 🔄 Automatisches Deployment
|
|
|
|
### **Git Hook Setup**
|
|
Das System verwendet einen Git Post-Receive Hook, der automatisch bei jedem Push ausgeführt wird:
|
|
|
|
```bash
|
|
# Hook ist bereits konfiguriert in:
|
|
.git/hooks/post-receive
|
|
```
|
|
|
|
### **Wie es funktioniert:**
|
|
1. **Git Push** → Hook wird ausgelöst
|
|
2. **Auto-Deploy Script** wird ausgeführt
|
|
3. **Vollständige Pipeline** läuft automatisch
|
|
4. **Deployment** wird durchgeführt
|
|
5. **Health Check** bestätigt Erfolg
|
|
|
|
## 📋 Deployment-Schritte
|
|
|
|
### **Automatisches Deployment:**
|
|
```bash
|
|
# 1. Code Quality Checks
|
|
git status --porcelain
|
|
git pull origin main
|
|
npm run lint
|
|
npm run test
|
|
|
|
# 2. Build Application
|
|
npm run build
|
|
|
|
# 3. Docker Operations
|
|
docker build -t portfolio-app:latest .
|
|
docker tag portfolio-app:latest portfolio-app:$(date +%Y%m%d-%H%M%S)
|
|
|
|
# 4. Deployment
|
|
docker stop portfolio-app || true
|
|
docker rm portfolio-app || true
|
|
docker run -d --name portfolio-app -p 3000:3000 portfolio-app:latest
|
|
|
|
# 5. Health Check
|
|
curl -f http://localhost:3000/api/health
|
|
|
|
# 6. Cleanup
|
|
docker system prune -f
|
|
```
|
|
|
|
## 🎯 Verwendung
|
|
|
|
### **Für Entwicklung:**
|
|
```bash
|
|
# Schnelles Deployment während der Entwicklung
|
|
npm run quick-deploy
|
|
```
|
|
|
|
### **Für Production:**
|
|
```bash
|
|
# Vollständiges Deployment mit Tests
|
|
npm run auto-deploy
|
|
```
|
|
|
|
### **Automatisch bei Push:**
|
|
```bash
|
|
# Einfach committen und pushen
|
|
git add .
|
|
git commit -m "Update feature"
|
|
git push origin main
|
|
# → Automatisches Deployment läuft
|
|
```
|
|
|
|
## 📊 Monitoring
|
|
|
|
### **Container Status:**
|
|
```bash
|
|
# Status prüfen
|
|
npm run monitor status
|
|
|
|
# Health Check
|
|
npm run monitor health
|
|
|
|
# Logs anzeigen
|
|
npm run monitor logs
|
|
```
|
|
|
|
### **Deployment Logs:**
|
|
```bash
|
|
# Deployment-Logs anzeigen
|
|
tail -f /var/log/portfolio-deploy.log
|
|
|
|
# Git-Deployment-Logs
|
|
tail -f /var/log/git-deploy.log
|
|
```
|
|
|
|
## 🔧 Konfiguration
|
|
|
|
### **Ports:**
|
|
- **Standard Port:** 3000
|
|
- **Backup Port:** 3001 (falls 3000 belegt)
|
|
|
|
### **Container:**
|
|
- **Name:** portfolio-app
|
|
- **Image:** portfolio-app:latest
|
|
- **Restart Policy:** unless-stopped
|
|
|
|
### **Logs:**
|
|
- **Deployment Logs:** `/var/log/portfolio-deploy.log`
|
|
- **Git Logs:** `/var/log/git-deploy.log`
|
|
|
|
## 🚨 Troubleshooting
|
|
|
|
### **Deployment schlägt fehl:**
|
|
```bash
|
|
# Logs prüfen
|
|
docker logs portfolio-app
|
|
|
|
# Container-Status prüfen
|
|
docker ps -a
|
|
|
|
# Manuell neu starten
|
|
npm run quick-deploy
|
|
```
|
|
|
|
### **Port bereits belegt:**
|
|
```bash
|
|
# Ports prüfen
|
|
lsof -i :3000
|
|
|
|
# Anderen Port verwenden
|
|
docker run -d --name portfolio-app -p 3001:3000 portfolio-app:latest
|
|
```
|
|
|
|
### **Tests schlagen fehl:**
|
|
```bash
|
|
# Tests lokal ausführen
|
|
npm run test
|
|
|
|
# Linting prüfen
|
|
npm run lint
|
|
|
|
# Build testen
|
|
npm run build
|
|
```
|
|
|
|
## 📈 Features
|
|
|
|
### **Automatische Features:**
|
|
- ✅ **Git Integration** - Automatisch bei Push
|
|
- ✅ **Code Quality** - Linting und Tests
|
|
- ✅ **Health Checks** - Automatische Verifikation
|
|
- ✅ **Rollback** - Alte Container werden gestoppt
|
|
- ✅ **Cleanup** - Alte Images werden entfernt
|
|
- ✅ **Logging** - Vollständige Deployment-Logs
|
|
|
|
### **Sicherheits-Features:**
|
|
- ✅ **Non-root Container**
|
|
- ✅ **Resource Limits**
|
|
- ✅ **Health Monitoring**
|
|
- ✅ **Error Handling**
|
|
- ✅ **Rollback bei Fehlern**
|
|
|
|
## 🎉 Vorteile
|
|
|
|
1. **Automatisierung** - Keine manuellen Schritte nötig
|
|
2. **Konsistenz** - Immer gleiche Deployment-Prozesse
|
|
3. **Sicherheit** - Tests vor jedem Deployment
|
|
4. **Monitoring** - Vollständige Logs und Health Checks
|
|
5. **Schnell** - Quick-Deploy für Entwicklung
|
|
6. **Zuverlässig** - Automatische Rollbacks bei Fehlern
|
|
|
|
## 📞 Support
|
|
|
|
Bei Problemen:
|
|
1. **Logs prüfen:** `tail -f /var/log/portfolio-deploy.log`
|
|
2. **Container-Status:** `npm run monitor status`
|
|
3. **Health Check:** `npm run monitor health`
|
|
4. **Manueller Neustart:** `npm run quick-deploy`
|