we are so ready

This commit is contained in:
Walter 2025-02-20 20:39:41 +01:00
parent ef004ded24
commit 39f343d6bc
8 changed files with 26 additions and 41 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ venv
*.sqlite3 *.sqlite3
*.db *.db
docker-compose.yml docker-compose.yml
.data

4
app/.dockerignore Normal file
View File

@ -0,0 +1,4 @@
*.db
*.sqlite3
reload.bat
readme.md

View File

@ -1,25 +1,3 @@
# https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
FROM python:3.13.2-slim-bullseye AS builder
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc && \
pip install --upgrade pip && \
pip install flake8==6.0.0
COPY . /usr/src/app/
# RUN flake8 --ignore=E501,F401 .
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
FROM python:3.13.2-alpine3.21 FROM python:3.13.2-alpine3.21
ENV PYTHONDONTWRITEBYTECODE=1 \ ENV PYTHONDONTWRITEBYTECODE=1 \
@ -31,22 +9,22 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
RUN mkdir -p $HOME && \ RUN mkdir -p $HOME && \
mkdir $APP_HOME && \ mkdir $APP_HOME && \
addgroup --system app && \ addgroup --system app && \
adduser --system -G app app adduser --system -G app app && \
apk update && \
apk add --no-cache netcat-openbsd
WORKDIR $APP_HOME WORKDIR $APP_HOME
RUN apk update && \ RUN
apk add --no-cache netcat-openbsd COPY ./requirements.txt $APP_HOME
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip && \ RUN pip install --upgrade pip && \
pip install --no-cache /wheels/* pip install -r requirements.txt
COPY . $APP_HOME COPY . $APP_HOME
RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh && \
chmod +x $APP_HOME/entrypoint.sh
RUN chown -R app:app $APP_HOME RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.sh && \
chmod +x $APP_HOME/entrypoint.sh && \
chown -R app:app $APP_HOME
USER app USER app

View File

@ -2,9 +2,9 @@
echo "Waiting for postgres..." echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do #while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1 # sleep 0.1
done #done
echo "PostgreSQL started" echo "PostgreSQL started"

View File

@ -7,3 +7,4 @@ Pillow==11.*
django-resized==1.0.3 django-resized==1.0.3
django-cleanup==9.0.0 django-cleanup==9.0.0
psycopg2-binary==2.9.10 psycopg2-binary==2.9.10
gunicorn

View File

@ -140,6 +140,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/" STATIC_URL = "/static/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_ROOT = os.path.join(BASE_DIR, "media")

View File

@ -25,16 +25,14 @@ class BloonsaUtil:
if not request.user.is_authenticated: if not request.user.is_authenticated:
return return
if hasattr(request.user, "player"): if hasattr(request.user, "player"):
# TODO Optimize this by only doing it on register
if not hasattr(request.user.player, "bloonsa_config"):
bloonsa_config = Config(player=request.user.player)
bloonsa_config.save()
return request.user.player return request.user.player
ip = self.get_ip(request=request) ip = self.get_ip(request=request)
player = Player(user=request.user, player = Player(user=request.user,
creation_ip=ip, creation_ip=ip,
latest_ip=ip) latest_ip=ip)
player.save() player.save()
bloonsa_config = Config(player=player)
bloonsa_config.save()
return player return player
# Update activity timestamp and IP # Update activity timestamp and IP

View File

@ -10,7 +10,7 @@ services:
- -c - -c
- | - |
python manage.py collectstatic --noinput python manage.py collectstatic --noinput
gunicorn --chdir /app --bind :80 --workers 3 Settings.wsgi:application gunicorn --chdir /app --bind :80 --workers 3 settings.wsgi:application
environment: environment:
- DJANGO_SECRET_KEY - DJANGO_SECRET_KEY
- DJANGO_ALLOWED_HOSTS - DJANGO_ALLOWED_HOSTS
@ -18,6 +18,8 @@ services:
networks: networks:
- nginx_private - nginx_private
- bloonsworld - bloonsworld
depends_on:
- bloonsworld-db
restart: unless-stopped restart: unless-stopped
bloonsworld-db: bloonsworld-db: