From 4429ad9f5d20ab8a7d09a8df4d54c2edfdf13e3f Mon Sep 17 00:00:00 2001 From: mike <219478+ilude@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:18:16 -0400 Subject: [PATCH] replace waitress with hypercorn --- Dockerfile | 8 +++++--- app/app.py | 9 +++++++-- requirements.txt | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2d6fa05..05fae99 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,10 +12,15 @@ ARG TZ=America/New_York ENV USER=${USER} ENV TZ=${TZ} +ARG PROJECT_NAME +ENV PROJECT_NAME=${PROJECT_NAME} + ARG PROJECT_PATH=/app ENV PROJECT_PATH=${PROJECT_PATH} + ENV PYTHON_DEPS_PATH=/dependencies ENV PYTHONPATH="${PYTHONPATH}:${PYTHON_DEPS_PATH}" +ENV PYTHONUNBUFFERED=TRUE ENV LANGUAGE=en_US.UTF-8 ENV LANG=en_US.UTF-8 @@ -151,9 +156,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ RUN echo ${USER} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USER} && \ chmod 0440 /etc/sudoers.d/${USER} -ARG PROJECT_NAME -ENV PROJECT_NAME=${PROJECT_NAME} - ENV DOTFILES_URL=https://github.com/ilude/dotfiles.git USER ${USER} diff --git a/app/app.py b/app/app.py index 48d3336..62f0649 100644 --- a/app/app.py +++ b/app/app.py @@ -147,8 +147,13 @@ def index(): if __name__ == '__main__': port = int(os.environ.get("ONBOARD_PORT", 9830)) + print(f"Starting {os.environ.get('PROJECT_NAME', 'OnBoard').title()} server on port {port}") if os.environ.get("FLASK_DEBUG", "False") == "True": app.run(port=port, debug=True) else: - from waitress import serve - serve(app, host='0.0.0.0', port=port) + import asyncio + from hypercorn.config import Config + from hypercorn.asyncio import serve + config = Config() + config.bind = [f"0.0.0.0:{port}"] + asyncio.run(serve(app, config)) diff --git a/requirements.txt b/requirements.txt index 030ce2c..9616042 100755 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ lxml python-dotenv pyyaml requests -waitress \ No newline at end of file +hypercorn \ No newline at end of file