fix: switch to dev settings for Docker services and improve env config
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 10m27s
CI/CD Pipeline / Run Tests (push) Failing after 10m43s
CI/CD Pipeline / Build & Push Images (push) Successful in 7m28s
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Successful in 44s
Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 10m27s
CI/CD Pipeline / Run Tests (push) Failing after 10m43s
CI/CD Pipeline / Build & Push Images (push) Successful in 7m28s
CI/CD Pipeline / Deploy (prod) (push) Has been skipped
CI/CD Pipeline / Deploy (dev) (push) Successful in 44s
This commit is contained in:
16
.env.example
16
.env.example
@@ -2,24 +2,26 @@
|
||||
# Скопируйте этот файл в .env и измените значения по необходимости
|
||||
|
||||
# Django Settings
|
||||
DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
DEBUG=True
|
||||
SECRET_KEY=django-insecure-development-key-change-in-production
|
||||
SECRET_KEY=${SECRET_KEY:-django-insecure-dev-key-change-in-production}
|
||||
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
|
||||
|
||||
# Database Settings
|
||||
POSTGRES_DB=project_dev
|
||||
POSTGRES_DB=mostovik
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=postgres
|
||||
POSTGRES_HOST=localhost
|
||||
POSTGRES_HOST=127.0.0.1
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_SSLMODE=disable
|
||||
|
||||
# Redis Settings
|
||||
REDIS_URL=redis://localhost:6379/0
|
||||
REDIS_CACHE_URL=redis://localhost:6379/1
|
||||
REDIS_URL=redis://127.0.0.1:6379/0
|
||||
REDIS_CACHE_URL=redis://127.0.0.1:6379/1
|
||||
|
||||
# Celery Settings
|
||||
CELERY_BROKER_URL=redis://localhost:6379/0
|
||||
CELERY_RESULT_BACKEND=redis://localhost:6379/0
|
||||
CELERY_BROKER_URL=redis://127.0.0.1:6379/0
|
||||
CELERY_RESULT_BACKEND=redis://127.0.0.1:6379/0
|
||||
|
||||
# CORS Settings
|
||||
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
|
||||
|
||||
@@ -5,7 +5,7 @@ services:
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.dev
|
||||
- DEBUG=False
|
||||
- SECRET_KEY=${SECRET_KEY:-django-insecure-dev-key-change-in-production}
|
||||
- ALLOWED_HOSTS=*
|
||||
@@ -33,8 +33,8 @@ services:
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
- DEBUG=False
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.dev
|
||||
- DEBUG=True
|
||||
- SECRET_KEY=${SECRET_KEY:-django-insecure-dev-key-change-in-production}
|
||||
- POSTGRES_HOST=127.0.0.1
|
||||
- POSTGRES_PORT=5432
|
||||
@@ -55,7 +55,7 @@ services:
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
- DJANGO_SETTINGS_MODULE=config.settings.dev
|
||||
- DEBUG=False
|
||||
- SECRET_KEY=${SECRET_KEY:-django-insecure-dev-key-change-in-production}
|
||||
- POSTGRES_HOST=127.0.0.1
|
||||
|
||||
@@ -4,6 +4,6 @@ Django settings module.
|
||||
|
||||
# This will be overridden by the specific settings file
|
||||
try:
|
||||
from .development import *
|
||||
from .dev import *
|
||||
except ImportError:
|
||||
from .base import *
|
||||
|
||||
@@ -7,26 +7,17 @@ Generated by 'django-admin startproject' using Django 3.2.25.
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from decouple import Config, RepositoryEnv
|
||||
from .env import build_config, env_list
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
# BASE_DIR = .../project_root
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
|
||||
# Application version
|
||||
APP_VERSION = "1.0.0"
|
||||
|
||||
# Load environment variables
|
||||
ENV_FILE = BASE_DIR / ".env"
|
||||
if ENV_FILE.exists():
|
||||
config = Config(RepositoryEnv(str(ENV_FILE)))
|
||||
else:
|
||||
from decouple import AutoConfig
|
||||
|
||||
config = AutoConfig(search_path=BASE_DIR)
|
||||
config = build_config(BASE_DIR)
|
||||
|
||||
|
||||
# Helper function for getting config values
|
||||
def get_env(key, default=None):
|
||||
def get_env(key: str, default=None):
|
||||
return config(key, default=default)
|
||||
|
||||
|
||||
@@ -40,7 +31,10 @@ DEBUG = get_env("DEBUG", True)
|
||||
if isinstance(DEBUG, str):
|
||||
DEBUG = DEBUG.lower() in ("true", "1", "yes")
|
||||
|
||||
ALLOWED_HOSTS = get_env("ALLOWED_HOSTS", "localhost,127.0.0.1")
|
||||
ALLOWED_HOSTS = env_list(
|
||||
get_env("ALLOWED_HOSTS", "localhost,127.0.0.1"), default=["localhost", "127.0.0.1"]
|
||||
)
|
||||
|
||||
if isinstance(ALLOWED_HOSTS, str):
|
||||
ALLOWED_HOSTS = ALLOWED_HOSTS.split(",")
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@ ALLOWED_HOSTS = ["localhost", "127.0.0.1", "0.0.0.0", "testserver", "*"] # noqa
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"NAME": os.getenv("POSTGRES_DB", "project_dev"),
|
||||
"NAME": os.getenv("POSTGRES_DB", "mostovik"),
|
||||
"USER": os.getenv("POSTGRES_USER", "postgres"),
|
||||
"PASSWORD": os.getenv("POSTGRES_PASSWORD", "postgres"),
|
||||
"HOST": os.getenv("POSTGRES_HOST", "localhost"),
|
||||
"HOST": os.getenv("POSTGRES_HOST", "127.0.0.1"),
|
||||
"PORT": os.getenv("POSTGRES_PORT", "5432"),
|
||||
}
|
||||
}
|
||||
|
||||
# Celery Configuration for Development
|
||||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://localhost:6379/0")
|
||||
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://localhost:6379/0")
|
||||
CELERY_BROKER_URL = os.getenv("CELERY_BROKER_URL", "redis://127.0.0.1:6379/0")
|
||||
CELERY_RESULT_BACKEND = os.getenv("CELERY_RESULT_BACKEND", "redis://127.0.0.1:6379/0")
|
||||
CELERY_ACCEPT_CONTENT = ["json"]
|
||||
CELERY_TASK_SERIALIZER = "json"
|
||||
CELERY_RESULT_SERIALIZER = "json"
|
||||
@@ -39,7 +39,7 @@ CELERY_TIMEZONE = "Europe/Moscow"
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
# Cache configuration for development
|
||||
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/1")
|
||||
REDIS_URL = os.getenv("REDIS_URL", "redis://127.0.0.1:6379/1")
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django_redis.cache.RedisCache",
|
||||
53
src/config/settings/env.py
Normal file
53
src/config/settings/env.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from decouple import AutoConfig, Config, RepositoryEnv
|
||||
|
||||
|
||||
def build_config(base_dir: Path):
|
||||
env_file = base_dir / ".env"
|
||||
if env_file.exists():
|
||||
return Config(RepositoryEnv(str(env_file)))
|
||||
return AutoConfig(search_path=base_dir)
|
||||
|
||||
|
||||
def env_bool(value: Any, default: bool = False) -> bool:
|
||||
if value is None:
|
||||
return default
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, (int, float)):
|
||||
return bool(value)
|
||||
s = str(value).strip().lower()
|
||||
if s in {"1", "true", "yes", "y", "on"}:
|
||||
return True
|
||||
if s in {"0", "false", "no", "n", "off"}:
|
||||
return False
|
||||
return default
|
||||
|
||||
|
||||
def env_int(value: Any, default: int = 0) -> int:
|
||||
try:
|
||||
return int(str(value).strip())
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def env_list(value: Any, default: Iterable[str] = ()) -> list[str]:
|
||||
"""
|
||||
Поддерживает:
|
||||
- "a,b,c"
|
||||
- "a, b, c"
|
||||
- пустые значения
|
||||
"""
|
||||
if value is None:
|
||||
return list(default)
|
||||
if isinstance(value, (list, tuple, set)):
|
||||
return [str(x).strip() for x in value if str(x).strip()]
|
||||
s = str(value).strip()
|
||||
if not s:
|
||||
return list(default)
|
||||
return [p.strip() for p in s.split(",") if p.strip()]
|
||||
@@ -11,6 +11,6 @@ import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.dev")
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
||||
Reference in New Issue
Block a user