-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add docker and docker-compose #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7067ee0
4e7a170
725af5e
db6d7d8
091e408
3b0a76f
294f11a
228fc72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .venv | ||
| __pycache__ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| env/ | ||
| venv/ | ||
| *.env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # ============================================= | ||
| # БАЗОВЫЕ НАСТРОЙКИ DJANGO | ||
| # ============================================= | ||
| DEBUG=True | ||
| SECRET_KEY=supersecretkey | ||
| DJANGO_SECRET_KEY=supersecretkey | ||
| ALLOWED_HOSTS=localhost,127.0.0.1 | ||
|
|
||
| # ============================================= | ||
| # БАЗА ДАННЫХ (PostgreSQL) | ||
| # ============================================= | ||
| POSTGRES_DB=pythonbooks | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
| POSTGRES_HOST=localhost | ||
| POSTGRES_PORT=5432 | ||
| DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Use official Python 3.13 slim image based on Debian Bookworm | ||
| FROM python:3.13-slim-bookworm | ||
|
|
||
| # Install UV (ultra-fast Python package installer) from Astral.sh | ||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | ||
|
|
||
| # Ensure Python output is sent straight to terminal without buffering | ||
| ENV PYTHONUNBUFFERED=1 \ | ||
| PYTHONDONTWRITEBYTECODE=1 | ||
|
|
||
| # ====================== | ||
| # SYSTEM DEPENDENCIES | ||
| # ====================== | ||
| RUN apt-get update && \ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше убрать совсем |
||
| apt-get install -y --no-install-recommends curl gettext && \ | ||
| apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Set working directory inside container | ||
| WORKDIR /app | ||
|
|
||
| # ====================== | ||
| # DEPENDENCY INSTALLATION | ||
| # ====================== | ||
| # Copies the dependency files (py project.tool and uv.lock) to /app. | ||
| COPY pyproject.toml uv.lock ./ | ||
|
|
||
| # Install Python dependencies using UV: | ||
| # --locked: ensures exact versions from lockfile are used | ||
| # Copies the rest of the project code to /app. | ||
| RUN uv sync --locked | ||
|
|
||
| # ====================== | ||
| # APPLICATION CODE | ||
| # ====================== | ||
| # Copy the rest of the application code | ||
| # Note: This is done after dependency installation for better caching | ||
| COPY . . | ||
|
|
||
| # Copies the script entrypoint.sh in /app. | ||
| # Makes it executable (chmod +x). | ||
| COPY entrypoint.sh /app/entrypoint.sh | ||
| RUN chmod +x /app/entrypoint.sh | ||
|
|
||
| # ====================== | ||
| # RUNTIME CONFIGURATION | ||
| # ====================== | ||
| # Expose the port Django runs on | ||
| EXPOSE 8000 | ||
|
|
||
| # Launches the application through a script entrypoint.sh | ||
| ENTRYPOINT ["/app/entrypoint.sh"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| USERID := $(shell id -u) | ||
| GROUPID := $(shell id -g) | ||
| PYTHON := docker compose run -u $(USERID):$(GROUPID) --rm django uv run | ||
|
|
||
| collectstatic: | ||
| $(PYTHON) manage.py collectstatic --noinput -c | ||
|
|
||
| startapp: | ||
| $(PYTHON) manage.py startapp ${app} | ||
|
|
||
| makemigrations: | ||
| $(PYTHON) manage.py makemigrations ${app} | ||
|
|
||
| migrate: | ||
| $(PYTHON) manage.py migrate ${app} | ||
|
|
||
| createsuperuser: | ||
| $(PYTHON) manage.py createsuperuser | ||
|
|
||
| shell: | ||
| $(PYTHON) manage.py shell_plus | ||
|
|
||
| reset_db: | ||
| $(PYTHON) manage.py reset_db | ||
|
|
||
| format: | ||
| uvx ruff check --fix apps config && uvx ruff check --select I --fix apps config && uvx ruff format apps config | ||
|
|
||
| run: | ||
| $(PYTHON) manage.py migrate | ||
| $(PYTHON) manage.py runserver 0.0.0.0:8000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,26 @@ | ||
| """ | ||
| Django settings for pythonbooks project. | ||
| import os | ||
|
|
||
| Generated by 'django-admin startproject' using Django 5.2.1. | ||
|
|
||
| For more information on this file, see | ||
| https://docs.djangoproject.com/en/5.2/topics/settings/ | ||
| from pathlib import Path | ||
|
|
||
| For the full list of settings and their values, see | ||
| https://docs.djangoproject.com/en/5.2/ref/settings/ | ||
| """ | ||
| import environ | ||
|
|
||
| from pathlib import Path | ||
| # Initialize environment variables | ||
| env = environ.Env() | ||
|
|
||
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | ||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
|
||
| # Quick-start development settings - unsuitable for production | ||
| # See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ | ||
| # Take environment variables from .env file | ||
| environ.Env.read_env(os.path.join(BASE_DIR, ".env")) | ||
|
|
||
| # ======================== | ||
| # SECURITY CONFIGURATION | ||
| # ======================== | ||
| # SECURITY WARNING: keep the secret key used in production secret! | ||
| SECRET_KEY = "django-insecure-&99ow@p0-s&blmk!57k%q_vr%u^baye)cp0zo^zyu8&6l6o27v" | ||
|
|
||
| SECRET_KEY = env("DJANGO_SECRET_KEY") | ||
| # SECURITY WARNING: don't run with debug turned on in production! | ||
| DEBUG = True | ||
|
|
||
| ALLOWED_HOSTS = [] | ||
| # Hosts/domain names that this Django site can serve | ||
| ALLOWED_HOSTS = env.list("ALLOWED_HOSTS") | ||
|
|
||
| # Application definition | ||
|
|
||
|
|
@@ -58,6 +54,7 @@ | |
| "APP_DIRS": True, | ||
| "OPTIONS": { | ||
| "context_processors": [ | ||
| "django.template.context_processors.debug", | ||
| "django.template.context_processors.request", | ||
| "django.contrib.auth.context_processors.auth", | ||
| "django.contrib.messages.context_processors.messages", | ||
|
|
@@ -68,19 +65,17 @@ | |
|
|
||
| WSGI_APPLICATION = "config.wsgi.application" | ||
|
|
||
| # Database | ||
| # https://docs.djangoproject.com/en/5.2/ref/settings/#databases | ||
|
|
||
| # ============= | ||
| # DATABASE | ||
| # ============= | ||
| # Uses django-environ to automatically parse DB_* variables or DATABASE_URL | ||
| DATABASES = { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Заменить на переменную окружения |
||
| "default": { | ||
| "ENGINE": "django.db.backends.sqlite3", | ||
| "NAME": BASE_DIR / "db.sqlite3", | ||
| } | ||
| } | ||
|
|
||
| # Password validation | ||
| # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators | ||
|
|
||
| AUTH_PASSWORD_VALIDATORS = [ | ||
| { | ||
| "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", | ||
|
|
@@ -96,23 +91,31 @@ | |
| }, | ||
| ] | ||
|
|
||
| # Internationalization | ||
| # https://docs.djangoproject.com/en/5.2/topics/i18n/ | ||
| # ================= | ||
| # INTERNATIONALIZATION | ||
| # ================= | ||
| LANGUAGE_CODE = "en" | ||
| LANGUAGES = [ | ||
| ("en", "English"), | ||
| ("ru", "Russian"), | ||
| ] | ||
| TIME_ZONE = "UTC" | ||
| USE_I18N = True | ||
| USE_L10N = True | ||
| USE_TZ = True | ||
| # path to catalog files: .po, .mo | ||
| LOCALE_PATHS = [ | ||
| os.path.join(BASE_DIR, "locale"), | ||
| ] | ||
|
|
||
| # Static files (CSS, JavaScript, Images) | ||
| # https://docs.djangoproject.com/en/5.2/howto/static-files/ | ||
|
|
||
| # ============= | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Прогнать настройки через LLM (отформатировать) |
||
| # STATIC FILES | ||
| # ============= | ||
| STATIC_URL = "static/" | ||
| # Note: STATIC_ROOT should be set when collecting static files for production | ||
| # STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') | ||
|
|
||
| # Default primary key field type | ||
| # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field | ||
|
|
||
| # ==================== | ||
| # DEFAULT PRIMARY KEY | ||
| # ==================== | ||
| DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зафиксировать версию UV