diff --git a/{{cookiecutter.project_slug}}/Dockerfile b/{{cookiecutter.project_slug}}/Dockerfile index 96b9bee..3ff5742 100644 --- a/{{cookiecutter.project_slug}}/Dockerfile +++ b/{{cookiecutter.project_slug}}/Dockerfile @@ -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"] diff --git a/{{cookiecutter.project_slug}}/docker/run.sh b/{{cookiecutter.project_slug}}/docker/run.sh new file mode 100755 index 0000000..17cd9fb --- /dev/null +++ b/{{cookiecutter.project_slug}}/docker/run.sh @@ -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 - diff --git a/{{cookiecutter.project_slug}}/docker/uwsgi.ini b/{{cookiecutter.project_slug}}/docker/uwsgi.ini deleted file mode 100644 index a841ae5..0000000 --- a/{{cookiecutter.project_slug}}/docker/uwsgi.ini +++ /dev/null @@ -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 diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 063b629..fbe54ad 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -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"