-
Notifications
You must be signed in to change notification settings - Fork 3
Posting-1: Config updates #131
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
Open
mlv-dev
wants to merge
55
commits into
posting.final
Choose a base branch
from
posting.1-configs
base: posting.final
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 43 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
22c7afe
1. Config updates
mlv-dev 2eba54c
1.1 Config fixes
mlv-dev 51cfdcf
1.2 Config fixes:
mlv-dev 9e5ef2b
1.3 Added more recomendations from @coderabbitai
mlv-dev 1cb0f4d
1.4 Config fixes
mlv-dev 21b6acd
1.5 Phony added to Makefile
mlv-dev 3b943c9
1.6 Save db date between restarts
mlv-dev ca81c19
1.7 Added clean command to Makefile
mlv-dev f597d50
1.8 Added run-migrations (run migrations at the first time)
mlv-dev 75aad74
1.9 Moved ports into env + fixed wrong default g_isready user
mlv-dev f9e7be0
1.10 Fixed typo
mlv-dev fd5a8b2
Apply suggestion from @coderabbitai[bot]
mlv-dev 0dfa4d8
Apply suggestion from @coderabbitai[bot]
mlv-dev b734a96
Apply suggestion from @coderabbitai[bot]
mlv-dev 682589d
Makefile fixes
mlv-dev abad419
More changes
mlv-dev 3b7eed5
Removed run from PHONY Makefile
mlv-dev 5585244
fcntl.flock
mlv-dev 625712f
Added all to Makefile
mlv-dev b018e26
--remove-orphans
mlv-dev 36ae861
Fix run-migrations.py
mlv-dev 35b578d
Some volume fixes
mlv-dev 92728cd
FIELD_ENCRYPTION_KEY
mlv-dev 484bc5c
qcluster working dir
mlv-dev 8ab704c
Web ports
mlv-dev 0086492
Remove unlock
mlv-dev 1eb054c
traceback
mlv-dev 476dbd9
Container-side Postgres port must be fixed to 5432 (internal port var…
mlv-dev 3161916
.env file for db
mlv-dev 2dc8ee0
remove environment (we already has env_file)
mlv-dev 7b002e9
No custom ports
mlv-dev 6128658
fix typo
mlv-dev 2d4e568
Correct Fernet example key
mlv-dev 1e48c4f
Guarantee LOCK_FILE.parent.mkdir
mlv-dev 880dc47
Added django_cryptography
mlv-dev 98c5c92
Remove custom port variables from .env.example and update docker-comp…
mlv-dev 8f743a9
Moved settings.py commits from 'posting.2-base_posting' branch
mlv-dev 07fadca
Added django_cryptography
mlv-dev a2f4861
if not DJANGO_CRYPTOGRAPHY_KEY
mlv-dev 9f2d2d5
x1Middleware ordering: place TimezoneMiddleware earlier
mlv-dev f2e21bb
Set USE_TZ to True and remove duplicate timezone settings
mlv-dev 6360780
Renamed Posting module to Publisher
mlv-dev ff6bf17
Add wait condition for migrations flag in qcluster command
mlv-dev 2cf56d7
Lock down CORS in production
mlv-dev 89927c8
Place CorsMiddleware earlier in the stack
mlv-dev b44d78d
LANGUAGE_COOKIE_SAMESITE should be a string
mlv-dev 0e045de
Make django-q cluster tunable via env
mlv-dev d3c00f6
Rename FIELD_ENCRYPTION_KEY to DJANGO_ENCRYPTION_KEY and update error…
mlv-dev 0736de7
rse ALLOWED_HOSTS as list and DEBUG as bool
mlv-dev 41efb59
Refactor STATICFILES_DIRS to use env.list for better handling of mult…
mlv-dev 866af55
Fix syntax error in MIDDLEWARE list by adding missing comma
mlv-dev 2795df5
ALLOWED_HOSTS format should align with settings parsing (list)
mlv-dev 8ce95f3
Simplify STATICFILES_DIRS assignment
mlv-dev 92bf74b
Add .gitattributes to mark CKEditor plugins as vendored
mlv-dev eb3f5df
_
mlv-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| PYTHONUNBUFFERED=1 | ||
| SECRET_KEY=secret | ||
|
mlv-dev marked this conversation as resolved.
|
||
| DATABASE_URL=postgis://docker:docker@db:5432/dtpstat | ||
| STATIC_ROOT=/static | ||
| MEDIA_ROOT=/app/media | ||
| STATICFILES_DIRS=/code/static | ||
| RECAPTCHA_PUBLIC_KEY=test | ||
| RECAPTCHA_PRIVATE_KEY=test | ||
| DEBUG=1 | ||
| PROJECT_PATH=/code | ||
| ALLOWED_HOSTS=* | ||
|
mlv-dev marked this conversation as resolved.
Outdated
|
||
| HERE_TOKEN=123 | ||
| YANDEX_TOKEN=123 | ||
|
|
||
| POSTGRES_DB=dtpstat | ||
| POSTGRES_USER=docker | ||
| POSTGRES_PASSWORD=docker | ||
|
|
||
| DJANGO_SUPERUSER_USERNAME=admin | ||
| DJANGO_SUPERUSER_EMAIL=admin@localhost | ||
| DJANGO_SUPERUSER_PASSWORD=admin | ||
|
|
||
| MIGRATIONS_FLAG_PATH=/var/run/dtpstat/.migrations_done | ||
|
|
||
| # Generate a key: python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" | ||
| # (example key): | ||
| FIELD_ENCRYPTION_KEY=Z0n5S1hFhE1w8V7eG1WQ9h9x8pPCk9Q5jQWQv7P3c4Y= | ||
|
mlv-dev marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,7 +102,8 @@ celerybeat.pid | |
| *.sage.py | ||
|
|
||
| # Environments | ||
| .env | ||
| .env* | ||
| !.env.example | ||
| .venv | ||
| env/ | ||
| venv/ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,19 @@ | ||
| run: | ||
| docker-compose up | ||
| .PHONY: all up down clean sh build test | ||
|
|
||
| # Replace with your compose file | ||
| COMPOSE_FILE=docker-compose.example.yml | ||
|
|
||
| up: | ||
| docker compose -f $(COMPOSE_FILE) up -d | ||
| down: | ||
| docker compose -f $(COMPOSE_FILE) down --remove-orphans | ||
| clean: | ||
| docker compose -f $(COMPOSE_FILE) down -v | ||
| sh: | ||
| docker-compose exec web /bin/bash | ||
| docker compose -f $(COMPOSE_FILE) exec -it web /bin/bash | ||
| build: | ||
| docker-compose build | ||
| docker compose -f $(COMPOSE_FILE) build | ||
| test: | ||
| docker-compose exec web pytest | ||
| docker compose -f $(COMPOSE_FILE) exec -it web pytest | ||
|
|
||
| all: build up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import os | ||
| import django | ||
|
|
||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dtpstat.settings") | ||
| django.setup() | ||
|
|
||
| from django.contrib.auth import get_user_model | ||
|
|
||
| User = get_user_model() | ||
|
|
||
| username = os.environ.get('DJANGO_SUPERUSER_USERNAME') | ||
| email = os.environ.get('DJANGO_SUPERUSER_EMAIL') | ||
| password = os.environ.get('DJANGO_SUPERUSER_PASSWORD') | ||
|
|
||
| if not User.objects.filter(username=username).exists(): | ||
| User.objects.create_superuser(username=username, email=email, password=password) | ||
|
mlv-dev marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Example file to run your dev server | ||
|
|
||
| # copy: 'cp docker-compose.example.yml docker-compose.yml' | ||
| # or use 'docker compose -f docker-compose.example.yml up' | ||
| # or just run 'make up' (Makefile handles it) | ||
|
|
||
| services: | ||
| db: | ||
| image: kartoza/postgis:14-3.3 | ||
| volumes: | ||
| - pgdata:/var/lib/postgresql/data | ||
| ports: | ||
| - "5431:5432" | ||
| networks: | ||
| - backend | ||
| env_file: | ||
| - .env.example | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\" -h 127.0.0.1 -p 5432"] | ||
| interval: 5s # Check health every 5 second | ||
| timeout: 2s # Allow 2 seconds for response | ||
| retries: 10 # Retry 10 times | ||
| start_period: 10s # Run checks during first 10 seconds | ||
| start_interval: 1s # Check every second during start_period (Docker 25.0+) | ||
| web: | ||
| build: . | ||
| ports: | ||
| - "5000:5000" | ||
| volumes: | ||
| - .:/code | ||
| - dtpstat:/var/run/dtpstat | ||
| working_dir: /code | ||
| # Старт: миграции + проверка суперпользователя + запуск сервера | ||
| command: > | ||
| sh -c " | ||
| python run-migrations.py && | ||
| python create_superuser.py && | ||
| python manage.py runserver 0.0.0.0:5000 | ||
| " | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| networks: | ||
| - backend | ||
| env_file: | ||
| - .env.example | ||
| restart: unless-stopped | ||
|
mlv-dev marked this conversation as resolved.
|
||
| qcluster: | ||
| build: . | ||
| command: > | ||
| sh -c " | ||
| while [ ! -f \"\${MIGRATIONS_FLAG_PATH:-/var/run/dtpstat/.migrations_done}\" ]; do sleep 1; done && | ||
| python manage.py qcluster | ||
| " | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| volumes: | ||
| - .:/code | ||
| - dtpstat:/var/run/dtpstat | ||
| working_dir: /code | ||
| depends_on: | ||
| db: | ||
| condition: service_healthy | ||
| networks: | ||
| - backend | ||
| env_file: | ||
| - .env.example | ||
| restart: unless-stopped | ||
| networks: | ||
| backend: | ||
| volumes: | ||
| pgdata: | ||
| dtpstat: | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
| import django | ||
| import fcntl | ||
| from django.core.management import call_command | ||
|
|
||
| # Путь к файлу-флагу (можно переопределить через MIGRATIONS_FLAG_PATH) | ||
| # По умолчанию используем каталог состояния приложения внутри контейнера | ||
| MIGRATIONS_FLAG_PATH = os.environ.get( | ||
| "MIGRATIONS_FLAG_PATH", | ||
| "/var/run/dtpstat/.migrations_done", | ||
| ) | ||
| MIGRATIONS_LOCK_PATH = os.environ.get( | ||
| "MIGRATIONS_LOCK_PATH", | ||
| f"{MIGRATIONS_FLAG_PATH}.lock", | ||
| ) | ||
| FLAG_FILE = Path(MIGRATIONS_FLAG_PATH) | ||
| LOCK_FILE = Path(MIGRATIONS_LOCK_PATH) | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Настройка Django | ||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dtpstat.settings") | ||
| django.setup() | ||
|
|
||
| # Проверяем, был ли уже первый запуск | ||
| if not FLAG_FILE.exists(): | ||
| print("Первый запуск контейнера: выполняем миграции...") | ||
| # Гарантируем наличие каталога для флага/лока заранее | ||
| FLAG_FILE.parent.mkdir(parents=True, exist_ok=True) | ||
| LOCK_FILE.parent.mkdir(parents=True, exist_ok=True) | ||
| try: | ||
| with open(LOCK_FILE, "w") as lock_fp: | ||
| fcntl.flock(lock_fp, fcntl.LOCK_EX) | ||
| # Повторная проверка под эксклюзивной блокировкой | ||
| if FLAG_FILE.exists(): | ||
| print("Миграции уже применены другим процессом, пропускаем.") | ||
| else: | ||
| call_command("migrate", interactive=False) | ||
| print("Миграции применены.") | ||
| FLAG_FILE.touch() # создаём флаг | ||
| except Exception as e: | ||
| import traceback | ||
| print("Ошибка при применении миграций:", e) | ||
| traceback.print_exc() | ||
| sys.exit(1) | ||
| else: | ||
| print("Миграции уже применены, пропускаем.") | ||
|
mlv-dev marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.