Switch to gunicorn

This commit is contained in:
Gabriel Augendre 2022-11-10 17:47:05 +01:00
parent 4a593dca2a
commit d3da95b117
4 changed files with 10 additions and 43 deletions

View File

@ -91,38 +91,13 @@ ENV PATH /app/venv/bin:$PATH
ENV STATIC_ROOT=/app/static
COPY --chown=django:django --from=venv $STATIC_ROOT $STATIC_ROOT
# uWSGI env vars
##############################################
ENV UWSGI_HTTP=:8000
ENV UWSGI_CHDIR="/app/src"
ENV UWSGI_WSGI_FILE="/app/src/{{cookiecutter.project_slug}}/wsgi.py"
ENV UWSGI_MASTER=1
ENV UWSGI_HTTP_AUTO_CHUNKED=1
ENV UWSGI_HTTP_KEEPALIVE=1
ENV UWSGI_UID=1000
ENV UWSGI_GID=1000
ENV UWSGI_WSGI_ENV_BEHAVIOR=holy
ENV UWSGI_DIE_ON_TERM=true
ENV UWSGI_STRICT=true
ENV UWSGI_NEED_APP=true
# Tweak for perf
ENV UWSGI_SINGLE_INTERPRETER=true
ENV UWSGI_AUTO_PROCNAME=true
ENV UWSGI_MAX_REQUESTS=5000
ENV UWSGI_MAX_WORKER_LIFETIME=3600
ENV UWSGI_RELOAD_ON_RSS=500
ENV UWSGI_WORKER_RELOAD_MERCY=10
ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
# Create directory structure
##############################################
WORKDIR /app
COPY pyproject.toml poetry.lock ./
ADD --chown=django:django ./src ./src
ADD --chown=django:django ./docker ./docker
COPY --chown=django:django tasks.py ./tasks.py
COPY --chown=django:django docker/uwsgi.ini ./uwsgi.ini
RUN mkdir -p /app/data
@ -132,5 +107,7 @@ EXPOSE 8000
WORKDIR /app/src
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
USER django
CMD ["uwsgi", "--show-config", "--ini", "/app/uwsgi.ini"]
CMD ["/app/docker/run.sh"]

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -eux
python manage.py migrate --noinput
gunicorn {{cookiecutter.project_slug}}.wsgi -b 0.0.0.0:8000 --log-file -

View File

@ -1,15 +0,0 @@
[uwsgi]
plugin = /app/escape_json_plugin.so
static-map = /media=/app/data/media/
logger-req = stdio
; json_uri and json_host are json-escaped fields defined in `escape_json_plugin.so`
log-format = "address":"%(addr)", "host":"%(json_host)", "method":"%(method)", "uri":"%(json_uri)", "protocol":"%(proto)", "resp_size":%(size), "req_body_size":%(cl), "resp_status":%(status), "resp_time":%(msecs), "referer":"%(referer)", "user_agent":"%(uagent)"
log-req-encoder = format {"source":"uwsgi-req", "time":"${strftime:%%FT%%T%%z}", ${msg}}
log-req-encoder = nl
; Ignore write errors
; https://github.com/getsentry/raven-python/issues/732#issuecomment-176854438
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true

View File

@ -17,7 +17,8 @@ django-linear-migrations = ">=2.2.0"
django-extensions = ">=3.1.5"
psycopg2-binary = ">=2.8"
whitenoise = ">=6.2"
uWSGI = ">=2.0.21"
requests = ">=2.28.1"
gunicorn = ">=20.1.0"
[tool.poetry.dev-dependencies]
django-debug-toolbar = ">=3.2"