From a1ffa444c25ca190c322275f8e2379299afeaf9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Thu, 7 Dec 2023 10:57:42 +0100 Subject: [PATCH] fix: allow gunicorn auto-reload locally --- .env | 9 +++++++-- Dockerfile | 2 ++ docker-compose.yml | 1 + gunicorn.py | 5 ++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 90707fa693..c5016218e7 100644 --- a/.env +++ b/.env @@ -44,7 +44,8 @@ POSTGRES_HOST=postgres POSTGRES_DB=postgres POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres -POSTGRES_EXPOSE=127.0.0.1:5432 +# Expose postgres on localhost for dev +# POSTGRES_EXPOSE=127.0.0.1:5432 # Triton ML inference server TRITON_HOST=triton @@ -84,4 +85,8 @@ FASTTEXT_MODEL_DIR=./models # Enable/disable MongoDB access. All insights/predictions are checked # against MongoDB, we disable by default locally to be able to easily test # image import -ENABLE_MONGODB_ACCESS=0 \ No newline at end of file +ENABLE_MONGODB_ACCESS=0 + +# gunicorn --auto-reload is not compatible with preload_app +# so it has to be disabled when developing, to allow hot reload +GUNICORN_PRELOAD_APP=0 diff --git a/Dockerfile b/Dockerfile index f18bc1b044..ae7f594088 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,3 +88,5 @@ RUN \ mkdir -p /opt/robotoff/gh_pages /opt/robotoff/doc /opt/robotoff/.cov && \ chown -R off:off /opt/robotoff/gh_pages /opt/robotoff/doc /opt/robotoff/.cov USER off +CMD [ "gunicorn", "--reload", "--config /opt/robotoff/gunicorn.py", "--log-file=-", "robotoff.app.api:api"] + diff --git a/docker-compose.yml b/docker-compose.yml index 3ddd1b6fbb..a662fdf9c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ x-robotoff-base-env: ROBOTOFF_TLD: ROBOTOFF_SCHEME: STATIC_DOMAIN: + GUNICORN_PRELOAD_APP: GUNICORN_NUM_WORKERS: ROBOTOFF_UPDATED_PRODUCT_WAIT: REDIS_HOST: diff --git a/gunicorn.py b/gunicorn.py index 08338bfe96..0aaa656055 100644 --- a/gunicorn.py +++ b/gunicorn.py @@ -4,5 +4,8 @@ # we have a trade-off with memory vs cpu numbers workers = int(os.environ.get("GUNICORN_NUM_WORKERS", 4)) worker_connections = 1000 -preload_app = True +# gunicorn --auto-reload is not compatible with preload_app +# so it has to be disabled when developing +# Default to True (production) if not specified +preload_app = bool(os.environ.get("GUNICORN_PRELOAD_APP", True)) timeout = 60