Add multi-method connection strategy for container health checks
Some checks failed
Release - Northern Thailand Ping River Monitor / Create Release (push) Successful in 5s
Security & Dependency Updates / Dependency Security Scan (push) Successful in 33s
Security & Dependency Updates / License Compliance (push) Successful in 13s
Security & Dependency Updates / Check for Dependency Updates (push) Successful in 19s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.10) (push) Successful in 16s
Security & Dependency Updates / Security Summary (push) Successful in 7s
Security & Dependency Updates / Code Quality Metrics (push) Successful in 20s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.11) (push) Successful in 15s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.12) (push) Successful in 14s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.9) (push) Successful in 17s
Release - Northern Thailand Ping River Monitor / Security Scan (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Build Release Images (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
Some checks failed
Release - Northern Thailand Ping River Monitor / Create Release (push) Successful in 5s
Security & Dependency Updates / Dependency Security Scan (push) Successful in 33s
Security & Dependency Updates / License Compliance (push) Successful in 13s
Security & Dependency Updates / Check for Dependency Updates (push) Successful in 19s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.10) (push) Successful in 16s
Security & Dependency Updates / Security Summary (push) Successful in 7s
Security & Dependency Updates / Code Quality Metrics (push) Successful in 20s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.11) (push) Successful in 15s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.12) (push) Successful in 14s
Release - Northern Thailand Ping River Monitor / Test Release Build (3.9) (push) Successful in 17s
Release - Northern Thailand Ping River Monitor / Security Scan (push) Has been cancelled
Release - Northern Thailand Ping River Monitor / Build Release Images (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
Connection Methods (in order of preference): 1. Container IP direct connection (172.17.0.x:8000) 2. Docker exec from inside container (127.0.0.1:8000) 3. Host networking fallback (127.0.0.1:8080) Addresses Exit Code 28 (Timeout): - Container IP connection was timing out in CI environment - Docker exec bypasses network isolation issues - Multiple fallback methods ensure reliability Improved Error Handling: - Shorter timeouts (5s max, 3s connect) for faster fallback - Clear method identification in logs - Graceful degradation through connection methods Why Docker Exec Should Work: - Runs curl from inside the target container - No network isolation between runner and app container - Direct access to 127.0.0.1:8000 (internal) - Most reliable method in containerized CI environments Should resolve timeout issues and provide reliable health checks
This commit is contained in:
@@ -230,12 +230,25 @@ jobs:
|
|||||||
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
|
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
|
||||||
echo "Container IP: $CONTAINER_IP"
|
echo "Container IP: $CONTAINER_IP"
|
||||||
|
|
||||||
# Test using container IP directly (port 8000 inside container)
|
# Try multiple connection methods
|
||||||
|
response=""
|
||||||
|
|
||||||
|
# Method 1: Try container IP directly
|
||||||
if [ -n "$CONTAINER_IP" ]; then
|
if [ -n "$CONTAINER_IP" ]; then
|
||||||
response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/health)
|
echo "Trying container IP: $CONTAINER_IP:8000"
|
||||||
else
|
response=$(curl -s --max-time 5 --connect-timeout 3 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/health 2>/dev/null || echo "TIMEOUT")
|
||||||
# Fallback to localhost if IP detection fails
|
fi
|
||||||
response=$(curl -s --max-time 10 --connect-timeout 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/health)
|
|
||||||
|
# Method 2: If container IP fails, try docker exec
|
||||||
|
if [[ "$response" == "TIMEOUT" ]] || [ -z "$response" ]; then
|
||||||
|
echo "Container IP failed, trying docker exec..."
|
||||||
|
response=$(docker exec ping-river-monitor-test curl -s --max-time 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8000/health 2>/dev/null || echo "EXEC_FAILED")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Method 3: If exec fails, try host networking
|
||||||
|
if [[ "$response" == "EXEC_FAILED" ]] || [ -z "$response" ]; then
|
||||||
|
echo "Docker exec failed, trying host networking..."
|
||||||
|
response=$(curl -s --max-time 5 --connect-timeout 3 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/health 2>/dev/null || echo "HOST_FAILED")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
||||||
@@ -260,20 +273,29 @@ jobs:
|
|||||||
|
|
||||||
# Test API endpoints with container networking
|
# Test API endpoints with container networking
|
||||||
echo "🧪 Testing API endpoints..."
|
echo "🧪 Testing API endpoints..."
|
||||||
|
|
||||||
# Get container IP for direct communication
|
# Get container IP for direct communication
|
||||||
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
|
CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ping-river-monitor-test)
|
||||||
echo "Using container IP: $CONTAINER_IP"
|
echo "Using container IP: $CONTAINER_IP"
|
||||||
|
|
||||||
endpoints=("health" "docs" "stations" "metrics")
|
endpoints=("health" "docs" "stations" "metrics")
|
||||||
for endpoint in "${endpoints[@]}"; do
|
for endpoint in "${endpoints[@]}"; do
|
||||||
echo "Testing /$endpoint..."
|
echo "Testing /$endpoint..."
|
||||||
|
|
||||||
# Use container IP if available, otherwise fallback to localhost
|
# Try multiple connection methods for reliability
|
||||||
if [ -n "$CONTAINER_IP" ]; then
|
response=""
|
||||||
response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/$endpoint)
|
|
||||||
else
|
# Try docker exec first (most reliable in containerized CI)
|
||||||
response=$(curl -s --max-time 10 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/$endpoint)
|
response=$(docker exec ping-river-monitor-test curl -s --max-time 5 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8000/$endpoint 2>/dev/null || echo "EXEC_FAILED")
|
||||||
|
|
||||||
|
# Fallback to container IP if exec fails
|
||||||
|
if [[ "$response" == "EXEC_FAILED" ]] && [ -n "$CONTAINER_IP" ]; then
|
||||||
|
response=$(curl -s --max-time 5 --connect-timeout 3 -w "HTTP_CODE:%{http_code}" http://$CONTAINER_IP:8000/$endpoint 2>/dev/null || echo "IP_FAILED")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Final fallback to host networking
|
||||||
|
if [[ "$response" == "IP_FAILED" ]] || [[ "$response" == "EXEC_FAILED" ]]; then
|
||||||
|
response=$(curl -s --max-time 5 --connect-timeout 3 -w "HTTP_CODE:%{http_code}" http://127.0.0.1:8080/$endpoint 2>/dev/null || echo "ALL_FAILED")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
http_code=$(echo "$response" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
||||||
|
Reference in New Issue
Block a user