Update test.sh
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Failing after 16s
Build-Test-Publish / build (linux/arm64) (push) Failing after 17s

This commit is contained in:
Your Name
2025-08-24 11:37:40 +12:00
parent 35aade44f4
commit 7b60c21f33

68
test.sh
View File

@@ -221,37 +221,38 @@ function start_test_server() {
while [ $attempt -lt $max_attempts ]; do
# Try multiple connection methods for different environments
local http_code="000"
local test_urls=""
local container_code="000"
local host_code="000"
local local_code="000"
# Try direct container IP on port 80 (might work in some Docker setups)
if [ "${CONTAINER_IP}" != "localhost" ]; then
http_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${CONTAINER_IP}:80/" 2>/dev/null || echo "000")
test_urls="${CONTAINER_IP}:80"
fi
# If that didn't work, try host IP with mapped port (Docker-in-Docker)
if [ "$http_code" = "000" ] || [ "$http_code" = "" ]; then
if [ -n "${HOST_IP}" ]; then
local host_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null || echo "000")
if [ "$host_code" != "000" ] && [ "$host_code" != "" ]; then
http_code="$host_code"
fi
test_urls="${test_urls}, host:${HOST_IP}:${TEST_PORT}"
container_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${CONTAINER_IP}:80/" 2>/dev/null || echo "000")
if [ "$container_code" != "000" ] && [ "$container_code" != "" ]; then
http_code="$container_code"
fi
fi
# If that didn't work, try localhost with mapped port (local Docker)
if [ "$http_code" = "000" ] || [ "$http_code" = "" ]; then
local local_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
if [ "$local_code" != "000" ] && [ "$local_code" != "" ]; then
http_code="$local_code"
# Try host IP with mapped port (Docker-in-Docker)
if [ -n "${HOST_IP}" ]; then
host_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null || echo "000")
if [ "$host_code" != "000" ] && [ "$host_code" != "" ]; then
http_code="$host_code"
fi
test_urls="${test_urls}, localhost:${TEST_PORT}"
fi
# Debug: Show HTTP code and container status on first few attempts
# Try localhost with mapped port (local Docker)
local_code=$(curl -s --max-time 2 -o /dev/null -w "%{http_code}" "http://localhost:${TEST_PORT}/" 2>/dev/null || echo "000")
if [ "$local_code" != "000" ] && [ "$local_code" != "" ]; then
http_code="$local_code"
fi
# Debug: Show HTTP codes from all attempts on first few tries
if [ $attempt -lt 3 ]; then
log_info "Health check attempt $((attempt + 1)): HTTP code ${http_code} (tried: ${test_urls})"
log_info "Health check attempt $((attempt + 1)):"
log_info " Container IP (${CONTAINER_IP}:80): ${container_code}"
log_info " Host IP (${HOST_IP}:${TEST_PORT}): ${host_code}"
log_info " Localhost (localhost:${TEST_PORT}): ${local_code}"
# Check if container is actually running
if docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
log_info "Container is running, checking logs..."
@@ -261,19 +262,18 @@ function start_test_server() {
fi
fi
if [ "$http_code" = "200" ] || [ "$http_code" = "204" ] || [ "$http_code" = "404" ]; then
log_info "Server is ready! (HTTP ${http_code})"
# Determine which connection method worked
if curl -s --max-time 1 -o /dev/null "http://${CONTAINER_IP}:80/" 2>/dev/null; then
export SOS_TEST_HOST="${CONTAINER_IP}:80"
log_info "Using container IP: ${SOS_TEST_HOST}"
elif [ -n "${HOST_IP}" ] && curl -s --max-time 1 -o /dev/null "http://${HOST_IP}:${TEST_PORT}/" 2>/dev/null; then
export SOS_TEST_HOST="${HOST_IP}:${TEST_PORT}"
log_info "Using host IP: ${SOS_TEST_HOST}"
else
export SOS_TEST_HOST="localhost:${TEST_PORT}"
log_info "Using localhost: ${SOS_TEST_HOST}"
fi
# Check if any method succeeded
if [ "$container_code" = "200" ] || [ "$container_code" = "204" ] || [ "$container_code" = "404" ]; then
export SOS_TEST_HOST="${CONTAINER_IP}:80"
log_info "Server is ready! Using container IP: ${SOS_TEST_HOST}"
return 0
elif [ "$host_code" = "200" ] || [ "$host_code" = "204" ] || [ "$host_code" = "404" ]; then
export SOS_TEST_HOST="${HOST_IP}:${TEST_PORT}"
log_info "Server is ready! Using host IP: ${SOS_TEST_HOST}"
return 0
elif [ "$local_code" = "200" ] || [ "$local_code" = "204" ] || [ "$local_code" = "404" ]; then
export SOS_TEST_HOST="localhost:${TEST_PORT}"
log_info "Server is ready! Using localhost: ${SOS_TEST_HOST}"
return 0
fi