# Deployment Checklist für Image Service

## Pre-Deployment Vorbereitung

### 1. Prerequisites
- [ ] Docker und Docker Compose installiert
- [ ] Node.js 18+ (für lokale Entwicklung)
- [ ] Java 17+ und Maven (für Spring Boot)
- [ ] kubectl konfiguriert (für Kubernetes Deployment)

### 2. Lokale Tests
- [ ] Puppeteer Service lokal getestet (`npm start`)
- [ ] Spring Boot Controller getestet
- [ ] Integration zwischen Frontend SDK und Backend getestet
- [ ] Test-Script erfolgreich ausgeführt (`./test-image.sh`)

## Docker Deployment

### 3. Docker Image Build
```bash
cd image-service
docker build -t releasebird/image-service:latest .
docker build -t releasebird/image-service:v1.0.0 .
```

- [ ] Docker Image erfolgreich gebaut
- [ ] Image lokal getestet:
```bash
docker run -p 3000:3000 releasebird/image-service:latest
curl http://localhost:3000/health
```

### 4. Docker Registry Push
```bash
# Tag für Registry
docker tag releasebird/image-service:latest registry.your-domain.com/releasebird/image-service:latest

# Push
docker push registry.your-domain.com/releasebird/image-service:latest
docker push registry.your-domain.com/releasebird/image-service:v1.0.0
```

- [ ] Image in Registry gepusht
- [ ] Image Pull von anderen Hosts getestet

### 5. Docker Compose Deployment

```bash
cd backend-image-service

# Production Compose File verwenden
docker-compose -f docker-compose.prod.yml up -d

# Logs prüfen
docker-compose logs -f
```

- [ ] Service gestartet
- [ ] Health Check erfolgreich: `curl http://localhost:3000/health`
- [ ] Image Test erfolgreich

## Kubernetes Deployment

### 6. Kubernetes Manifests anpassen

```bash
cd kubernetes/
```

Anpassen:
- [ ] `puppeteer-deployment.yaml` - Image URL
- [ ] `configmap.yaml` - Environment Variables
- [ ] Resource Limits basierend auf Last

### 7. Kubernetes Deployment ausführen

```bash
# ConfigMap erstellen
kubectl apply -f configmap.yaml

# Service und Deployment erstellen
kubectl apply -f puppeteer-deployment.yaml

# Status prüfen
kubectl get pods -l app=image-service
kubectl get svc image-service
```

- [ ] Pods laufen erfolgreich
- [ ] Service erreichbar
- [ ] HorizontalPodAutoscaler konfiguriert

### 8. Kubernetes Health Checks

```bash
# Port Forward für Test
kubectl port-forward svc/image-service 3000:3000

# Health Check
curl http://localhost:3000/health

# Pod Logs
kubectl logs -f deployment/image-service
```

- [ ] Health Checks erfolgreich
- [ ] Keine Fehler in Logs

## Spring Boot Integration

### 9. Spring Boot Deployment

In deinem Spring Boot Projekt:

- [ ] `ImageController.java` integriert
- [ ] `RestTemplateConfig.java` integriert
- [ ] `application.properties` konfiguriert:
```properties
# Kubernetes Service URL
image.service.url=http://image-service.default.svc.cluster.local:3000
```

### 10. Spring Boot Tests

```bash
# Build
mvn clean package

# Run
java -jar target/your-app.jar

# Test Endpoint
curl -X POST http://localhost:8080/ewidget/image/health
```

- [ ] Build erfolgreich
- [ ] Health Endpoint antwortet
- [ ] Image Endpoint funktioniert

## Frontend SDK Deployment

### 11. JavaScript SDK Build

```bash
cd /Users/christianzillmann/IdeaProjects/releasebird-javascript-sdk
npm run build
```

- [ ] Build erfolgreich: `build/index.js`
- [ ] Kein Fehler in Console
- [ ] Bundle Size akzeptabel (< 150 KB)

### 12. SDK Deployment

- [ ] `build/index.js` zu CDN hochgeladen
- [ ] CDN URL in Kunden-Integration aktualisiert
- [ ] Cache invalidiert

## Production Monitoring

### 13. Monitoring Setup

- [ ] Health Check Monitoring eingerichtet
  - Puppeteer: `http://image-service:3000/health`
  - Spring Boot: `http://api-service:8080/actuator/health`

- [ ] Prometheus Metrics (optional):
```yaml
# Prometheus ServiceMonitor
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: image-service
spec:
  selector:
    matchLabels:
      app: image-service
```

- [ ] Grafana Dashboard eingerichtet
- [ ] Alerts konfiguriert:
  - CPU > 80%
  - Memory > 80%
  - Health Check Failures
  - Response Time > 5s

### 14. Logging

- [ ] Log Aggregation eingerichtet (ELK, Loki, CloudWatch)
- [ ] Log Retention konfiguriert
- [ ] Log Level auf Production gesetzt (INFO)

## Performance Tuning

### 15. Load Testing

```bash
# Mit Apache Bench
ab -n 100 -c 10 -p image-payload.json -T application/json \
  http://localhost:3000/render

# Mit k6
k6 run loadtest.js
```

- [ ] Load Test durchgeführt
- [ ] Performance akzeptabel (< 2s pro Image)
- [ ] Keine Memory Leaks
- [ ] Pods skalieren korrekt mit Last

### 16. Resource Optimization

Basierend auf Load Tests anpassen:

```yaml
resources:
  limits:
    cpu: "2000m"      # Anpassen basierend auf Last
    memory: "2Gi"     # Anpassen basierend auf Last
  requests:
    cpu: "1000m"
    memory: "1Gi"
```

- [ ] CPU Limits optimiert
- [ ] Memory Limits optimiert
- [ ] HPA Thresholds angepasst

## Security

### 17. Security Hardening

- [ ] Non-root User (bereits in Dockerfile)
- [ ] Security Context konfiguriert (Kubernetes)
- [ ] Network Policies eingerichtet
- [ ] Rate Limiting im Spring Boot Controller
- [ ] Input Validation für HTML Content
- [ ] API Key Validation (falls erforderlich)

### 18. Secrets Management

- [ ] Sensitive Daten in Kubernetes Secrets
- [ ] Environment Variables nicht hardcoded
- [ ] TLS/SSL für externe Kommunikation

## Post-Deployment

### 19. Smoke Tests

Nach Deployment testen:

```bash
# Health Checks
curl http://your-domain.com/health
curl http://your-domain.com/actuator/health

# Image Test
./test-image.sh http://your-domain.com
```

- [ ] Alle Health Checks erfolgreich
- [ ] Image Generierung funktioniert
- [ ] Keine Fehler in Production Logs

### 20. Rollback Plan

Vorbereitet für Rollback:

```bash
# Kubernetes Rollback
kubectl rollout undo deployment/image-service

# Docker Compose Rollback
docker-compose -f docker-compose.prod.yml down
# Alte Version starten
```

- [ ] Rollback Prozedur dokumentiert
- [ ] Alte Images verfügbar
- [ ] Backup der Konfiguration

## Documentation

### 21. Dokumentation aktualisieren

- [ ] Deployment Guides aktualisiert
- [ ] API Dokumentation aktualisiert
- [ ] Runbook für Operations Team erstellt
- [ ] Troubleshooting Guide erweitert

## Sign-Off

- [ ] Development Team: _______________
- [ ] QA Team: _______________
- [ ] DevOps Team: _______________
- [ ] Product Owner: _______________

**Deployment Date:** _______________
**Deployed By:** _______________
**Version:** v1.0.0
