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

feat(gunicorn): Add config #3894

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
21 changes: 3 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
FROM docker.io/library/python:3.11-slim-bullseye

ENV GUNICORN_WORKERS=1
ENV GUNICORN_THREADS=1
ENV GUNICORN_BIND="0.0.0.0:8000"
ENV GUNICORN_TIMEOUT=400


ENV CG_SQL_DATABASE_URI="sqlite:///:memory:"
ENV CG_SECRET_KEY="key"

Check warning on line 4 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "CG_SECRET_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ENV LIMS_HOST="mocklims.scilifelab.se"
ENV LIMS_USERNAME="limsadmin"
ENV LIMS_PASSWORD="limsadminpassword"

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "LIMS_PASSWORD") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ENV MAIL_CONTAINER_URI="http://127.0.0.1:port/container"

ENV OSTICKET_EMAIL="[email protected]"
ENV OSTICKET_API_KEY=None

Check warning on line 13 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "OSTICKET_API_KEY") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
ENV OSTICKET_DOMAIN=None
ENV OSTICKET_TIMEOUT="1"

ENV GOOGLE_OAUTH_CLIENT_ID="1"
ENV GOOGLE_OAUTH_CLIENT_SECRET="1"

Check warning on line 18 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "GOOGLE_OAUTH_CLIENT_SECRET") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

ENV TRAILBLAZER_HOST="host"
ENV TRAILBLAZER_SERVICE_ACCOUNT="service_account"
ENV TRAILBLAZER_SERVICE_ACCOUNT_AUTH_FILE="auth_file"

Check warning on line 22 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "TRAILBLAZER_SERVICE_ACCOUNT_AUTH_FILE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/


WORKDIR /home/src/app
COPY pyproject.toml poetry.lock ./
COPY pyproject.toml poetry.lock gunicorn.conf.py ./

RUN pip install --no-cache-dir poetry \
&& poetry config virtualenvs.create false \
Expand All @@ -37,15 +31,6 @@

COPY cg ./cg

CMD gunicorn \

Check warning on line 34 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-image-push

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
--workers=$GUNICORN_WORKERS \
--bind=$GUNICORN_BIND \
--threads=$GUNICORN_THREADS \
--timeout=$GUNICORN_TIMEOUT \
--proxy-protocol \
--forwarded-allow-ips="10.0.2.100,127.0.0.1" \
--log-syslog \
--access-logfile - \
--error-logfile - \
--log-level="debug" \
cg.server.auto:app
--config gunicorn.conf.py \
cg.server.auto:app
9 changes: 9 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bind = "0.0.0.0:8000"
threads = 4
timeout = 400
loglevel = "debug"
protocol = "proxy"
syslog = True
forwarded_allow_ips = "10.0.2.100,127.0.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwarded_allow_ips = "127.0.0.1"

I would suggest having deployment-specific configurations in their respective repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, but in a specific future PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should not the configuration of gunicorn be handled in servers rather than be dictated by code in the repo? If we want to increase the number of workers we shouldn't have to make a PR to cg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a even bigger change. And I do not know if it would make sense to move it away from the actual app. Either way it is definitively out of scope.

If you agree - could you approve this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accesslog = "-"
workers = 2
Loading
Loading