diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..a26a3f3d70484698eecb4370a68fe352de09240e --- /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 0000000000000000000000000000000000000000..16484fd52069292cf24727fbf8e393ac8583608e --- /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 0000000000000000000000000000000000000000..44ce2f937a524e71decc18ee9ea9c8ba7b5d1b5d --- /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