From 77a800293f8401f5d313ba78df9caf20e540bf00 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 30 May 2025 20:32:01 +1200 Subject: [PATCH] :-'Generic Commit' --- .test-docker/compose.yaml | 3 ++- test-docker.sh | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.test-docker/compose.yaml b/.test-docker/compose.yaml index 4c46d67..57e2bfb 100644 --- a/.test-docker/compose.yaml +++ b/.test-docker/compose.yaml @@ -1,6 +1,7 @@ services: sos: image: gitea.jde.nz/public/simple-object-storage:test + container_name: sos-test ports: - 7703:80 volumes: @@ -9,7 +10,7 @@ services: - SOS_CONFIG=/data/sos_config.json restart: no healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:7703/status"] + test: ["CMD", "wget", "-qO-", "http://0.0.0.0/status"] interval: 1s timeout: 1s retries: 3 diff --git a/test-docker.sh b/test-docker.sh index a458075..ec0f23b 100755 --- a/test-docker.sh +++ b/test-docker.sh @@ -15,6 +15,28 @@ function title() { echo "----------------------------------------" } + +function wait_for_container { + container_id="$1" + container_name="$(docker inspect "${container_id}" --format '{{ .Name }}')" + echo "Waiting for container: ${container_name} [${container_id}]" + waiting_done="false" + while [[ "${waiting_done}" != "true" ]]; do + container_state="$(docker inspect "${container_id}" --format '{{ .State.Status }}')" + if [[ "${container_state}" == "running" ]]; then + health_status="$(docker inspect "${container_id}" --format '{{ .State.Health.Status }}')" + echo "${container_name}: container_state=${container_state}, health_status=${health_status}" + if [[ ${health_status} == "healthy" ]]; then + waiting_done="true" + fi + else + echo "${container_name}: container_state=${container_state}" + waiting_done="true" + fi + sleep 1; + done; +} + #------------------------------------------------------------------------------------------------ # build the executable title "Building amd64 executable" @@ -54,6 +76,8 @@ docker compose -f "${COMPOSE_FILE}" rm -v docker compose -f "${COMPOSE_FILE}" up -d +# wait until healthy. +wait_for_container "sos-test" "${SCRIPT_DIR}/test.sh" "http://localhost:7703" RESULT=$?