From fba195db9c1ae8de7bada3d2e3e19ba6d35531cb Mon Sep 17 00:00:00 2001 From: ackFromRedmi Date: Sat, 28 Mar 2026 10:11:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B4=D0=BE=D0=BA=D0=B5=D1=80=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 20 +++++++++++++++++++- core/settings.py | 5 ++++- core/urls.py | 7 +++++++ docker-compose.yml | 1 + entrypoint.sh | 7 +++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 74fbcdb..1f9b2d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,24 @@ FROM python:3.12-slim + WORKDIR /app + +# Окружение +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +# Ставим системные либы для Postgres +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc libpq-dev && rm -rf /var/lib/apt/lists/* + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt + COPY . . -CMD ["gunicorn", "--bind", "0.0.0.0:8000", "core.wsgi:application"] \ No newline at end of file + +# Обязательно даем права скрипту +RUN chmod +x /app/entrypoint.sh + +# Используем путь из рабочей папки +ENTRYPOINT ["/app/entrypoint.sh"] + +CMD ["gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3"] \ No newline at end of file diff --git a/core/settings.py b/core/settings.py index 26cdab9..287dbac 100644 --- a/core/settings.py +++ b/core/settings.py @@ -179,4 +179,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') CSRF_TRUSTED_ORIGINS = env.list('CSRF_ORIGINS', default=['http://localhost']) -print(f"--- РАБОТАЕМ НА БАЗЕ: {DATABASES['default']['NAME']} (HOST: {DATABASES['default'].get('HOST', 'localhost')}) ---") \ No newline at end of file +print(f"--- РАБОТАЕМ НА БАЗЕ: {DATABASES['default']['NAME']} (HOST: {DATABASES['default'].get('HOST', 'localhost')}) ---") + +print (env) + diff --git a/core/urls.py b/core/urls.py index 3667112..9789db1 100644 --- a/core/urls.py +++ b/core/urls.py @@ -16,7 +16,14 @@ Including another URLconf """ from django.contrib import admin from django.urls import path +from django.conf.urls.static import static # <--- Добавьте эту строку +from core import settings urlpatterns = [ path('admin/', admin.site.urls), ] + +# Вместо if settings.DEBUG: не забываем from django.conf.urls.static import static # <--- Добавьте эту строку +if settings.ENV_TYPE in ['local', 'dev']: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2ac8e52..b196e2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,7 @@ services: image: nginx:1.25-alpine restart: unless-stopped volumes: + # Подключаем конфиг и статику с медиа в режиме только для чтения (т.к. nginx смотрит в интернет и может быть подвергнута атаке) - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro - staticfiles:/app/staticfiles:ro - mediafiles:/app/media:ro diff --git a/entrypoint.sh b/entrypoint.sh index 96bc549..c9c5a38 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,15 @@ #!/bin/sh + +# Собираем статику в папку, которую увидит Nginx echo "Collecting static files..." python manage.py collectstatic --noinput + +# Миграции echo "Applying database migrations..." python manage.py migrate --noinput + +# Создаем админа (из переменных .env) python manage.py createsuperuser --no-input || true + echo "Starting Gunicorn..." exec "$@" \ No newline at end of file