2018-02-22 15:01:05 +00:00
|
|
|
#!/bin/sh
|
2017-09-05 11:39:20 +00:00
|
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
set -o pipefail
|
2018-03-08 13:59:41 +00:00
|
|
|
set -o nounset
|
2017-09-05 11:39:20 +00:00
|
|
|
|
|
|
|
|
|
2018-04-04 10:42:01 +00:00
|
|
|
# N.B. If only .env files supported variable expansion...
|
|
|
|
|
export CELERY_BROKER_URL="${REDIS_URL}"
|
|
|
|
|
|
2018-03-08 13:59:41 +00:00
|
|
|
if [ -z "${POSTGRES_USER}" ]; then
|
2018-04-04 08:43:39 +00:00
|
|
|
base_postgres_image_default_user='postgres'
|
|
|
|
|
export POSTGRES_USER="${base_postgres_image_default_user}"
|
2016-03-08 09:12:55 +00:00
|
|
|
fi
|
2018-05-09 09:58:37 +00:00
|
|
|
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
|
2016-08-16 19:20:41 +00:00
|
|
|
|
2018-02-22 15:01:05 +00:00
|
|
|
postgres_ready() {
|
2016-08-16 19:20:41 +00:00
|
|
|
python << END
|
|
|
|
|
import sys
|
2018-03-08 13:59:41 +00:00
|
|
|
|
2016-08-16 19:20:41 +00:00
|
|
|
import psycopg2
|
2018-03-08 13:59:41 +00:00
|
|
|
|
2016-08-16 19:20:41 +00:00
|
|
|
try:
|
2018-03-08 13:59:41 +00:00
|
|
|
psycopg2.connect(
|
|
|
|
|
dbname="${POSTGRES_DB}",
|
|
|
|
|
user="${POSTGRES_USER}",
|
|
|
|
|
password="${POSTGRES_PASSWORD}",
|
2018-05-09 09:58:37 +00:00
|
|
|
host="${POSTGRES_HOST}",
|
|
|
|
|
port="${POSTGRES_PORT}",
|
2018-03-08 13:59:41 +00:00
|
|
|
)
|
2016-08-16 19:20:41 +00:00
|
|
|
except psycopg2.OperationalError:
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
sys.exit(0)
|
2018-03-08 13:59:41 +00:00
|
|
|
|
2016-08-16 19:20:41 +00:00
|
|
|
END
|
|
|
|
|
}
|
|
|
|
|
until postgres_ready; do
|
2018-05-21 12:03:37 +00:00
|
|
|
>&2 echo 'Waiting for PostgreSQL to become available...'
|
2016-08-16 19:20:41 +00:00
|
|
|
sleep 1
|
|
|
|
|
done
|
2018-05-21 12:03:37 +00:00
|
|
|
>&2 echo 'PostgreSQL is available'
|
2018-03-08 13:59:41 +00:00
|
|
|
|
2018-05-21 11:59:20 +00:00
|
|
|
exec "$@"
|