186 lines
4.1 KiB
Markdown
186 lines
4.1 KiB
Markdown
# Production Deployment Guide
|
|
|
|
## Voraussetzungen
|
|
|
|
- Docker und Docker Compose auf dem Server installiert
|
|
- Traefik läuft im `dockge_default` Netzwerk
|
|
- Domain `wetter.fuerst-stuttgart.de` zeigt auf den Server
|
|
- `.env` Datei mit Datenbank-Credentials
|
|
|
|
## 1. Images bauen und pushen
|
|
|
|
Lokal auf dem Entwicklungsrechner:
|
|
|
|
```bash
|
|
# Alle Images bauen und zur Registry pushen
|
|
./push-images.sh
|
|
```
|
|
|
|
Dieser Befehl:
|
|
- Baut `wetterstation-collector`
|
|
- Baut `wetterstation-api`
|
|
- Baut `wetterstation-frontend`
|
|
- Pusht alle Images zu `docker.citysensor.de`
|
|
|
|
## 2. Server vorbereiten
|
|
|
|
Auf dem Production-Server:
|
|
|
|
```bash
|
|
# Projekt-Verzeichnis erstellen
|
|
mkdir -p ~/wetterstation
|
|
cd ~/wetterstation
|
|
|
|
# docker-compose.prod.yml hochladen
|
|
# .env Datei erstellen oder hochladen
|
|
```
|
|
|
|
### Beispiel .env für Production:
|
|
|
|
```env
|
|
# Datenbank
|
|
DB_NAME=wetterstation
|
|
DB_USER=wetterstation_user
|
|
DB_PASSWORD=<sicheres-passwort>
|
|
DB_HOST=postgres
|
|
DB_PORT=5432
|
|
|
|
# Collector
|
|
COLLECTOR_PORT=8001
|
|
|
|
# Optional: PostgreSQL custom port
|
|
# DB_PORT=5432
|
|
```
|
|
|
|
## 3. Deployment starten
|
|
|
|
```bash
|
|
# Images von Registry pullen
|
|
docker-compose -f docker-compose.prod.yml pull
|
|
|
|
# Services starten
|
|
docker-compose -f docker-compose.prod.yml up -d
|
|
|
|
# Logs prüfen
|
|
docker-compose -f docker-compose.prod.yml logs -f
|
|
```
|
|
|
|
## 4. Erreichbarkeit
|
|
|
|
Nach erfolgreichem Start ist die Wetterstation erreichbar unter:
|
|
|
|
- **Frontend**: https://wetter.fuerst-stuttgart.de/
|
|
- **API**: https://wetter.fuerst-stuttgart.de/api/health
|
|
- **Collector**: https://wetter.fuerst-stuttgart.de/collector/health
|
|
|
|
Traefik übernimmt:
|
|
- Automatisches HTTPS (Let's Encrypt)
|
|
- Routing basierend auf Pfad
|
|
- StripPrefix für `/api` und `/collector`
|
|
|
|
## 5. Updates deployen
|
|
|
|
Bei Code-Änderungen:
|
|
|
|
```bash
|
|
# Lokal: Images neu bauen und pushen
|
|
./push-images.sh
|
|
|
|
# Server: Neue Images pullen und Container neu starten
|
|
ssh user@server
|
|
cd ~/wetterstation
|
|
docker-compose -f docker-compose.prod.yml pull
|
|
docker-compose -f docker-compose.prod.yml up -d
|
|
```
|
|
|
|
## 6. Nützliche Befehle
|
|
|
|
```bash
|
|
# Status prüfen
|
|
docker-compose -f docker-compose.prod.yml ps
|
|
|
|
# Logs einzelner Services
|
|
docker-compose -f docker-compose.prod.yml logs -f frontend
|
|
docker-compose -f docker-compose.prod.yml logs -f api
|
|
docker-compose -f docker-compose.prod.yml logs -f collector
|
|
docker-compose -f docker-compose.prod.yml logs -f postgres
|
|
|
|
# Service neu starten
|
|
docker-compose -f docker-compose.prod.yml restart api
|
|
|
|
# Alle Services stoppen
|
|
docker-compose -f docker-compose.prod.yml down
|
|
|
|
# Services stoppen und Volumes löschen (⚠️ löscht Daten!)
|
|
docker-compose -f docker-compose.prod.yml down -v
|
|
```
|
|
|
|
## 7. Datenbank-Backup
|
|
|
|
```bash
|
|
# Backup erstellen
|
|
docker exec wetterstation_db_prod pg_dump -U wetterstation_user wetterstation > backup_$(date +%Y%m%d_%H%M%S).sql
|
|
|
|
# Backup wiederherstellen
|
|
docker exec -i wetterstation_db_prod psql -U wetterstation_user wetterstation < backup.sql
|
|
```
|
|
|
|
## Architektur
|
|
|
|
```
|
|
Internet
|
|
↓
|
|
Traefik (dockge_default)
|
|
↓
|
|
├─→ Frontend (nginx) → API (intern)
|
|
├─→ API (FastAPI)
|
|
└─→ Collector (FastAPI)
|
|
↓
|
|
PostgreSQL (intern)
|
|
```
|
|
|
|
**Netzwerke**:
|
|
- `dockge_default` (external): Traefik-Netzwerk
|
|
- `wetterstation_internal`: Interne Service-Kommunikation
|
|
|
|
**Container**:
|
|
- `wetterstation_frontend_prod`: Nginx + React SPA
|
|
- `wetterstation_api_prod`: FastAPI (Weather Data API)
|
|
- `wetterstation_collector_prod`: FastAPI (Data Collection)
|
|
- `wetterstation_db_prod`: PostgreSQL 16
|
|
|
|
## Troubleshooting
|
|
|
|
### SSL-Zertifikat wird nicht erstellt
|
|
|
|
Prüfe:
|
|
- DNS zeigt auf Server: `dig wetter.fuerst-stuttgart.de`
|
|
- Traefik läuft: `docker ps | grep traefik`
|
|
- Port 80/443 offen: `netstat -tulpn | grep -E ':(80|443)'`
|
|
|
|
### API nicht erreichbar
|
|
|
|
```bash
|
|
# Prüfe ob Container läuft
|
|
docker ps | grep wetterstation_api_prod
|
|
|
|
# Prüfe Logs
|
|
docker logs wetterstation_api_prod
|
|
|
|
# Teste intern
|
|
docker exec wetterstation_api_prod curl localhost:8000/health
|
|
```
|
|
|
|
### Datenbank-Verbindungsfehler
|
|
|
|
```bash
|
|
# Prüfe ob DB läuft
|
|
docker ps | grep wetterstation_db_prod
|
|
|
|
# Prüfe DB-Logs
|
|
docker logs wetterstation_db_prod
|
|
|
|
# Teste Verbindung
|
|
docker exec wetterstation_db_prod psql -U wetterstation_user -d wetterstation -c "SELECT 1"
|
|
```
|