feat: integración final de Jenkins con inyección de .env segura
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
All checks were successful
DEPLOY_MULTI_BRACH/pipeline/head This commit looks good
This commit is contained in:
@@ -3,35 +3,30 @@ import os
|
||||
from dotenv import load_dotenv
|
||||
from datetime import timedelta
|
||||
|
||||
# Cargar variables desde el archivo .env
|
||||
load_dotenv()
|
||||
# 1. RUTA DEL SETTINGS Y CARGA DEL .ENV
|
||||
# Obtenemos la ruta de la carpeta donde está este archivo (core/)
|
||||
CURRENT_DIR = Path(__file__).resolve().parent
|
||||
BASE_DIR = CURRENT_DIR.parent
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
# Cargamos el .env específico de esta carpeta (core/.env)
|
||||
load_dotenv(dotenv_path=CURRENT_DIR / '.env')
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-change-me-for-production')
|
||||
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-default-key-change-it')
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = os.getenv('DEBUG', 'True').lower() == 'true'
|
||||
|
||||
# Constants from .env
|
||||
DB_NAME = os.getenv('DB_NAME')
|
||||
DB_USER = os.getenv('DB_USER')
|
||||
DB_PASSWORD = os.getenv('DB_PASSWORD')
|
||||
DB_HOST = os.getenv('DB_HOST')
|
||||
DB_PORT = os.getenv('DB_PORT')
|
||||
# Mejoramos el parseo de DEBUG para que no falle si viene como string
|
||||
DEBUG = os.getenv('DEBUG', 'True').lower() in ('true', '1', 't')
|
||||
|
||||
# 2. ALLOWED HOSTS
|
||||
# Limpiamos y centralizamos los hosts permitidos
|
||||
ALLOWED_HOSTS = [
|
||||
'v-encore-lab.com',
|
||||
'dev.v-encore-lab.com',
|
||||
'185.187.169.109', # Añade la IP aquí
|
||||
'185.187.169.109',
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'django_app_dev',
|
||||
'django_app_master',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken'
|
||||
os.getenv('APP_CONTAINER_NAME', 'django_app_dev'), # Dinámico para Docker
|
||||
]
|
||||
|
||||
# Application definition
|
||||
@@ -42,12 +37,16 @@ INSTALLED_APPS = [
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
# Plugins
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'corsheaders',
|
||||
|
||||
# Tus Apps (Asegúrate de que el path sea correcto)
|
||||
'apps.promociones',
|
||||
'apps.backend_admin',
|
||||
'apps.common',
|
||||
'corsheaders',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -81,15 +80,16 @@ TEMPLATES = [
|
||||
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
|
||||
# Database
|
||||
# 3. DATABASE
|
||||
# Extraemos con fallback por si el .env falla
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': DB_PORT,
|
||||
'NAME': os.getenv('DB_NAME', 'postgres'),
|
||||
'USER': os.getenv('DB_USER', 'postgres'),
|
||||
'PASSWORD': os.getenv('DB_PASSWORD', ''),
|
||||
'HOST': os.getenv('DB_HOST', 'localhost'),
|
||||
'PORT': os.getenv('DB_PORT', '5432'),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ TIME_ZONE = 'Europe/Madrid'
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# Static files
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
|
||||
@@ -120,27 +120,43 @@ SIMPLE_JWT = {
|
||||
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
|
||||
}
|
||||
|
||||
# CORS
|
||||
CORS_ALLOW_ALL_ORIGINS = True
|
||||
# CORS & CSRF
|
||||
CORS_ALLOW_ALL_ORIGINS = DEBUG # Solo permitir todo en modo DEBUG
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'chrome-extension://amknoiejhlmhancpahfcfcfhllgkpbld',
|
||||
'https://v-encore-lab.com',
|
||||
'http://localhost:8000',
|
||||
'http://127.0.0.1:8000',
|
||||
]
|
||||
|
||||
# Logging
|
||||
# Logging simplificado
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '{levelname} {asctime} {module} {message}',
|
||||
'style': '{',
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose',
|
||||
},
|
||||
},
|
||||
'loggers': {
|
||||
'': {
|
||||
'handlers': ['console'],
|
||||
'level': 'INFO',
|
||||
'level': os.getenv('LOG_LEVEL', 'INFO'),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
# --- CONFIGURACIONES PERSONALIZADAS DE LA APP ---
|
||||
|
||||
# Leemos la variable del .env (cargado previamente con load_dotenv)
|
||||
# Ponemos un valor por defecto por si se nos olvida ponerlo en el .env
|
||||
APP_CUSTOM_SETTING = os.getenv('APP_CUSTOM_SETTING', 'valor_por_defecto_seguro')
|
||||
|
||||
# Ejemplo de otra variable de API
|
||||
EXTERNAL_SERVICE_API_KEY = os.getenv('EXTERNAL_SERVICE_API_KEY', None)
|
||||
Reference in New Issue
Block a user