mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(docker): add gunicorn support & production default
Supply FASTAPI_BACKEND=gunicorn and FASTAPI_WORKERS=<threads_num> to docker-compose up to use the gunicorn backend. This is defaulted in production to gunicorn, but FASTAPI_WORKERS should definitely be configured by any production deployment. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
28c4e9697b
commit
927f5e8567
5 changed files with 28 additions and 1 deletions
1
.env
1
.env
|
@ -1 +1,2 @@
|
||||||
FASTAPI_BACKEND="uvicorn"
|
FASTAPI_BACKEND="uvicorn"
|
||||||
|
FASTAPI_WORKERS=2
|
||||||
|
|
|
@ -21,6 +21,8 @@ services:
|
||||||
- cache:/cache
|
- cache:/cache
|
||||||
|
|
||||||
fastapi:
|
fastapi:
|
||||||
|
environment:
|
||||||
|
- FASTAPI_BACKEND="gunicorn"
|
||||||
volumes:
|
volumes:
|
||||||
- cache:/cache
|
- cache:/cache
|
||||||
|
|
||||||
|
|
|
@ -166,6 +166,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
- AUR_CONFIG=conf/config
|
- AUR_CONFIG=conf/config
|
||||||
- DB_HOST=mariadb
|
- DB_HOST=mariadb
|
||||||
|
- FASTAPI_WORKERS=${FASTAPI_WORKERS}
|
||||||
entrypoint: /docker/fastapi-entrypoint.sh
|
entrypoint: /docker/fastapi-entrypoint.sh
|
||||||
command: /docker/scripts/run-fastapi.sh "${FASTAPI_BACKEND}"
|
command: /docker/scripts/run-fastapi.sh "${FASTAPI_BACKEND}"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
|
|
|
@ -12,6 +12,15 @@ if [ -f /cache/production.key.pem ]; then
|
||||||
KEY=/cache/production.key.pem
|
KEY=/cache/production.key.pem
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# By default, set FASTAPI_WORKERS to 2. In production, this should
|
||||||
|
# be configured by the deployer.
|
||||||
|
if [ -z "$FASTAPI_WORKERS" ]; then
|
||||||
|
FASTAPI_WORKERS=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "FASTAPI_BACKEND: $FASTAPI_BACKEND"
|
||||||
|
echo "FASTAPI_WORKERS: $FASTAPI_WORKERS"
|
||||||
|
|
||||||
if [ "$1" == "uvicorn" ] || [ "$1" == "" ]; then
|
if [ "$1" == "uvicorn" ] || [ "$1" == "" ]; then
|
||||||
exec uvicorn --reload \
|
exec uvicorn --reload \
|
||||||
--ssl-certfile "$CERT" \
|
--ssl-certfile "$CERT" \
|
||||||
|
@ -20,11 +29,24 @@ if [ "$1" == "uvicorn" ] || [ "$1" == "" ]; then
|
||||||
--host "0.0.0.0" \
|
--host "0.0.0.0" \
|
||||||
--port 8000 \
|
--port 8000 \
|
||||||
aurweb.asgi:app
|
aurweb.asgi:app
|
||||||
else
|
elif [ "$1" == "gunicorn" ]; then
|
||||||
|
exec gunicorn \
|
||||||
|
--keyfile="$KEY" \
|
||||||
|
--certfile="$CERT" \
|
||||||
|
--log-config /docker/logging.conf \
|
||||||
|
--bind "0.0.0.0:8000" \
|
||||||
|
-w $FASTAPI_WORKERS \
|
||||||
|
-k uvicorn.workers.UvicornWorker \
|
||||||
|
aurweb.asgi:app
|
||||||
|
elif [ "$1" == "hypercorn" ]; then
|
||||||
exec hypercorn --reload \
|
exec hypercorn --reload \
|
||||||
--certfile "$CERT" \
|
--certfile "$CERT" \
|
||||||
--keyfile "$KEY" \
|
--keyfile "$KEY" \
|
||||||
--log-config /docker/logging.conf \
|
--log-config /docker/logging.conf \
|
||||||
-b "0.0.0.0:8000" \
|
-b "0.0.0.0:8000" \
|
||||||
aurweb.asgi:app
|
aurweb.asgi:app
|
||||||
|
else
|
||||||
|
echo "Error: Invalid \$FASTAPI_BACKEND supplied."
|
||||||
|
echo "Valid backends: 'uvicorn', 'gunicorn', 'hypercorn'."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -86,6 +86,7 @@ pytest-asyncio = { version = "0.15.1", python = "^3.9" }
|
||||||
pytest-cov = { version = "2.12.1", python = "^3.9" }
|
pytest-cov = { version = "2.12.1", python = "^3.9" }
|
||||||
pytest-tap = { version = "3.2", python = "^3.9" }
|
pytest-tap = { version = "3.2", python = "^3.9" }
|
||||||
uvicorn = { version = "0.15.0", python = "^3.9" }
|
uvicorn = { version = "0.15.0", python = "^3.9" }
|
||||||
|
gunicorn = { version = "20.1.0", python = "^3.9" }
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
aurweb-git-auth = "aurweb.git.auth:main"
|
aurweb-git-auth = "aurweb.git.auth:main"
|
||||||
|
|
Loading…
Add table
Reference in a new issue