2 Commits

Author SHA1 Message Date
d8709c0849 Fix container networking: Use container IP for health checks
Some checks failed
Release - Northern Thailand Ping River Monitor / Create Release (push) Successful in 6s
Security & Dependency Updates / Dependency Security Scan (push) Successful in 26s
Security & Dependency Updates / License Compliance (push) Successful in 11s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.12) (push) Successful in 17s
Release - Northern Thailand Ping River Monitor / Build Release Images (push) Successful in 6m9s
Release - Northern Thailand Ping River Monitor / Security Scan (push) Successful in 7s
Release - Northern Thailand Ping River Monitor / Test Release Deployment (push) Failing after 1m23s
Release - Northern Thailand Ping River Monitor / Notify Release (push) Successful in 1s
Security & Dependency Updates / Check for Dependency Updates (push) Successful in 20s
Security & Dependency Updates / Code Quality Metrics (push) Successful in 16s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.10) (push) Successful in 15s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.11) (push) Successful in 13s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.9) (push) Successful in 15s
Security & Dependency Updates / Security Summary (push) Successful in 7s
Root Cause Identified:
- Gitea runner runs inside docker.gitea.com/runner-images:ubuntu-latest
- App container runs as sibling container, not accessible via localhost:8080
- Port mapping works for host access, but not container-to-container

 Networking Solution:
- Get container IP with: docker inspect ping-river-monitor-test
- Connect directly to container IP:8000 (internal port)
- Fallback to localhost:8080 if IP detection fails
- Bypasses localhost networking issues in containerized CI

 Updated Health Checks:
- Use container IP for direct communication
- Test internal port 8000 instead of mapped port 8080
- More reliable in containerized CI environments
- Better debugging with container IP logging

 Should resolve curl connection failures in Gitea CI environment
2025-08-13 16:35:23 +07:00
b753866b98 🔧 Make health checks more robust with detailed debugging
Some checks failed
Security & Dependency Updates / Dependency Security Scan (push) Has been cancelled
Security & Dependency Updates / License Compliance (push) Has been cancelled
Security & Dependency Updates / Check for Dependency Updates (push) Has been cancelled
Security & Dependency Updates / Code Quality Metrics (push) Has been cancelled
Security & Dependency Updates / Security Summary (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Create Release (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Test Release Build (3.10) (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Test Release Build (3.11) (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Test Release Build (3.12) (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Test Release Build (3.9) (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Build Release Images (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Security Scan (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Test Release Deployment (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Notify Release (push) Has been cancelled
🔍 Enhanced Debugging:
- Show HTTP response codes and response bodies
- Remove -f flag that was causing curl to fail on valid responses
- Add detailed logging for each endpoint test
- Show container logs on failures

🌐 Improved Health Check Logic:
- Check HTTP code = 200 AND response body exists
- Use curl -w to capture HTTP status codes
- Parse response and status separately
- More tolerant of response format variations

🧪 Better API Endpoint Testing:
- Test each endpoint individually with status reporting
- Show specific HTTP codes for each endpoint
- Clear success/failure messages per endpoint
- Exit only on actual HTTP errors

🎯 Addresses CI-Specific Issues:
- Local testing shows endpoints work correctly
- CI environment may have different curl behavior
- More detailed output will help identify root cause
- Removes false failures from -f flag sensitivity

 Should resolve curl failures despite HTTP 200 responses
2025-08-13 14:28:25 +07:00

View File

@@ -223,25 +223,69 @@ jobs:
for i in {1..15}; do
echo "⏳ Attempt $i/15: Testing health endpoint..."
# Use curl with more verbose output and longer timeout
if curl -f -s --max-time 10 --connect-timeout 5 http://127.0.0.1:8080/health; then
# Test health endpoint with container networking
echo "Testing health endpoint..."
# Get the container's IP address for direct communication
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
echo "Container IP: $CONTAINER_IP"
# Test using container IP directly (port 8000 inside container)
if [ -n "$CONTAINER_IP" ]; then
response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/health)
else
# Fallback to localhost if IP detection fails
response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/health)
fi
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
response_body=$(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//')
echo "HTTP Code: $http_code"
echo "Response Body: $response_body"
if [ "$http_code" = "200" ] && [ -n "$response_body" ]; then
echo "✅ Health endpoint responding successfully!"
break
else
echo "❌ Health check failed, waiting 15 seconds..."
echo "❌ Health check failed (HTTP: $http_code), waiting 15 seconds..."
# Show what's happening with the container
echo "Container status:"
docker ps | grep ping-river-monitor-test || echo "Container not found"
echo "Recent container logs:"
docker logs --tail 5 ping-river-monitor-test || true
sleep 15
fi
done
# Test API endpoints
# Test API endpoints with container networking
echo "🧪 Testing API endpoints..."
curl -f http://127.0.0.1:8080/health || exit 1
curl -f http://127.0.0.1:8080/docs || exit 1
curl -f http://127.0.0.1:8080/stations || exit 1
curl -f http://127.0.0.1:8080/metrics || exit 1
# Get container IP for direct communication
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
echo "Using container IP: $CONTAINER_IP"
endpoints=("health" "docs" "stations" "metrics")
for endpoint in "${endpoints[@]}"; do
echo "Testing /$endpoint..."
# Use container IP if available, otherwise fallback to localhost
if [ -n "$CONTAINER_IP" ]; then
response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/$endpoint)
else
response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/$endpoint)
fi
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
if [ "$http_code" = "200" ]; then
echo "✅ /$endpoint: OK (HTTP $http_code)"
else
echo "❌ /$endpoint: FAILED (HTTP $http_code)"
echo "Response: $(echo "$response" | sed 's/HTTP_CODE:[0-9]*$//')"
exit 1
fi
done
echo "✅ All health checks passed!"