From 1696955a0f16ccd6ad582fcae91c5aafd8ebd6e7 Mon Sep 17 00:00:00 2001 From: K Davis Date: Sat, 1 Jun 2024 13:18:15 -0700 Subject: [PATCH] Move gunicorn config to file and set path envvar. (#58) --- votingapi/.dockerignore | 1 + votingapi/Dockerfile | 12 ++++++------ votingapi/gunicorn.conf.py | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 votingapi/gunicorn.conf.py diff --git a/votingapi/.dockerignore b/votingapi/.dockerignore index 3e4bdd9..58da127 100644 --- a/votingapi/.dockerignore +++ b/votingapi/.dockerignore @@ -5,3 +5,4 @@ README.md *.pyd __pycache__ .pytest_cache +*~ diff --git a/votingapi/Dockerfile b/votingapi/Dockerfile index ce8fa07..f4a851c 100644 --- a/votingapi/Dockerfile +++ b/votingapi/Dockerfile @@ -34,9 +34,9 @@ COPY . ./ ENV PORT=8000 -# Run the web service on container startup. Here we use the gunicorn -# webserver, with one worker process and 8 threads. -# For environments with multiple CPU cores, increase the number of workers -# to be equal to the cores available. -# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling. -CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 voting.api:app +# Sets the url path prefix. +ENV SCRIPT_NAME=/votingapi + +# Run the web service on container startup with gunicorn. +# See gunicorn.conf.py for configuration. +CMD exec gunicorn voting.api:app diff --git a/votingapi/gunicorn.conf.py b/votingapi/gunicorn.conf.py new file mode 100644 index 0000000..1e5701c --- /dev/null +++ b/votingapi/gunicorn.conf.py @@ -0,0 +1,9 @@ +import multiprocessing +import os + +PORT = os.environ["PORT"] + +bind = f":{PORT}" +workers = multiprocessing.cpu_count() * 2 + 1 +# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling. +timeout = 0