/ docker-entrypoint.sh
docker-entrypoint.sh
1 #!/bin/bash 2 set -e 3 4 function wait_for_broker { 5 set +e 6 for try in {1..60} ; do 7 python -c "from kombu import Connection; x=Connection('$CELERY_BROKER_URL', timeout=1); x.connect()" && break 8 echo "Waiting for celery broker to respond..." 9 sleep 1 10 done 11 } 12 13 function wait_for_database { 14 set +e 15 for try in {1..60} ; do 16 python -c "from django.db import connection; connection.connect()" && break 17 echo "Waiting for database to respond..." 18 sleep 1 19 done 20 } 21 22 function wait_for_migrations { 23 set +e 24 for try in {1..60} ; do 25 # Kind of ugly but not sure if there's another way to determine if migrations haven't run. 26 # showmigrations -p returns a checkbox list of migrations, empty checkboxes mean they haven't been run 27 python manage.py showmigrations -p | grep "\[ \]" &> /dev/null || break 28 echo "Waiting for database migrations to be run..." 29 sleep 1 30 done 31 } 32 33 34 wait_for_broker 35 wait_for_database 36 37 if [ -z "$SKIP_INIT" ]; then 38 /code/bin/build-app 39 fi 40 41 if [ -n "$WAIT_FOR_MIGRATIONS" ]; then 42 wait_for_migrations 43 fi 44 45 exec "$@"