-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint
76 lines (63 loc) · 2.5 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
72
73
74
75
76
#!/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 [[ ($LOAD) && ("$LOAD" = "True") ]]; then
echo "entrypoint: Deleting all Yasna data"
python3 manage.py delete_all_yasna_data
echo "entrypoint: Loading Yasna Object data from versioned fixtures"
python3 manage.py loaddata ./yasna/data/yasna_objects_fixtures.json
echo "entrypoint: Loading YasnaObjectImage avro from versioned fixtures"
python3 manage.py load_avro_frame_data --framef=./yasna/data/uniqueframes_2decimalplaces.avro --normf=./yasna/data/normalisedwithframes_2decimalplaces.avro
echo "entrypoint: Loading eaf data from versioned fixtures"
python3 manage.py loaddata ./yasna/data/eaf_fixtures.json
fi
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 --url-scheme=https --trusted-proxy='*' --trusted-proxy-headers='x-forwarded-for x-forwarded-proto x-forwarded-port' --threads=16 --listen=127.0.0.1:5000 yasna_backend.wsgi:application
# python3 /app/manage.py waitress --port=5000 --threads=16
else
python3 /app/manage.py runserver 5000
fi
fi