-
Notifications
You must be signed in to change notification settings - Fork 112
/
docker-entrypoint.sh
executable file
·63 lines (53 loc) · 2.2 KB
/
docker-entrypoint.sh
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
#!/bin/sh
set -e
if [ -f '.env' ]; then
. '.env'
fi
echo "Using $(python3 --version 2>&1) located at $(which python3)"
# Do first-time set up of the database if necessary
if [ ! -z "$RUN_MIGRATIONS" ]; then
# Wait for the database to be ready for initialization tasks
until pg_isready --host="${PGHOST:-localhost}" --port="${PGPORT:-5432}"
do
echo "Waiting for postgres at: ${PGHOST:-localhost}:${PGPORT:-5432}"
sleep 1;
done
# Check the DB if it needs refresh or migrations (initial-data.sh)
if ! psql "postgres://${PGUSER:-cfpb}:${PGPASSWORD:-cfpb}@${PGHOST:-localhost}:${PGPORT:-5432}/${PGDATABASE:-cfgov}" -c 'SELECT COUNT(*) FROM auth_user' >/dev/null 2>&1 || [ ! -z $FORCE_DB_REBUILD ]; then
echo "Doing first-time database and search index setup..."
if [ -n "$CFGOV_PROD_DB_LOCATION" ] || [ -n "$DB_DUMP_FILE" ] || [ -n "$DB_DUMP_URL" ]; then
echo "Running refresh-data.sh... $DB_DUMP_FILE"
./refresh-data.sh "$DB_DUMP_FILE"
echo "Create the cache table..."
./cfgov/manage.py createcachetable
# refresh-data.sh runs migrations and rebuilds index,
# unset vars to prevent further action
unset RUN_MIGRATIONS
unset REBUILD_INDEX
else
# Detected the database is empty, or force rebuild was requested,
# but we have no valid data sources to load data.
echo "WARNING: Database rebuild request detected, but missing CFGOV_PROD_DB_LOCATION/DB_DUMP_FILE variable (one or the other is needed). Unable to load data!!"
fi
else
echo "Data detected, FORCE_DB_REBUILD not requested. Skipping data load!"
fi
# Check if we still need to run migrations, if so, run them
if [ ! -z $RUN_MIGRATIONS ]; then
echo "Running initial-data.sh (migrations)..."
./initial-data.sh
fi
fi
# Check if we need to rebuild index
if [ ! -z $REBUILD_INDEX ]; then
echo "Rebuilding Search Indexes..."
django-admin opensearch index --force rebuild
django-admin opensearch document --force --refresh index
fi
# Do first-time build of the front-end if necessary
if [ ! -d "node_modules" ] && [ ! "$(ls cfgov/static_built)" ]; then
echo "Running ./frontend.sh for the first time..."
./frontend.sh
fi
# Execute the Docker CMD
exec "$@"