-
Notifications
You must be signed in to change notification settings - Fork 4
/
docker-entrypoint.sh
executable file
·80 lines (71 loc) · 2.14 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
### Uvicorn common settings ###
UVICORN_PORT=${UVICORN_PORT:-"5000"}
UVICORN_SECURITY_GATEWAY_PORT=${UVICORN_SECURITY_GATEWAY_PORT:-"5001"}
UVICORN_RELOAD=${UVICORN_RELOAD:-"false"}
UVICORN_LOG_LEVEL=${UVICORN_LOG_LEVEL:-"info"}
### Celery common settings ###
CELERY_LOG_LEVEL=${CELERY_LOG_LEVEL:-"info"}
CELERY_MIN_WORKERS=${CELERY_MIN_WORKERS:-"1"}
CELERY_MAX_WORKERS=${CELERY_MAX_WORKERS:-"2"}
if [ $UVICORN_RELOAD == "true" ]; then
UVICORN_START_ARGS="${UVICORN_START_ARGS} --reload"
else
### Not valid with --reload
export UVICORN_WORKERS=${UVICORN_WORKERS:-"1"}
fi
function export_overriden_env() {
# Override env variables with .env.override file
# It will allow to have different env variables for local development and production
FILE=".env.override"
if [[ -f "$FILE" ]]; then
export $(grep -v '^#' $FILE | xargs -d '\n')
else
echo "Override env $FILE not found"
fi
}
function run_migrations() {
echo "Running migration"
alembic -c /opt/app/secbot/alembic.ini upgrade head
}
function run_app() {
echo "Starting security bot app"
export_overriden_env
run_migrations
uvicorn app.main:app --host 0.0.0.0 --port ${UVICORN_PORT} --log-level ${UVICORN_LOG_LEVEL} ${UVICORN_START_ARGS}
}
function run_security_gateway() {
echo "Starting security bot security gateway"
export_overriden_env
uvicorn app.main:security_gateway_app --host 0.0.0.0 --port ${UVICORN_SECURITY_GATEWAY_PORT} --log-level ${UVICORN_LOG_LEVEL} ${UVICORN_START_ARGS}
}
function run_celery() {
echo "Starting security bot celery worker"
export_overriden_env
celery -A app.main:celery_app worker --autoscale=${CELERY_MAX_WORKERS},${CELERY_MIN_WORKERS} --loglevel ${CELERY_LOG_LEVEL}
}
case $1 in
"shell")
bash
;;
"start_app")
run_app
;;
"start_security_gateway")
run_security_gateway
;;
"start_celery")
run_celery
;;
"migrate")
run_migrations
;;
*)
echo "Please use of next parameters to start:"
echo " help: help information"
echo " shell: run shell"
echo " migrate: run migrations"
echo " start_app: run app"
echo " start_celery: run celery"
;;
esac