## Scripts de Base de Datos (12 archivos) - init-database.sh: Inicializacion completa con usuario y BD - init-database-v3.sh: Version con dotenv-vault - reset-database.sh: Reset BD manteniendo usuario - recreate-database.sh: Recreacion completa - cleanup-duplicados.sh, fix-duplicate-triggers.sh - verify-users.sh, verify-missions-status.sh - load-users-and-profiles.sh, DB-127-validar-gaps.sh ## Scripts de Produccion (5 archivos) - build-production.sh: Compilar backend y frontend - deploy-production.sh: Desplegar con PM2 - pre-deploy-check.sh: Validaciones pre-deploy - repair-missing-data.sh: Reparar datos faltantes - migrate-missing-objects.sh: Migrar objetos SQL ## Documentacion (7 archivos) - GUIA-DESPLIEGUE-PRODUCCION-COMPLETA.md - GUIA-ACTUALIZACION-PRODUCCION.md - GUIA-VALIDACION-PRODUCCION.md - GUIA-DEPLOYMENT-AGENTE-PRODUCCION.md - GUIA-SSL-NGINX-PRODUCCION.md - GUIA-SSL-AUTOFIRMADO.md - DIRECTIVA-DEPLOYMENT.md ## Actualizaciones DDL/Seeds - 99-post-ddl-permissions.sql: Permisos actualizados - LOAD-SEEDS-gamification_system.sh: Seeds completos ## Nuevos archivos - PROMPT-AGENTE-PRODUCCION.md: Prompt para agente productivo - FLUJO-CARGA-LIMPIA.md: Documentacion de carga limpia Resuelve: Problema de carga de BD entre dev y produccion Cumple: DIRECTIVA-POLITICA-CARGA-LIMPIA.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4.1 KiB
4.1 KiB
DIRECTIVA: Deployment en Producción
Versión: 1.0 Servidor: 74.208.126.102 Ejecutar después de: Backup configs + Pull + Restaurar configs
PREREQUISITOS
Antes de ejecutar esta directiva, debes haber completado:
- Backup de configuraciones en ../backups/TIMESTAMP/
- Pull del repositorio (git reset --hard origin/master)
- Restauración de .env.production desde backup
PROCESO DE DEPLOYMENT
PASO 1: Verificar SSL/Nginx
# Verificar si Nginx está instalado y corriendo
if ! command -v nginx &> /dev/null; then
echo "Nginx no instalado. Ejecutar GUIA-SSL-AUTOFIRMADO.md primero"
exit 1
fi
if ! systemctl is-active --quiet nginx; then
echo "Nginx no está corriendo. Iniciando..."
sudo systemctl start nginx
fi
# Verificar certificado SSL existe
if [ ! -f /etc/nginx/ssl/gamilit.crt ]; then
echo "Certificado SSL no encontrado. Ejecutar GUIA-SSL-AUTOFIRMADO.md"
exit 1
fi
echo "✓ SSL/Nginx configurado"
PASO 2: Recrear Base de Datos
cd apps/database
chmod +x create-database.sh
./create-database.sh
cd ../..
echo "✓ Base de datos recreada"
PASO 3: Instalar Dependencias
# Backend
cd apps/backend
npm install --production=false
cd ../..
# Frontend
cd apps/frontend
npm install --production=false
cd ../..
echo "✓ Dependencias instaladas"
PASO 4: Build
# Backend
cd apps/backend
npm run build
cd ../..
# Frontend
cd apps/frontend
npm run build
cd ../..
echo "✓ Build completado"
PASO 5: Iniciar Servicios con PM2
pm2 start ecosystem.config.js --env production
pm2 save
pm2 list
echo "✓ Servicios iniciados"
PASO 6: Validación
# Esperar a que los servicios inicien
sleep 5
# Health check backend (interno)
echo "=== Health Check Backend (interno) ==="
curl -s http://localhost:3006/api/v1/health | head -10
# Health check frontend (interno)
echo "=== Health Check Frontend (interno) ==="
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" http://localhost:3005
# Health check via Nginx (HTTPS)
echo "=== Health Check HTTPS ==="
curl -sk https://74.208.126.102/api/v1/health | head -10
echo "=== Frontend HTTPS ==="
curl -sk -o /dev/null -w "HTTP Status: %{http_code}\n" https://74.208.126.102
# PM2 status
echo "=== PM2 Status ==="
pm2 list
# Logs recientes
echo "=== Logs Recientes ==="
pm2 logs --lines 10 --nostream
CONFIGURACIÓN ESPERADA
Puertos
| Servicio | Puerto | Protocolo |
|---|---|---|
| Backend | 3006 | HTTP (interno) |
| Frontend | 3005 | HTTP (interno) |
| Nginx | 443 | HTTPS (externo) |
URLs de Acceso
| Servicio | URL |
|---|---|
| Frontend | https://74.208.126.102 |
| Backend API | https://74.208.126.102/api/v1 |
| Health Check | https://74.208.126.102/api/v1/health |
SI FALLA ALGO
Error en Base de Datos
# Verificar PostgreSQL
sudo systemctl status postgresql
PGPASSWORD="$DB_PASSWORD" psql -h localhost -U gamilit_user -d gamilit_platform -c "SELECT 1"
Error en Build
# Ver logs de error
cd apps/backend && npm run build 2>&1 | tail -50
cd apps/frontend && npm run build 2>&1 | tail -50
Error en PM2
pm2 logs gamilit-backend --err --lines 50
pm2 logs gamilit-frontend --err --lines 50
Error en Nginx/SSL
sudo nginx -t
sudo systemctl status nginx
curl -vk https://74.208.126.102:3006/api/v1/health
Rollback Completo
pm2 stop all
# Restaurar configs
cp "../backups/latest/config/backend.env.production" apps/backend/.env.production
cp "../backups/latest/config/frontend.env.production" apps/frontend/.env.production
# Rebuild
cd apps/backend && npm run build && cd ../..
cd apps/frontend && npm run build && cd ../..
# Reiniciar
pm2 start ecosystem.config.js --env production
CHECKLIST FINAL
- Nginx corriendo con SSL
- Base de datos recreada
- Backend build exitoso
- Frontend build exitoso
- PM2 servicios online
- Health check backend OK
- Health check frontend OK
- HTTPS funcionando en :3005 y :3006
Directiva creada: 2025-12-18