Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move gunicorn config to file and set path envvar. #58

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading