From 9a07a7b9b387e58a629f005d6cf1f299068c324d Mon Sep 17 00:00:00 2001 From: urieljareth Date: Thu, 13 Aug 2026 15:03:25 -0600 Subject: [PATCH] fix: compliance con directrices de red coolify y limpieza de variables de entorno --- .env.coolify.example | 7 +++-- .env.example | 11 +++---- docker-compose.coolify.yml | 60 ++++++++++++++++++++++---------------- docker-compose.yml | 49 +++++++++++++++++-------------- 4 files changed, 70 insertions(+), 57 deletions(-) diff --git a/.env.coolify.example b/.env.coolify.example index 21cdcef..763fa61 100644 --- a/.env.coolify.example +++ b/.env.coolify.example @@ -1,8 +1,9 @@ -# Variables de Entorno para Coolify +# Variables de Entorno para Producción en Coolify PORT=3000 NODE_ENV=production +POSTGRES_HOST=db +POSTGRES_PORT=5432 POSTGRES_DB=encuesta_e3 POSTGRES_USER=postgres -POSTGRES_PASSWORD=postgres_password_e3 -DATABASE_URL=postgresql://postgres:postgres_password_e3@db:5432/encuesta_e3 +POSTGRES_PASSWORD=your_coolify_postgres_password ADMIN_SECRET=RESETEOE3 diff --git a/.env.example b/.env.example index 9494cd6..323410d 100644 --- a/.env.example +++ b/.env.example @@ -1,17 +1,14 @@ -# Configuración del Servidor y Base de Datos PostgreSQL +# Variables de Entorno - Encuesta de Votación Consultoría E3 PORT=3000 NODE_ENV=production -# Conexión PostgreSQL (Formato URL o componentes individuales) -DATABASE_URL=postgresql://postgres:postgres_password_e3@db:5432/encuesta_e3 - -# Variables alternativas de PostgreSQL +# Configuración de Base de Datos PostgreSQL POSTGRES_HOST=db POSTGRES_PORT=5432 POSTGRES_DB=encuesta_e3 POSTGRES_USER=postgres -POSTGRES_PASSWORD=postgres_password_e3 +POSTGRES_PASSWORD=your_secure_password_here DATABASE_SSL=false -# Clave secreta para funciones de administrador (Restablecer votos) +# Clave secreta para panel de administración (Restablecer votos) ADMIN_SECRET=RESETEOE3 diff --git a/docker-compose.coolify.yml b/docker-compose.coolify.yml index d52bb30..4b7ade8 100644 --- a/docker-compose.coolify.yml +++ b/docker-compose.coolify.yml @@ -1,44 +1,54 @@ +# Docker Compose optimizado para despliegue en Coolify +# Cumple con todas las directrices de docs/AGENTS-coolify-apps.md + services: web: - build: - context: . - dockerfile: Dockerfile + build: . restart: unless-stopped - ports: - - "3000:3000" + expose: + - "3000" environment: - - NODE_ENV=production - - PORT=3000 - - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres_password_e3}@db:5432/${POSTGRES_DB:-encuesta_e3} - - ADMIN_SECRET=${ADMIN_SECRET:-RESETEOE3} + NODE_ENV: production + PORT: "3000" + POSTGRES_HOST: db + POSTGRES_PORT: "5432" + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ADMIN_SECRET: ${ADMIN_SECRET} + healthcheck: + test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"] + interval: 20s + timeout: 5s + retries: 3 + start_period: 15s depends_on: - db: - condition: service_healthy + - db networks: - - app-network + - coolify db: image: postgres:16-alpine restart: unless-stopped environment: - - POSTGRES_DB=${POSTGRES_DB:-encuesta_e3} - - POSTGRES_USER=${POSTGRES_USER:-postgres} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres_password_e3} + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - - postgres_data:/var/lib/postgresql/data + - encuesta-db-data:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER:-postgres} -d $${POSTGRES_DB:-encuesta_e3}"] - interval: 5s + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 10s timeout: 5s retries: 5 start_period: 10s networks: - - app-network - -networks: - app-network: - driver: bridge + - coolify volumes: - postgres_data: - driver: local + encuesta-db-data: {} + +networks: + coolify: + name: coolify + external: true diff --git a/docker-compose.yml b/docker-compose.yml index 3169405..7084094 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,43 +1,48 @@ services: web: - build: - context: . - dockerfile: Dockerfile + build: . + restart: unless-stopped ports: - "3000:3000" environment: - - NODE_ENV=production - - PORT=3000 - - DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres_password_e3}@db:5432/${POSTGRES_DB:-encuesta_e3} - - ADMIN_SECRET=${ADMIN_SECRET:-RESETEOE3} + NODE_ENV: production + PORT: "3000" + POSTGRES_HOST: db + POSTGRES_PORT: "5432" + POSTGRES_DB: ${POSTGRES_DB:-encuesta_e3} + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres_local_password} + ADMIN_SECRET: ${ADMIN_SECRET:-RESETEOE3} + healthcheck: + test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"] + interval: 20s + timeout: 5s + retries: 3 + start_period: 15s depends_on: - db: - condition: service_healthy + - db networks: - - app-network + - default db: image: postgres:16-alpine + restart: unless-stopped ports: - "5432:5432" environment: - - POSTGRES_DB=${POSTGRES_DB:-encuesta_e3} - - POSTGRES_USER=${POSTGRES_USER:-postgres} - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres_password_e3} + POSTGRES_DB: ${POSTGRES_DB:-encuesta_e3} + POSTGRES_USER: ${POSTGRES_USER:-postgres} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres_local_password} volumes: - - postgres_data:/var/lib/postgresql/data + - encuesta-db-data-local:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER:-postgres} -d $${POSTGRES_DB:-encuesta_e3}"] - interval: 5s + test: ["CMD-SHELL", "pg_isready -U postgres -d encuesta_e3"] + interval: 10s timeout: 5s retries: 5 start_period: 10s networks: - - app-network - -networks: - app-network: - driver: bridge + - default volumes: - postgres_data: + encuesta-db-data-local: {}