Skip to content

Commit

Permalink
abort the service wait after a timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Mar 31, 2024
1 parent 328cea8 commit 318e448
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,29 @@ docker compose up --build --detach

# wait for the services to exit.
function wait-for-service {
echo "Waiting for the $1 service to complete..."
local service="$1"
local timeout_s="${2:-300}"
local start_time_s=$(date +%s)
echo "Waiting for the $service service to exit..."
while true; do
result="$(docker compose ps --status exited --format json $1)"
local result="$(docker compose ps --no-trunc --all --status exited --format json "$service")"
if [ -n "$result" ] && [ "$result" != 'null' ]; then
exit_code="$(jq -r '.ExitCode' <<<"$result")"
local exit_code="$(jq -r '.ExitCode' <<<"$result")"
break
fi
sleep 3
local elapsed_time_s=$(( $(date +%s) - $start_time_s ))
if [ $elapsed_time_s -ge $timeout_s ]; then
echo "ERROR: Timeout reached ($timeout_s seconds)."
docker version 2>&1 \
| perl -pe 's/^/DEBUG: docker version: /'
docker compose version 2>&1 \
| perl -pe 's/^/DEBUG: docker compose version: /'
local exit_code=1
break
fi
done
docker compose logs $1
docker compose logs "$service"
return $exit_code
}
wait-for-service init
Expand Down

0 comments on commit 318e448

Please sign in to comment.