Progress on production

This commit is contained in:
Walter 2025-02-19 11:44:19 +01:00
parent b3d0510161
commit 8fd90940bc
7 changed files with 79 additions and 7 deletions

1
.my_pgpass Normal file
View File

@ -0,0 +1 @@
localhost:5432:bloonsworld:password123

5
.pg_service.conf Normal file
View File

@ -0,0 +1,5 @@
[bloonsworld]
host=localhost
user=bloonsworld
dbname=bloonsworld
port=5432

12
app/Dockerfile Normal file
View File

@ -0,0 +1,12 @@
FROM python:3.12.2-alpine3.21
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR app
COPY requirements.txt .
RUN pip install -r requirements.txt && \
pip install gunicorn
COPY . .

View File

@ -10,8 +10,11 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from sys import platform
from pathlib import Path
from django.db.backends.postgresql.psycopg_any import IsolationLevel
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@ -19,12 +22,16 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)e!wy4)=xinnd!d(iuw6*-tf^-)ptiwnttwf+9ql%*jy63wtd8'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
if platform != "win32":
with open("/secret", "r") as f:
SECRET_KEY = f.read()
else:
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)e!wy4)=xinnd!d(iuw6*-tf^-)ptiwnttwf+9ql%*jy63wtd8'
ALLOWED_HOSTS = ["*"]
# Application definition
@ -87,12 +94,22 @@ WSGI_APPLICATION = 'settings.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
DATABASES = {}
if DEBUG:
DATABASES["default"] = {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
else:
DATABASES["default"] = {
"ENGINE": "django.db.backends.postgresql",
"OPTIONS": {
"service": "bloonsworld_db",
"passfile": ".my_pgpass",
# "isolation_level": IsolationLevel.SERIALIZABLE,
}
}
# Password validation
@ -143,3 +160,5 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
CRISPY_TEMPLATE_PACK = "bootstrap4"
CRISPY_FAIL_SILENTLY = not DEBUG

View File

@ -14,3 +14,4 @@ from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
application = get_wsgi_application()

View File

@ -20,6 +20,7 @@ class LoginView(TemplateView):
if not form.is_valid():
return render(request=request, template_name="users/login.html", context={"form": form})
user = form.get_user()
bloonsa_util.init_player(request=request)
login(request=request, user=user)
bloonsa_util.log(player=user.player,
action=actions.login)
@ -48,6 +49,7 @@ class RegisterView(TemplateView):
class LogoutView(TemplateView):
def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
bloonsa_util.init_player(request=request)
bloonsa_util.log(request=request,
action=actions.logout)
logout(request)

View File

@ -0,0 +1,32 @@
services:
bloonsworld:
build: ./app
volumes:
- ./.media:/app/media:ro
- ./.static:/app/static:rw
- ./.django:/app/data:rw
command:
- sh
- -c
- |
python manage.py collectstatic --noinput
gunicorn --chdir /app --bind :80 --workers 3 Settings.wsgi:application
environment:
- DJANGO_SECRET_KEY
- DJANGO_ALLOWED_HOSTS
- DJANGO_DEBUG
networks:
- nginx_private
- bloonsworld
restart: unless-stopped
bloonsworld-db:
networks:
- bloonsworld
restart: unless-stopped
networks:
nginx_private:
external: true
bloonsworld: