From 33ae9a96dc4329b93e8bf01b6b8e7089f0a07d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Tue, 7 Nov 2023 22:45:47 +0100 Subject: [PATCH] make Dockerfile --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ gunicorn.conf.py | 7 +++++++ run.sh | 10 ++++++++++ 3 files changed, 53 insertions(+) create mode 100644 Dockerfile create mode 100644 gunicorn.conf.py create mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a26a3f3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM python:3.11 + +RUN mkdir /app +WORKDIR /app + +# Install NodeJS +ENV NODE_MAJOR=20 +RUN apt-get update +RUN apt-get install -y ca-certificates curl gnupg +RUN mkdir -p /etc/apt/keyrings +RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg +RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list +RUN apt-get update +RUN apt-get install -y nodejs +RUN rm -rf /var/lib/apt/lists/* + +COPY . . + +RUN pip install -r requirements/base.txt +RUN python manage.py migrate --settings=majak_uistyleguide.settings.production +RUN npm install +RUN npm run prod + +# Placeholder values so the static files collect +RUN python manage.py collectstatic --noinput --settings=majak_uistyleguide.settings.production + +RUN bash -c "adduser --disabled-login --quiet --gecos app app && \ + chmod -R o+r /app/ && \ + chmod o+x /app/run.sh" +USER app + +ENV DJANGO_SETTINGS_MODULE "majak_uistyleguide.settings.production" + +EXPOSE 8000 + +CMD ["bash", "run.sh"] diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..16484fd --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,7 @@ +bind = "0.0.0.0:8000" +accesslog = "-" +workers = 1 +max_requests = 1000 +max_requests_jitter = 10 +timeout = 60 +graceful_timeout = 60 diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..44ce2f9 --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# exit on error +set -e + +# migrate database +python manage.py migrate + +# start webserver +exec gunicorn -c gunicorn.conf.py majak_uistyleguide.wsgi -- GitLab