diff --git a/.gitignore b/.gitignore index 2d3c928..fd07185 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ venv .env *.sqlite3 *.db -docker-compose.yml \ No newline at end of file +docker-compose.yml +.data \ No newline at end of file diff --git a/app/.dockerignore b/app/.dockerignore new file mode 100644 index 0000000..724967f --- /dev/null +++ b/app/.dockerignore @@ -0,0 +1,4 @@ +*.db +*.sqlite3 +reload.bat +readme.md \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile index 30451d8..639a7af 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -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 ENV PYTHONDONTWRITEBYTECODE=1 \ @@ -31,22 +9,22 @@ ENV PYTHONDONTWRITEBYTECODE=1 \ RUN mkdir -p $HOME && \ mkdir $APP_HOME && \ addgroup --system app && \ - adduser --system -G app app + adduser --system -G app app && \ + apk update && \ + apk add --no-cache netcat-openbsd WORKDIR $APP_HOME -RUN apk update && \ - apk add --no-cache netcat-openbsd -COPY --from=builder /usr/src/app/wheels /wheels -COPY --from=builder /usr/src/app/requirements.txt . +RUN +COPY ./requirements.txt $APP_HOME RUN pip install --upgrade pip && \ - pip install --no-cache /wheels/* + pip install -r requirements.txt 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 diff --git a/app/entrypoint.sh b/app/entrypoint.sh index b7840c2..977b5f0 100644 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -2,9 +2,9 @@ echo "Waiting for postgres..." -while ! nc -z $SQL_HOST $SQL_PORT; do - sleep 0.1 -done +#while ! nc -z $SQL_HOST $SQL_PORT; do +# sleep 0.1 +#done echo "PostgreSQL started" diff --git a/app/requirements.txt b/app/requirements.txt index b59fd97..8a5455c 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -6,4 +6,5 @@ tqdm==4.67.1 Pillow==11.* django-resized==1.0.3 django-cleanup==9.0.0 -psycopg2-binary==2.9.10 \ No newline at end of file +psycopg2-binary==2.9.10 +gunicorn \ No newline at end of file diff --git a/app/settings/settings.py b/app/settings/settings.py index fc45300..3e2d32a 100644 --- a/app/settings/settings.py +++ b/app/settings/settings.py @@ -140,6 +140,7 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ +STATIC_ROOT = os.path.join(BASE_DIR, "static") STATIC_URL = "/static/" MEDIA_ROOT = os.path.join(BASE_DIR, "media") diff --git a/app/users/util.py b/app/users/util.py index 37ab57a..6d4f36c 100644 --- a/app/users/util.py +++ b/app/users/util.py @@ -25,16 +25,14 @@ class BloonsaUtil: if not request.user.is_authenticated: return 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 ip = self.get_ip(request=request) player = Player(user=request.user, creation_ip=ip, latest_ip=ip) player.save() + bloonsa_config = Config(player=player) + bloonsa_config.save() return player # Update activity timestamp and IP diff --git a/docker-compose-example.yml b/docker-compose-example.yml index 6dde518..eb2fb01 100644 --- a/docker-compose-example.yml +++ b/docker-compose-example.yml @@ -10,7 +10,7 @@ services: - -c - | 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: - DJANGO_SECRET_KEY - DJANGO_ALLOWED_HOSTS @@ -18,6 +18,8 @@ services: networks: - nginx_private - bloonsworld + depends_on: + - bloonsworld-db restart: unless-stopped bloonsworld-db: