# Deployment zu deiner Elastic Beanstalk Environment

## 🎯 Deine Environment

- **Application:** `releasebird-image-service`
- **Environment:** `Releasebird-image-service-env`
- **Region:** `eu-central-1` (Standard)

## 🚀 Quick Deployment (Empfohlen)

Einfach deployen ohne Prompts:

```bash
cd backend-image-service
./quick-deploy.sh
```

Das Script:
- ✅ Baut Docker Image
- ✅ Erstellt Deployment Package
- ✅ Uploaded zu S3
- ✅ Deployed zu `Releasebird-image-service-env`
- ✅ Wartet auf Completion
- ✅ Testet Health Endpoint

⏱️ Dauert ca. 5-10 Minuten

## 📦 Alternativer Deployment

Mit Standard Script (mit Prompts):

```bash
# Deployed zu deiner Environment (default)
./deploy-to-eb.sh

# Oder explizit:
./deploy-to-eb.sh Releasebird-image-service-env
```

## 🧪 Vor dem Deployment testen

Lokal testen:

```bash
# Mit Docker Compose
docker-compose up -d

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

# Test Script
./test-image.sh
```

## 📊 Nach dem Deployment

### Environment Status prüfen

```bash
aws elasticbeanstalk describe-environments \
  --environment-names Releasebird-image-service-env \
  --query 'Environments[0].[EnvironmentName,Status,Health,CNAME]' \
  --output table
```

### Logs anschauen

```bash
# Aktuelle Logs
aws elasticbeanstalk logs \
  --environment-name Releasebird-image-service-env

# Logs streamen (mit EB CLI)
eb logs --stream -e Releasebird-image-service-env
```

### Health Check

```bash
# Environment URL holen
ENV_URL=$(aws elasticbeanstalk describe-environments \
  --environment-names Releasebird-image-service-env \
  --query 'Environments[0].CNAME' \
  --output text)

# Health Check
curl http://$ENV_URL/health

# Image Test
curl -X POST http://$ENV_URL/render \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<!DOCTYPE html><html><body><h1>Test</h1></body></html>",
    "width": 1280,
    "height": 720
  }'
```

## 🔧 Troubleshooting

### Deployment schlägt fehl

```bash
# Environment Events anschauen
aws elasticbeanstalk describe-events \
  --environment-name Releasebird-image-service-env \
  --max-items 20

# Logs holen
aws elasticbeanstalk logs \
  --environment-name Releasebird-image-service-env
```

### Health Check schlägt fehl

```bash
# SSH in Instance (mit EB CLI)
eb ssh -e Releasebird-image-service-env

# Docker Logs anschauen
sudo docker logs $(sudo docker ps -q)

# Service Status
sudo docker ps
```

### Rollback zu vorheriger Version

```bash
# Letzte Versionen anzeigen
aws elasticbeanstalk describe-application-versions \
  --application-name releasebird-image-service \
  --max-records 10 \
  --query 'ApplicationVersions[*].[VersionLabel,DateCreated]' \
  --output table

# Zu Version rollback
aws elasticbeanstalk update-environment \
  --application-name releasebird-image-service \
  --environment-name Releasebird-image-service-env \
  --version-label v20251028-143000  # Ersetze mit gewünschter Version
```

## 🎯 Deployment Checklist

Vor jedem Deployment:

- [ ] Code-Änderungen getestet (lokal mit Docker)
- [ ] Health Endpoint funktioniert (`/health`)
- [ ] Render Endpoint funktioniert (`/render`)
- [ ] Docker Image baut erfolgreich
- [ ] AWS Credentials konfiguriert
- [ ] Docker läuft

Nach dem Deployment:

- [ ] Health Check erfolgreich
- [ ] Environment Status: `Ready`
- [ ] Health: `Green`
- [ ] Logs zeigen keine Fehler
- [ ] Test-Request funktioniert

## 📞 Quick Commands

```bash
# Deployment
./quick-deploy.sh

# Status
aws elasticbeanstalk describe-environments \
  --environment-names Releasebird-image-service-env

# Logs
aws elasticbeanstalk logs \
  --environment-name Releasebird-image-service-env

# Restart Environment
aws elasticbeanstalk restart-app-server \
  --environment-name Releasebird-image-service-env

# Health
curl http://$(aws elasticbeanstalk describe-environments \
  --environment-names Releasebird-image-service-env \
  --query 'Environments[0].CNAME' \
  --output text)/health
```

---

**Ready to deploy!** 🚀

Fragen? Siehe [ELASTIC_BEANSTALK_DEPLOYMENT.md](ELASTIC_BEANSTALK_DEPLOYMENT.md) für Details.
