From d8709c08494db269448c29c9de450eed3e30214f Mon Sep 17 00:00:00 2001 From: grabowski Date: Wed, 13 Aug 2025 16:35:23 +0700 Subject: [PATCH] Fix container networking: Use container IP for health checks 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 --- .gitea/workflows/release.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 3a9b7b8..0659f64 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -223,11 +223,21 @@ jobs: for i in {1..15}; do echo "⏳ Attempt $i/15: Testing health endpoint..." - # Test health endpoint with detailed debugging + # Test health endpoint with container networking echo "Testing health endpoint..." - # First try with verbose output to see what's happening - response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/health) + # 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]*$//') @@ -248,13 +258,24 @@ jobs: fi done - # Test API endpoints with better error handling + # Test API endpoints with container networking echo "🧪 Testing API endpoints..." + # 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..." - response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/$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