Skip to content

Commit

Permalink
fix/gh-actions-setup-postgres: fixing script to be resilient to array…
Browse files Browse the repository at this point in the history
… or object docker compose output (#10512)
  • Loading branch information
patrickhuie19 authored Sep 6, 2023
1 parent 5aadc9c commit c40169c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/actions/setup-postgres/wait-for-healthy-postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
RETRIES=10

until [ $RETRIES -eq 0 ]; do
if docker compose ps postgres --status running --format json | jq >/dev/null -e 'if (.[0].Health == "healthy") then true else false end'; then
DOCKER_OUTPUT=$(docker compose ps postgres --status running --format json)
JSON_TYPE=$(echo "$DOCKER_OUTPUT" | jq -r 'type')

if [ "$JSON_TYPE" == "array" ]; then
HEALTH_STATUS=$(echo "$DOCKER_OUTPUT" | jq -r '.[0].Health')
elif [ "$JSON_TYPE" == "object" ]; then
HEALTH_STATUS=$(echo "$DOCKER_OUTPUT" | jq -r '.Health')
else
HEALTH_STATUS="Unknown JSON type: $JSON_TYPE"
fi

echo "postgres health status: $HEALTH_STATUS"
if [ "$HEALTH_STATUS" == "healthy" ]; then
exit 0
fi

echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
sleep 2
done

exit 1

0 comments on commit c40169c

Please sign in to comment.