-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint
71 lines (58 loc) · 2.08 KB
/
entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -o errexit
set -o pipefail
# No postgres user, so just use the default.
if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
fi
# This call does not seem to be effective. Hence the hardcoded version of this in the env variables.
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
# Loop until postgres is ready
postgres_ready() {
python3 << END
import sys
import psycopg2
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 'entrypoint: Waiting for PostgreSQL to become available...'
sleep 1
done
>&2 echo 'entrypoint: PostgreSQL is available'
echo "$MIGRATE"
if [[ ($MIGRATE) && ("$MIGRATE" = "True") ]]; then
python3 manage.py makemigrations --no-input
python3 manage.py migrate --no-input --fake-initial
echo "entrypoint: Migrations finished"
python3 manage.py collectstatic --noinput
echo "entrypoint: Static files collected"
fi
if [[ ($INIT_SUPERUSER) && ("$INIT_SUPERUSER" = "True") ]]; then
echo "entrypoint: Creating superuser"
python3 manage.py initialise_superuser --user "$DJANGO_ADMIN" --email "$DJANGO_ADMIN_EMAIL" --password "$DJANGO_ADMIN_PASSWORD"
fi
nginx
# Switching the WSGI host to Waitress, which seems faster, and more robust than Gunicorn for long running jobs when
# sitting behind Nginx.
# Switching the WSGI host to Waitress, which seems faster, and more robust than Gunicorn for long running jobs when
# sitting behind Nginx.
if [[ (-z "$LOADER") || ("$LOADER" = "False")]]; then
if [[ ($WAITRESS) && ("$WAITRESS" = "True") ]]; then
echo "Bringing up waitress on port 5000 as wsgi host"
waitress-serve --threads=16 --listen=127.0.0.1:5000 search_service.wsgi:application
else
python3 /app/manage.py runserver 5000
fi
fi