diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6c91c04 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +# Exclude everything and allow only the necessary files +* +!/docker/ +!/src/ +!/src/manage.py +!/pyproject.toml + +# Python +*.py[cod] +__pycache__ + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ff2659b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3-slim +MAINTAINER Julian-Samuel Gebühr + +ENV DOCKER_BUILD=true + +RUN apt update +RUN apt install gettext -y +COPY . /app +WORKDIR /app +RUN mkdir /app/static +RUN mkdir /app/media +RUN pip install -e . # Without the -e the library static folder will not be copied by collectstatic! + +RUN nf collectstatic --noinput +RUN nf compilemessages --ignore venv + +COPY docker/notfellchen.bash /bin/notfellchen + +EXPOSE 8345 +CMD ["notfellchen"] diff --git a/docker/build.cfg b/docker/build.cfg new file mode 100644 index 0000000..df9a20f --- /dev/null +++ b/docker/build.cfg @@ -0,0 +1,5 @@ +[django] +secret="NOTREALSECRET" +[locations] +static=/notfellchen/static +media=/notfellchen/media \ No newline at end of file diff --git a/docker/notfellchen.bash b/docker/notfellchen.bash new file mode 100755 index 0000000..c63942a --- /dev/null +++ b/docker/notfellchen.bash @@ -0,0 +1,22 @@ +#!/bin/bash + +set -eux + +cd /app + +AUTOMIGRATE=${AUTOMIGRATE:-yes} +NUM_WORKERS_DEFAULT=$((2 * $(nproc --all))) +export NUM_WORKERS=${NUM_WORKERS:-$NUM_WORKERS_DEFAULT} + +if [ "$AUTOMIGRATE" != "skip" ]; then + nf migrate --noinput +fi + +exec gunicorn notfellchen.wsgi \ + --name notfellchen \ + --workers $NUM_WORKERS \ + --max-requests 1200 \ + --max-requests-jitter 50 \ + --log-level=info \ + --bind 0.0.0.0:8345 +