infrastructure/production/django/entrypoint
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
postgres_ready() {
python << END
import sys
import psycopg2
with open("${POSTGRES_DB_FILE}") as file:
POSTGRES_DB = file.read().strip()
with open("${POSTGRES_USER_FILE}") as file:
POSTGRES_USER = file.read().strip()
with open("${POSTGRES_PASSWORD_FILE}") as file:
POSTGRES_PASSWORD = file.read().strip()
try:
psycopg2.connect(
dbname=POSTGRES_DB,
user=POSTGRES_USER,
password=POSTGRES_PASSWORD,
host="${POSTGRES_HOST}",
port="${POSTGRES_PORT}",
)
except psycopg2.OperationalError:
sys.exit(-1)
sys.exit(0)
END
}
until postgres_ready; do
>&2 echo 'Waiting for PostgreSQL to become available...'
sleep 1
done
>&2 echo 'PostgreSQL is available'
exec "$@"