-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.sh
executable file
Β·93 lines (79 loc) Β· 3.06 KB
/
start.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Case insenstive match
shopt -s nocaseglob
if [ -z "${ENV_FILE}" ]; then
ENV_FILE="/secrets/env.json"
fi
echo 'Checking for environment file "'${ENV_FILE}'"...'
if [ ! -f "${ENV_FILE}" ]; then
echo 'Error: Environment file "'${ENV_FILE}'" not found!'
exit 1
fi
echo 'Using environment file "'${ENV_FILE}'"...'
#echo $DJANGO_SETTINGS_MODULE
#
#if [ -z "${GUNICORN_WORKERS}" ]; then
# GUNICORN_WORKERS=4
#fi
#
#if [ -z "${GUNICORN_PORT}" ]; then
# GUNICORN_PORT=5000
#fi
#
#if [ -z "${GUNICORN_TIMEOUT}" ]; then
# GUNICORN_TIMEOUT=120
#fi
#
#if [ "${GUNICORN_RELOAD}" ]; then
# GUNICORN_RELOAD="--reload"
#else
# GUNICORN_RELOAD=""
#fi
#DOMAIN_JQ='.ALLOWED_HOSTS | . - ["127.0.0.1", "localhost", ".ngrok.io"] | if . | length == 0 then "localhost" else .[0] end'
#
#if [ -z "${ENV_JSON}" ]; then
# MYSQL_HOST=$(jq -r -c ".MYSQL_HOST | values" ${ENV_FILE})
# MYSQL_PORT=$(jq -r -c ".MYSQL_PORT | values" ${ENV_FILE})
# IS_CRON_POD=$(jq -r -c ".IS_CRON_POD | values" ${ENV_FILE})
# PTVSD_ENABLE=$(jq -r -c ".PTVSD_ENABLE | values" ${ENV_FILE})
# CRONTAB_SCHEDULE=$(jq -r -c ".CRONTAB_SCHEDULE | values" ${ENV_FILE})
# RUN_AT_TIMES=$(jq -r -c ".RUN_AT_TIMES | values" ${ENV_FILE})
# DOMAIN=$(jq -r -c "${DOMAIN_JQ} | values" ${ENV_FILE})
#else
# MYSQL_HOST=$(echo "${ENV_JSON}" | jq -r -c ".MYSQL_HOST | values")
# MYSQL_PORT=$(echo "${ENV_JSON}" | jq -r -c ".MYSQL_PORT | values")
# IS_CRON_POD=$(echo "${ENV_JSON}" | jq -r -c ".IS_CRON_POD | values")
# PTVSD_ENABLE=$(echo "${ENV_JSON}" | jq -r -c ".PTVSD_ENABLE | values")
# CRONTAB_SCHEDULE=$(echo "${ENV_JSON}" | jq -r -c ".CRONTAB_SCHEDULE | values")
# RUN_AT_TIMES=$(echo "${ENV_JSON}" | jq -r -c ".RUN_AT_TIMES | values")
# DOMAIN=$(echo "${ENV_JSON}" | jq -r -c "${DOMAIN_JQ} | values")
#fi
DB_HOST=$(jq -r -c ".DB_HOST | values" ${ENV_FILE})
DB_PORT=$(jq -r -c ".DB_PORT | values" ${ENV_FILE})
DB_TUNNEL_PORT=$(jq -r -c ".DB_TUNNEL_PORT | values" ${ENV_FILE})
echo 'Checking for DB readiness...'
while ! nc -z ${DB_HOST} ${DB_PORT}; do
echo 'Waiting for DB...'
sleep 1 # in seconds
done
echo 'DB is ready.'
echo 'Applying Django migrations...'
python manage.py migrate
echo 'Django migrations complete.'
if [ -n "${DB_TUNNEL_PORT}" ]; then
echo "Opening tunnel on port (${DB_TUNNEL_PORT}) to DB server at (${DB_HOST}:${DB_PORT})..."
socat "TCP-LISTEN:${DB_TUNNEL_PORT},fork" "TCP:${DB_HOST}:${DB_PORT}" &
fi
echo 'Setting Git info variables...'
export GIT_REPO="$(git config --local remote.origin.url)"
export GIT_COMMIT="$(git rev-parse HEAD)"
export GIT_BRANCH="$(git name-rev $GIT_COMMIT --name-only)"
#echo "Setting domain of default site record"
## The value for LOCALHOST_PORT is set in docker-compose.yml
#if [ ${DOMAIN} == "localhost" ]; then
# python manage.py site --domain="${DOMAIN}:${LOCALHOST_PORT}" --name="${DOMAIN}"
#else
# python manage.py site --domain="${DOMAIN}" --name="${DOMAIN}"
#fi
# TODO: DO NOT USE THIS SERVER IN A PRODUCTION SETTING (https://docs.djangoproject.com/en/3.1/ref/django-admin/#runserver)
python manage.py runserver 0.0.0.0:8000