Skip to content

Commit

Permalink
Move gunicorn config to file and set path envvar. (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
anybodys authored Jun 1, 2024
1 parent bc39362 commit 1696955
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions votingapi/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ README.md
*.pyd
__pycache__
.pytest_cache
*~
12 changes: 6 additions & 6 deletions votingapi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions votingapi/gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1696955

Please sign in to comment.