-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replacing django entrypoint to check whether the database exists
- Loading branch information
Showing
7 changed files
with
97 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
|
||
|
||
# N.B. If only .env files supported variable expansion... | ||
export CELERY_BROKER_URL="redis://${REDIS_HOST}:${REDIS_PORT}/0" | ||
|
||
|
||
if [ -z "${POSTGRES_USER}" ]; then | ||
base_postgres_image_default_user='postgres' | ||
export POSTGRES_USER="${base_postgres_image_default_user}" | ||
fi | ||
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" | ||
|
||
python << END | ||
import sys | ||
import time | ||
import psycopg | ||
suggest_unrecoverable_after = 30 | ||
start = time.time() | ||
while True: | ||
try: | ||
psycopg.connect( | ||
dbname="${POSTGRES_DB}", | ||
user="${POSTGRES_USER}", | ||
password="${POSTGRES_PASSWORD}", | ||
host="${POSTGRES_HOST}", | ||
port="${POSTGRES_PORT}", | ||
) | ||
break | ||
except psycopg.OperationalError as error: | ||
sys.stderr.write("Waiting for PostgreSQL to become available...\n") | ||
if time.time() - start > suggest_unrecoverable_after: | ||
sys.stderr.write(" This is taking longer than expected. The following exception may be indicative of an unrecoverable error: '{}'\n".format(error)) | ||
time.sleep(1) | ||
END | ||
|
||
>&2 echo 'PostgreSQL is available' | ||
|
||
exec "$@" |
Oops, something went wrong.