From 7df105360a9a0df273a569dcc11db53ef47050e8 Mon Sep 17 00:00:00 2001 From: Timon Engelke Date: Mon, 7 Aug 2023 17:30:50 +0200 Subject: [PATCH] Add MafiAStarLite --- MafiAStarLite/Dockerfile | 34 ++++++++++++++++++++++++++ MafiAStarLite/MafiAStarLite | 1 + MafiAStarLite/MafiAStarLite-frontend | 1 + MafiAStarLite/nginx.conf | 19 +++++++++++++++ MafiAStarLite/start.sh | 13 ++++++++++ MafiAStarLite/uwsgi-mafiastar.ini | 36 ++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 MafiAStarLite/Dockerfile create mode 160000 MafiAStarLite/MafiAStarLite create mode 160000 MafiAStarLite/MafiAStarLite-frontend create mode 100644 MafiAStarLite/nginx.conf create mode 100755 MafiAStarLite/start.sh create mode 100644 MafiAStarLite/uwsgi-mafiastar.ini diff --git a/MafiAStarLite/Dockerfile b/MafiAStarLite/Dockerfile new file mode 100644 index 0000000..ab04e5e --- /dev/null +++ b/MafiAStarLite/Dockerfile @@ -0,0 +1,34 @@ +FROM debian:bullseye AS base + +ARG BACKEND_PATH=./MafiAStarLite + +# Install normal dependencies +RUN apt-get update +RUN apt-get -y --no-install-recommends install uwsgi uwsgi-plugin-python3 python3 python3-pip python3-setuptools pipenv nginx +RUN pip3 install wheel + +# Add project code to container +ADD $BACKEND_PATH /app/backend + +# Setup backend +RUN cd /app/backend && pipenv install --system --deploy --ignore-pipfile + +FROM node:18 AS frontend + +# Build frontend +ARG FRONTEND_PATH=./MafiAStarLite-frontend +ADD $FRONTEND_PATH /app/frontend +WORKDIR /app/frontend +RUN npm install +RUN npm run build + +FROM base AS final +COPY --from=frontend /app/frontend/dist /app/static +RUN mkdir /app/backend/logs +ADD start.sh /usr/local/bin/run +ADD uwsgi-mafiastar.ini /etc/uwsgi/mafiastar.ini +ADD nginx.conf /etc/nginx/sites-enabled/default + +RUN usermod -u 2009 -g 33 -d /app/backend www-data + +CMD /usr/local/bin/run diff --git a/MafiAStarLite/MafiAStarLite b/MafiAStarLite/MafiAStarLite new file mode 160000 index 0000000..37bcfeb --- /dev/null +++ b/MafiAStarLite/MafiAStarLite @@ -0,0 +1 @@ +Subproject commit 37bcfeb64e285bbb3516076f885cc28894321139 diff --git a/MafiAStarLite/MafiAStarLite-frontend b/MafiAStarLite/MafiAStarLite-frontend new file mode 160000 index 0000000..a916f0a --- /dev/null +++ b/MafiAStarLite/MafiAStarLite-frontend @@ -0,0 +1 @@ +Subproject commit a916f0afb3b5b1cf2093db0d433fd9ed8e303c84 diff --git a/MafiAStarLite/nginx.conf b/MafiAStarLite/nginx.conf new file mode 100644 index 0000000..306527e --- /dev/null +++ b/MafiAStarLite/nginx.conf @@ -0,0 +1,19 @@ +# vim: set filetype=conf: + +server { + listen 80; + server_name default_server; + + try_files $uri /index.html; + root /app/static; + + location /admin { + include uwsgi_params; + uwsgi_pass 127.0.0.1:3008; + } + + location /api { + include uwsgi_params; + uwsgi_pass 127.0.0.1:3008; + } +} diff --git a/MafiAStarLite/start.sh b/MafiAStarLite/start.sh new file mode 100755 index 0000000..fa37781 --- /dev/null +++ b/MafiAStarLite/start.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e +export USER=www-data +export HOME=/home/www-data + +# Migrate database and deploy staticfiles +python3 /app/backend/manage.py migrate +python3 /app/backend/manage.py collectstatic --noinput +chown -R www-data:www-data /app/backend/logs + +# Start backend with uWSGI +nginx +exec uwsgi /etc/uwsgi/mafiastar.ini diff --git a/MafiAStarLite/uwsgi-mafiastar.ini b/MafiAStarLite/uwsgi-mafiastar.ini new file mode 100644 index 0000000..0db5abe --- /dev/null +++ b/MafiAStarLite/uwsgi-mafiastar.ini @@ -0,0 +1,36 @@ +[uwsgi] + +procname-master = uwsgi %n +master = true +socket = :3008 + +plugins = python3 + +chdir = /app/backend + +#home = /opt/tauschen/tauschen-backend/.pyenv +module = MafiAStarLite.wsgi:application +#env = DJANGO_SETTINGS_MODULE=tauschen.settings +env = LANG='C.UTF-8' +env = LC_ALL='C.UTF-8' + +; drop privileges +uid = www-data +gid = www-data +umask = 027 + +; run with at least 2 process but increase up to 8 when needed +processes = 8 +cheaper = 2 + +; reload whenever this config file changes +; %p is the full path of the current config file +touch-reload = %p + +; disable uWSGI request logging +disable-logging = true + +enable-threads = true + +; cron job +cron2 = minute=30,hour=2,unique=1 python3 /app/backend/manage.py updatedb