-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapi.main.sh
executable file
·47 lines (40 loc) · 992 Bytes
/
api.main.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
#!/bin/bash
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd "$script_dir"
set -e
export PYTHONUNBUFFERED=true
export PYTHONDONTWRITEBYTECODE=true
export PYTHONPATH=.
if [ "${DUO_USE_VENV:-true}" = true ] && [ -d venv/api/ ]
then
export PATH=$(readlink -e venv/api/bin):$PATH
fi
if [ "${DUO_USE_VENV:-true}" = true ] && [ ! -d venv/api/ ]
then
python3 -m venv venv/api/
export PATH=$(readlink -e venv/api/bin):$PATH
python3 -m pip install -r api.requirements.txt
fi
if [ -z "$PORT" ]
then
PORT=5000
fi
if [ "$DUO_ENV" = "prod" ]
then
python3 database/initapi.py
exec gunicorn \
--workers "${DUO_WORKERS:-4}" \
--bind "0.0.0.0:$PORT" \
--timeout 0 \
service.api:app
elif [ "$DUO_ENV" = "dev" ]
then
python3 database/initapi.py
exec flask \
--app service.api:app \
--debug run \
--host 0.0.0.0 \
--port "$PORT"
else
echo "The environment variable DUO_ENV must be set and have the value 'dev' or 'prod'"
fi