diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..40abb35 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.gitignore +.idea +__pycache__ +*.pyc +*.pyo +.env +.venv +venv +db.sqlite3 +staticfiles +logs +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01f1eef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +# Python 3.12 slim +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Сначала зависимости — чтобы кэшировать слой +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Код приложения +COPY . . + +# Миграции + статика при старте контейнера +CMD ["sh", "-c", "python manage.py migrate --noinput && python manage.py collectstatic --noinput && gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 2"] diff --git a/config/settings.py b/config/settings.py index f73a025..c66566c 100644 --- a/config/settings.py +++ b/config/settings.py @@ -110,5 +110,6 @@ USE_TZ = True STATIC_URL = "static/" STATICFILES_DIRS = [BASE_DIR / "static"] +STATIC_ROOT = BASE_DIR / "staticfiles" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..88e6842 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +# Секреты — только из .env (см. .env.example) +services: + web: + build: . + ports: + - "8000:8000" + env_file: + - .env + volumes: + - sqlite_data:/app/db.sqlite3 + restart: unless-stopped + +volumes: + sqlite_data: diff --git a/requirements.txt b/requirements.txt index 51030d4..144a429 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Django>=5.0,<6.0 django-axes>=8.3.1 python-dotenv>=1.0 +gunicorn>=22.0