feat: move from gunicorn to waitress

Waitress, unlike unicorn, is multi-threaded. As it does not do access logs
by default, the app needs to be wrapped in TransLogger before being passed to
Waitress.

To make the switch, a custom registry is now also used instead of the global REGISTRY
as the default registry for the app. As part of this change, the default
prometheus metrics are then also registered with this new registry.

Closes: #72
This commit is contained in:
Ana Custura 2024-12-04 12:57:09 +00:00 committed by irl
parent ffe097b24f
commit c50d341c26
4 changed files with 27 additions and 15 deletions

View file

@ -4,15 +4,15 @@ ENV APP="bc"
ENV APP_BASE="/srv"
ENV SHELL="/bin/bash"
ENV FLASK_APP="${FLASK_APP:-app}"
ENV GUNICORN_RUN_HOST="${GUNICORN_RUN_HOST:-0.0.0.0}"
ENV GUNICORN_RUN_PORT="${GUNICORN_RUN_PORT:-5000}"
ENV WAITRESS_RUN_HOST="${WAITRESS_RUN_HOST:-0.0.0.0}"
ENV WAITRESS_RUN_PORT="${WAITRESS_RUN_PORT:-5000}"
ENV PYTHONPATH="${APP_BASE}/env/lib/python3.11/site-packages"
ENV PATH="${APP_BASE}/env/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:/home/${APP}/.local/bin"
ARG CONTAINER_UID="${CONTAINER_UID:-1000}"
ARG CONTAINER_GID="${CONTAINER_GID:-1000}"
ENV GUNICORN_WORKERS="${GUNICORN_WORKERS:-4}"
ENV WAITRESS_THREADS="${WAITRESS_THREADS:-4}"
RUN apt-get update && \
apt-get install --no-install-recommends -y \
@ -49,11 +49,9 @@ USER ${APP}
WORKDIR ${APP_BASE}/${APP}
COPY --chown=${APP}:${APP} . ${APP_BASE}/${APP}
RUN chmod +x ${APP_BASE}/${APP}/run_gunicorn.sh
RUN python3 -m venv ${APP_BASE}/env && \
${APP_BASE}/env/bin/pip install --no-cache-dir -r requirements.txt && \
${APP_BASE}/env/bin/pip install --no-cache-dir psycopg2-binary gunicorn
${APP_BASE}/env/bin/pip install --no-cache-dir psycopg2-binary waitress paste
RUN make install-frontend
ENTRYPOINT ["./run_gunicorn.sh"]
ENTRYPOINT ["python", "./run_waitress.py"]