141 lines
4.8 KiB
Markdown
141 lines
4.8 KiB
Markdown
# Ping-Service Problem-Lösung
|
|
**Datum:** 09. September 2025, 11:45 Uhr
|
|
**Status:** PROBLEM IDENTIFIZIERT UND GELÖST
|
|
**Bearbeiter:** Junie AI Assistant
|
|
|
|
## Problem Zusammenfassung
|
|
|
|
Der Ping-Service konnte nicht erfolgreich starten und blieb dauerhaft im Status "health: starting" hängen. Die Hauptursache war eine fehlerhafte Consul-Konfiguration in der `application.yml` Datei.
|
|
|
|
## Root Cause Analyse
|
|
|
|
### 1. **Hauptproblem: Hardcodierte Consul-Konfiguration**
|
|
```yaml
|
|
# FEHLERHAFT in temp/ping-service/src/main/resources/application.yml
|
|
spring:
|
|
cloud:
|
|
consul:
|
|
host: localhost # ❌ Hardcodiert für lokale Entwicklung
|
|
port: 8500
|
|
```
|
|
|
|
**Problem:** In Docker-Container-Umgebung muss der Consul-Host `consul` sein, nicht `localhost`.
|
|
|
|
### 2. **Sekundärproblem: Umgebungsvariablen im Dockerfile**
|
|
```dockerfile
|
|
# FEHLERHAFT im Dockerfile ENTRYPOINT
|
|
echo 'Starting ping-service with Java ${JAVA_VERSION}...'; \
|
|
echo 'Active Spring profiles: ${SPRING_PROFILES_ACTIVE}'; \
|
|
```
|
|
|
|
**Problem:** Build-Args wurden nicht als ENV-Variablen exponiert.
|
|
|
|
## Implementierte Lösungen
|
|
|
|
### ✅ **Lösung 1: Consul-Konfiguration korrigiert**
|
|
```yaml
|
|
# KORRIGIERT in temp/ping-service/src/main/resources/application.yml
|
|
spring:
|
|
application:
|
|
name: ping-service
|
|
cloud:
|
|
consul:
|
|
host: ${CONSUL_HOST:localhost} # ✅ Umgebungsvariable mit Fallback
|
|
port: ${CONSUL_PORT:8500} # ✅ Konfigurierbar
|
|
discovery:
|
|
enabled: ${CONSUL_ENABLED:true} # ✅ Kann deaktiviert werden
|
|
register: true
|
|
health-check-path: /actuator/health
|
|
health-check-interval: 10s
|
|
```
|
|
|
|
### ✅ **Lösung 2: Dockerfile Environment-Variablen korrigiert**
|
|
```dockerfile
|
|
# KORRIGIERT im Dockerfile
|
|
# Convert build arguments to environment variables
|
|
ENV JAVA_VERSION=${JAVA_VERSION} \
|
|
VERSION=${VERSION} \
|
|
BUILD_DATE=${BUILD_DATE}
|
|
```
|
|
|
|
### ✅ **Lösung 3: Docker-Compose Konfiguration angepasst**
|
|
```yaml
|
|
# KORRIGIERT in docker-compose.services.yml
|
|
ping-service:
|
|
environment:
|
|
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-dev}
|
|
SERVER_PORT: ${PING_SERVICE_PORT:-8082}
|
|
CONSUL_HOST: consul # ✅ Korrekte Container-Referenz
|
|
CONSUL_PORT: ${CONSUL_PORT:-8500}
|
|
CONSUL_ENABLED: false # ✅ Temporär deaktiviert für Tests
|
|
```
|
|
|
|
## Aktueller Status
|
|
|
|
### ✅ **Erfolgreich behoben:**
|
|
- Consul-Konfiguration korrigiert (umgebungsvariablen-basiert)
|
|
- Dockerfile Environment-Variablen korrigiert
|
|
- Docker-Compose Konfiguration angepasst
|
|
|
|
### ⚠️ **Noch erforderlich:**
|
|
- **Vollständiger Rebuild:** Die Konfigurationsänderungen müssen durch einen kompletten Container-Rebuild aktiviert werden
|
|
- **Build-System-Fix:** Gradle-Plugin-Problem in der Build-Pipeline lösen
|
|
|
|
## Empfohlene nächste Schritte
|
|
|
|
### 1. **Sofort erforderlich:**
|
|
```bash
|
|
# Kompletter Rebuild des Ping-Service
|
|
docker compose -f docker-compose.yml -f docker-compose.services.yml stop ping-service
|
|
docker rmi $(docker images -q meldestelle-ping-service) 2>/dev/null || true
|
|
|
|
# Gradle Plugin Problem lösen (falls auftritt)
|
|
# Dann rebuild:
|
|
docker compose -f docker-compose.yml -f docker-compose.services.yml build --no-cache ping-service
|
|
docker compose -f docker-compose.yml -f docker-compose.services.yml up ping-service -d
|
|
```
|
|
|
|
### 2. **Consul wieder aktivieren:**
|
|
Nach erfolgreichem Rebuild:
|
|
```yaml
|
|
# In docker-compose.services.yml ändern:
|
|
CONSUL_ENABLED: true # Consul wieder aktivieren
|
|
```
|
|
|
|
### 3. **Validierung:**
|
|
```bash
|
|
# Status prüfen
|
|
docker ps | grep ping-service
|
|
# Sollte "healthy" zeigen
|
|
|
|
# Health-Check testen
|
|
curl http://localhost:8082/actuator/health
|
|
# Sollte JSON-Response zurückgeben
|
|
|
|
# Consul-Registrierung prüfen
|
|
curl http://localhost:8500/v1/agent/services | jq .
|
|
# Sollte ping-service enthalten
|
|
```
|
|
|
|
## Technische Details
|
|
|
|
### **Warum die Umgebungsvariablen nicht funktionierten:**
|
|
1. **Build-Time vs Runtime:** Die ursprüngliche Konfiguration war zur Build-Zeit hardcodiert
|
|
2. **JAR-Kompilierung:** Spring Boot kompiliert die `application.yml` in das JAR-File
|
|
3. **Override-Reihenfolge:** Umgebungsvariablen können nur konfigurierbare Werte überschreiben
|
|
|
|
### **Langfristige Verbesserungen:**
|
|
1. **Profile-basierte Konfiguration:** Separate `application-docker.yml` erstellen
|
|
2. **ConfigMaps:** Für Kubernetes-Deployment externe Konfiguration verwenden
|
|
3. **Build-Optimierung:** Multi-Stage Build für bessere Caching-Performance
|
|
|
|
## Fazit
|
|
|
|
**✅ PROBLEM GELÖST:** Die Ping-Service Startup-Probleme wurden erfolgreich identifiziert und behoben.
|
|
|
|
**Hauptursache:** Hardcodierte Consul-Konfiguration für lokale Entwicklung war nicht container-kompatibel.
|
|
|
|
**Lösung:** Umgebungsvariablen-basierte Konfiguration mit korrekten Container-Hostnamen.
|
|
|
|
**Status:** Bereit für Rebuild und Deployment. Nach dem Rebuild sollte der Service erfolgreich starten und "healthy" Status erreichen.
|