-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.bash
executable file
·98 lines (91 loc) · 2.44 KB
/
entrypoint.bash
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
94
95
96
97
98
#!/bin/bash
ACTION="${1}"
function help() {
echo -e "Entrypoint for VerbaCap\nArguments:\n"
echo -e "\tcreateadminuser\t\tCreate superuser account"
echo -e "\tcelery\t\tStart Celery with Beat included"
echo -e "\tdebugrun\tStart the app in debug mode"
echo -e "\tpyshell\t\tStart an interative Django shell"
echo -e "\trun\t\tStart the app"
echo -e "\tshell\t\tInteractive Shell /bin/bash with all vars loaded"
}
function prepare() {
echo "-- Collect Static"
python3 manage.py collectstatic --no-input --clear
echo "-- Migrate DB"
python3 manage.py migrate
echo "-- Generate compress files"
python3 manage.py compress
echo "-- Load Fixtures"
python3 manage.py loaddata "fixtures/main.json"
}
# Precheck validation
if [[ ! -v DATABASE_URL ]]; then
echo "CRIICAL Please set DATABASE_URL var!"
exit 1
fi
if [[ ! -v DJANGO_SECRET_KEY ]]; then
echo "CRIICAL Please set DJANGO_SECRET_KEY var!"
exit 1
fi
if [[ ! -v CELERY_BROKER_URL ]]; then
echo "CRIICAL Please set CELERY_BROKER_URL var!"
exit 1
fi
if [[ ! -v PERSIST_AUDIO_ROOTDIR ]]; then
echo "CRIICAL Please set PERSIST_AUDIO_ROOTDIR var!"
exit 1
fi
echo "Waiting for DB ready"
DB_ADDR=$(echo "$DATABASE_URL" |cut -d'@' -f2|cut -d':' -f1)
while ! nc -z "${DB_ADDR}" 5432; do
echo "DB '${DB_ADDR}' not ready..."
sleep 1
done
echo "Database Ready."
# Load virtualenv
cd "${HOME}" || exit
# shellcheck disable=SC1091
. "${HOME}/venv/bin/activate"
# Actions
case "${ACTION}" in
debugrun)
echo "Staring App with debug"
export DJANGO_DEBUG="True"
prepare
echo "--------"
python3 manage.py runserver 8080
;;
celery)
echo "Starting Celery"
echo "--------"
# Waiting for first start for webapp
sleep 60
celery --app config.celery_app worker --loglevel="info" --concurrency 1 --beat
;;
createadminuser)
echo "Creating ADMIN user"
echo "--------"
python3 manage.py createsuperuser
;;
pyshell)
echo "Starting Django interactive shell"
echo "--------"
python3 manage.py shell
;;
run)
echo "Starting App"
prepare
echo "--------"
nginx
gunicorn config.wsgi --bind 0.0.0.0:8000
;;
shell)
echo "Staring Interactive Bash shell"
echo "--------"
/bin/bash
;;
*)
help
;;
esac