aurweb/docker/scripts/run-fastapi.sh
Kevin Morris 42aa12d075
fix(docker): unrestrict --forwarded-allow-ips on (uvi|hyper)corn
Signed-off-by: Kevin Morris <kevr@0cost.org>
2022-01-15 21:04:47 -08:00

42 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
# By default, set FASTAPI_WORKERS to 2. In production, this should
# be configured by the deployer.
if [ -z ${FASTAPI_WORKERS+x} ]; then
FASTAPI_WORKERS=2
fi
export FASTAPI_BACKEND="$1"
echo "FASTAPI_BACKEND: $FASTAPI_BACKEND"
echo "FASTAPI_WORKERS: $FASTAPI_WORKERS"
# Perform migrations.
alembic upgrade head
if [ "$1" == "uvicorn" ] || [ "$1" == "" ]; then
exec uvicorn --reload \
--log-config /docker/logging.conf \
--host "0.0.0.0" \
--port 8000 \
--forwarded-allow-ips "*" \
aurweb.asgi:app
elif [ "$1" == "gunicorn" ]; then
exec gunicorn \
--log-config /docker/logging.conf \
--bind "0.0.0.0:8000" \
--proxy-protocol \
--forwarded-allow-ips "*" \
-w $FASTAPI_WORKERS \
-k uvicorn.workers.UvicornWorker \
aurweb.asgi:app
elif [ "$1" == "hypercorn" ]; then
exec hypercorn --reload \
--log-config /docker/logging.conf \
-b "0.0.0.0:8000" \
--forwarded-allow-ips "*" \
aurweb.asgi:app
else
echo "Error: Invalid \$FASTAPI_BACKEND supplied."
echo "Valid backends: 'uvicorn', 'gunicorn', 'hypercorn'."
exit 1
fi