-
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.
reverting back to orig entrypoint script
- Loading branch information
Showing
3 changed files
with
82 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/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 | ||
def database_exists(conn_params, dbname): | ||
with psycopg.connect(**conn_params) as conn: | ||
with conn.cursor() as cur: | ||
cur.execute("SELECT 1 FROM pg_database WHERE datname = %s", (dbname,)) | ||
return cur.fetchone() is not None | ||
def create_database(conn_params, dbname): | ||
with psycopg.connect(**conn_params) as conn: | ||
conn.autocommit = True | ||
with conn.cursor() as cur: | ||
cur.execute(f"CREATE DATABASE \"{dbname}\"") | ||
conn_params = { | ||
"dbname": "postgres", # connect to the default database to check/create | ||
"user": "${POSTGRES_USER}", | ||
"password": "${POSTGRES_PASSWORD}", | ||
"host": "${POSTGRES_HOST}", | ||
"port": "${POSTGRES_PORT}" | ||
} | ||
dbname = "${POSTGRES_DB}" | ||
if not database_exists(conn_params, dbname): | ||
print("Database does not exist. Creating database: {}".format(dbname)) | ||
create_database(conn_params, dbname) | ||
else: | ||
print("Database {} already exists.".format(dbname)) | ||
# Now connect to the target database | ||
conn_params["dbname"] = dbname | ||
with psycopg.connect(**conn_params) as conn: | ||
print('Connected to the database successfully') | ||
END | ||
|
||
>&2 echo 'PostgreSQL is available' | ||
|
||
exec "$@" |
This file was deleted.
Oops, something went wrong.