Merge pull request 'dev' (#28) from dev into master
Some checks failed
DEPLOY_MULTI_BRACH/pipeline/head There was a failure building this commit

Reviewed-on: #28
This commit is contained in:
2026-04-11 23:02:30 +02:00
3 changed files with 32 additions and 29 deletions

View File

@@ -1,6 +1,6 @@
# django-core-base # django-core-base
// V-Encore Lab: Sistema Automatizado v1.0. // V-Encore Lab: Sistema Automatizado v1.0.3

View File

@@ -5,14 +5,13 @@ pipeline {
stage('Configurar Entorno') { stage('Configurar Entorno') {
steps { steps {
script { script {
// Aquí asignamos las variables directamente al entorno global de la ejecución
if (env.BRANCH_NAME == 'master') { if (env.BRANCH_NAME == 'master') {
echo "--- MODO PRODUCCIÓN DETECTADO ---" env.PROJECT_NAME = "django_master" // <--- Nombre único
env.CONTAINER_NAME = "django_app_master" env.CONTAINER_NAME = "django_app_master"
env.PORT = "8001" env.PORT = "8001"
env.DEBUG_MODE = "0" env.DEBUG_MODE = "0"
} else if (env.BRANCH_NAME == 'dev') { } else {
echo "--- MODO DESARROLLO DETECTADO ---" env.PROJECT_NAME = "django_dev" // <--- Nombre único
env.CONTAINER_NAME = "django_app_dev" env.CONTAINER_NAME = "django_app_dev"
env.PORT = "8000" env.PORT = "8000"
env.DEBUG_MODE = "1" env.DEBUG_MODE = "1"
@@ -22,17 +21,22 @@ pipeline {
} }
stage('Despliegue') { stage('Despliegue') {
when { when { anyOf { branch 'dev'; branch 'master' } }
anyOf { branch 'dev'; branch 'master' } steps {
} echo "DESPLEGANDO: ${env.CONTAINER_NAME} en el puerto ${env.PORT}"
steps {
echo "EJECUTANDO DOCKER: ${env.CONTAINER_NAME} en el puerto ${env.PORT}"
// Forzamos a Docker a leer las variables y usamos un nombre de proyecto fijo (-p) // 1. Levantamos el contenedor con su nombre de proyecto único (-p)
// Busca esta línea en tu Jenkinsfile y añade el final: sh """
sh "CONTAINER_NAME=${CONTAINER_NAME} PORT=${PORT} DEBUG_MODE=${DEBUG_MODE} docker compose -p django_bac -f deployments/docker-compose.yml up -d --build web" CONTAINER_NAME=${env.CONTAINER_NAME} \
} PORT=${env.PORT} \
} DEBUG_MODE=${env.DEBUG_MODE} \
docker compose -p ${env.PROJECT_NAME} -f deployments/docker-compose.yml up -d --build web
"""
// 2. Ejecutamos migraciones automáticamente al terminar
echo "Ejecutando migraciones en ${env.CONTAINER_NAME}..."
sh "docker exec ${env.CONTAINER_NAME} python manage.py migrate --noinput"
}
}
} }
} }
// Automatización activada

View File

@@ -5,22 +5,21 @@ services:
dockerfile: deployments/Dockerfile dockerfile: deployments/Dockerfile
container_name: ${CONTAINER_NAME} container_name: ${CONTAINER_NAME}
restart: always restart: always
working_dir: /app # <--- Vital para que encuentre 'core'
environment: environment:
- DEBUG=${DEBUG_MODE} - DEBUG=${DEBUG_MODE}
# Piezas sueltas para Django: - PYTHONPATH=/app # <--- Asegura que Python vea las carpetas
- DB_NAME=gitea - DB_NAME=gitea
- DB_USER=gitea - DB_USER=gitea
- DB_PASSWORD=gitea - DB_PASSWORD=gitea
- DB_HOST=gitea-db-1 - DB_HOST=gitea-db-1
- DB_PORT=5432 - DB_PORT=5432
# Mantenemos esta por si acaso la usas en otro sitio:
- DATABASE_URL=postgres://gitea:gitea@gitea-db-1:5432/gitea
networks: networks:
- gitea_net # Nombre interno para este archivo - gitea_net
ports: ports:
- "${PORT}:8000" - "${PORT}:8000"
networks: networks:
gitea_net: gitea_net:
external: true external: true
name: frontend # <--- Este es el nombre real que vimos en el JSON name: frontend