Skip to content

Commit

Permalink
Wait for database to be ready before running migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
negasora committed Jan 5, 2023
1 parent 6e89a75 commit 8457775
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/bin/bash


health_check () {
pipenv run ./manage.py check --database default;
return $?;
}

HEALTH_CHECK_INTERVAL=5;
HEALTH_CHECK_ATTEMPTS=0;
HEALTH_CHECK_ATTEMPT_LIMIT=5;
while ! health_check; do
HEALTH_CHECK_ATTEMPTS=$((HEALTH_CHECK_ATTEMPTS + 1));
echo "Health check attempt ${HEALTH_CHECK_ATTEMPTS} failed, retrying in ${HEALTH_CHECK_INTERVAL} seconds...";
if [ "$HEALTH_CHECK_ATTEMPTS" -ge "$HEALTH_CHECK_ATTEMPT_LIMIT" ]; then
echo "Exceeded number of health check attempts, exiting";
exit 1;
fi;
sleep $HEALTH_CHECK_INTERVAL;
done

set -e

pipenv run ./manage.py migrate -v 0
Expand Down

0 comments on commit 8457775

Please sign in to comment.