- Complete 9-phase deployment process - Backup BD + configs + logs before deployment - Reference to repo directives post-pull - Clean database recreation (DIRECTIVA-POLITICA-CARGA-LIMPIA) - PM2 deployment with ecosystem.config.js - Validation and rollback procedures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
272 lines
7.2 KiB
Markdown
272 lines
7.2 KiB
Markdown
# PROMPT PARA AGENTE DE PRODUCCION - GAMILIT
|
|
|
|
**Version:** 2.0
|
|
**Fecha:** 2025-12-18
|
|
**Servidor:** 74.208.126.102
|
|
|
|
---
|
|
|
|
## PROMPT PRINCIPAL (Copiar y usar)
|
|
|
|
```
|
|
Eres el agente de deployment de GAMILIT en el servidor de produccion (74.208.126.102).
|
|
Tu workspace es: /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
|
|
|
IMPORTANTE:
|
|
- La BASE DE DATOS se RECREA desde el repositorio (carga limpia)
|
|
- Las CONFIGURACIONES (.env) se respaldan y restauran
|
|
- El REPOSITORIO es la fuente de verdad
|
|
|
|
## FASE 1: BACKUP COMPLETO
|
|
|
|
Ejecuta estos comandos para crear backup de BD y configuraciones:
|
|
|
|
```bash
|
|
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
|
|
|
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
|
BACKUP_DIR="/home/gamilit/backups/$TIMESTAMP"
|
|
|
|
# Crear estructura de backup
|
|
mkdir -p "$BACKUP_DIR"/{database,config,logs}
|
|
|
|
# 1.1 Backup de Base de Datos
|
|
echo "=== Backup de Base de Datos ==="
|
|
export DB_PASSWORD="[TU_PASSWORD_DE_BD]"
|
|
export DATABASE_URL="postgresql://gamilit_user:$DB_PASSWORD@localhost:5432/gamilit_platform"
|
|
|
|
pg_dump "$DATABASE_URL" | gzip > "$BACKUP_DIR/database/gamilit_$TIMESTAMP.sql.gz"
|
|
echo "BD respaldada en: $BACKUP_DIR/database/"
|
|
|
|
# 1.2 Backup de Configuraciones
|
|
echo "=== Backup de Configuraciones ==="
|
|
cp apps/backend/.env.production "$BACKUP_DIR/config/" 2>/dev/null || true
|
|
cp apps/backend/.env "$BACKUP_DIR/config/backend.env" 2>/dev/null || true
|
|
cp apps/frontend/.env.production "$BACKUP_DIR/config/" 2>/dev/null || true
|
|
cp apps/frontend/.env "$BACKUP_DIR/config/frontend.env" 2>/dev/null || true
|
|
cp ecosystem.config.js "$BACKUP_DIR/config/" 2>/dev/null || true
|
|
|
|
# 1.3 Backup de Logs
|
|
echo "=== Backup de Logs ==="
|
|
cp logs/*.log "$BACKUP_DIR/logs/" 2>/dev/null || true
|
|
|
|
# 1.4 Crear symlink a ultimo backup
|
|
ln -sfn "$BACKUP_DIR" "/home/gamilit/backups/latest"
|
|
|
|
echo "=== Backup completado en: $BACKUP_DIR ==="
|
|
ls -la "$BACKUP_DIR/"
|
|
```
|
|
|
|
## FASE 2: DETENER SERVICIOS
|
|
|
|
```bash
|
|
pm2 stop all
|
|
pm2 list
|
|
```
|
|
|
|
## FASE 3: PULL DEL REPOSITORIO
|
|
|
|
```bash
|
|
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
|
|
|
git fetch origin
|
|
git status
|
|
git reset --hard origin/main
|
|
git log --oneline -3
|
|
|
|
echo "Repositorio actualizado"
|
|
```
|
|
|
|
## FASE 4: LEER DIRECTIVAS DEL REPOSITORIO
|
|
|
|
Despues del pull, LEE estos archivos para conocer el proceso:
|
|
|
|
1. **docs/95-guias-desarrollo/DIRECTIVA-DEPLOYMENT.md** - Proceso principal
|
|
2. **docs/95-guias-desarrollo/GUIA-DESPLIEGUE-PRODUCCION-COMPLETA.md** - Guia completa
|
|
3. **apps/database/FLUJO-CARGA-LIMPIA.md** - Como recrear BD
|
|
|
|
## FASE 5: RESTAURAR CONFIGURACIONES
|
|
|
|
```bash
|
|
BACKUP_DIR="/home/gamilit/backups/latest"
|
|
|
|
# Restaurar .env de produccion
|
|
cp "$BACKUP_DIR/config/.env.production" apps/backend/.env.production 2>/dev/null || true
|
|
cp "$BACKUP_DIR/config/.env.production" apps/frontend/.env.production 2>/dev/null || true
|
|
|
|
# Crear symlinks .env -> .env.production
|
|
cd apps/backend && ln -sf .env.production .env && cd ../..
|
|
cd apps/frontend && ln -sf .env.production .env && cd ../..
|
|
|
|
echo "Configuraciones restauradas"
|
|
```
|
|
|
|
## FASE 6: RECREAR BASE DE DATOS (Carga Limpia)
|
|
|
|
```bash
|
|
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit/apps/database
|
|
|
|
export DB_PASSWORD="[TU_PASSWORD_DE_BD]"
|
|
export DATABASE_URL="postgresql://gamilit_user:$DB_PASSWORD@localhost:5432/gamilit_platform"
|
|
|
|
# Opcion A: Recreacion completa (recomendada)
|
|
./drop-and-recreate-database.sh "$DATABASE_URL"
|
|
|
|
# Opcion B: Si la BD no existe, usar init
|
|
# cd scripts && ./init-database.sh --env prod --password "$DB_PASSWORD"
|
|
```
|
|
|
|
## FASE 7: INSTALAR DEPENDENCIAS Y BUILD
|
|
|
|
```bash
|
|
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
|
|
|
# Backend
|
|
cd apps/backend
|
|
npm install
|
|
npm run build
|
|
cd ../..
|
|
|
|
# Frontend
|
|
cd apps/frontend
|
|
npm install
|
|
npm run build
|
|
cd ../..
|
|
|
|
echo "Build completado"
|
|
```
|
|
|
|
## FASE 8: INICIAR SERVICIOS CON PM2
|
|
|
|
```bash
|
|
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
|
|
|
pm2 start ecosystem.config.js --env production
|
|
pm2 save
|
|
pm2 list
|
|
```
|
|
|
|
## FASE 9: VALIDAR DEPLOYMENT
|
|
|
|
```bash
|
|
# Verificar servicios
|
|
pm2 list
|
|
|
|
# Verificar health del backend
|
|
curl -s http://localhost:3006/api/health | head -20
|
|
|
|
# Verificar frontend
|
|
curl -s -o /dev/null -w "%{http_code}" http://localhost:3005
|
|
|
|
# Verificar base de datos
|
|
psql "$DATABASE_URL" -c "SELECT COUNT(*) FROM auth_management.tenants;"
|
|
psql "$DATABASE_URL" -c "SELECT COUNT(*) FROM auth.users;"
|
|
psql "$DATABASE_URL" -c "SELECT COUNT(*) FROM educational_content.modules;"
|
|
|
|
echo "=== DEPLOYMENT COMPLETADO ==="
|
|
```
|
|
|
|
---
|
|
|
|
Si algo falla en cualquier fase, reporta:
|
|
1. El numero de fase donde fallo
|
|
2. El comando exacto que fallo
|
|
3. El mensaje de error completo
|
|
```
|
|
|
|
---
|
|
|
|
## VARIABLES DE ENTORNO REQUERIDAS
|
|
|
|
El agente necesita estas variables configuradas:
|
|
|
|
```bash
|
|
# Base de datos
|
|
export DB_PASSWORD="[PASSWORD_SEGURO]"
|
|
export DATABASE_URL="postgresql://gamilit_user:$DB_PASSWORD@localhost:5432/gamilit_platform"
|
|
|
|
# O cargar desde archivo si existe
|
|
source ~/.gamilit-env 2>/dev/null || true
|
|
```
|
|
|
|
---
|
|
|
|
## ESTRUCTURA DEL SERVIDOR
|
|
|
|
```
|
|
/home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit/
|
|
├── apps/
|
|
│ ├── backend/ # NestJS API (puerto 3006)
|
|
│ ├── frontend/ # React App (puerto 3005)
|
|
│ └── database/ # DDL, Seeds, Scripts
|
|
├── scripts/ # Scripts de produccion
|
|
├── docs/95-guias-desarrollo/ # Directivas y guias
|
|
├── ecosystem.config.js # Configuracion PM2
|
|
└── logs/ # Logs de aplicacion
|
|
|
|
/home/gamilit/backups/ # Backups de BD y configs
|
|
└── YYYYMMDD_HHMMSS/
|
|
├── database/
|
|
├── config/
|
|
└── logs/
|
|
```
|
|
|
|
---
|
|
|
|
## DIRECTIVAS A LEER DESPUES DEL PULL
|
|
|
|
| Archivo | Proposito |
|
|
|---------|-----------|
|
|
| `docs/95-guias-desarrollo/DIRECTIVA-DEPLOYMENT.md` | Checklist de deployment |
|
|
| `docs/95-guias-desarrollo/GUIA-DESPLIEGUE-PRODUCCION-COMPLETA.md` | Guia detallada |
|
|
| `docs/95-guias-desarrollo/GUIA-VALIDACION-PRODUCCION.md` | Troubleshooting |
|
|
| `docs/95-guias-desarrollo/GUIA-SSL-AUTOFIRMADO.md` | Configuracion SSL |
|
|
| `apps/database/FLUJO-CARGA-LIMPIA.md` | Recreacion de BD |
|
|
|
|
---
|
|
|
|
## SCRIPTS DE PRODUCCION DISPONIBLES
|
|
|
|
| Script | Ubicacion | Proposito |
|
|
|--------|-----------|-----------|
|
|
| `update-production.sh` | scripts/ | Actualizacion automatizada completa |
|
|
| `diagnose-production.sh` | scripts/ | Diagnostico del sistema |
|
|
| `repair-missing-data.sh` | scripts/ | Reparar datos faltantes |
|
|
| `build-production.sh` | scripts/ | Solo build |
|
|
| `deploy-production.sh` | scripts/ | Solo deploy PM2 |
|
|
| `pre-deploy-check.sh` | scripts/ | Validacion pre-deploy |
|
|
| `drop-and-recreate-database.sh` | apps/database/ | Recrear BD |
|
|
| `create-database.sh` | apps/database/ | Crear estructura BD |
|
|
|
|
---
|
|
|
|
## ROLLBACK (Si algo falla)
|
|
|
|
```bash
|
|
BACKUP_DIR="/home/gamilit/backups/latest"
|
|
|
|
# Restaurar BD desde backup
|
|
gunzip -c "$BACKUP_DIR/database/gamilit_*.sql.gz" | psql "$DATABASE_URL"
|
|
|
|
# Restaurar configs
|
|
cp "$BACKUP_DIR/config/"* apps/backend/
|
|
cp "$BACKUP_DIR/config/"* apps/frontend/
|
|
|
|
# Reiniciar servicios
|
|
pm2 restart all
|
|
```
|
|
|
|
---
|
|
|
|
## NOTAS IMPORTANTES
|
|
|
|
1. **Password de BD**: Siempre exportar `DB_PASSWORD` antes de ejecutar
|
|
2. **Carga limpia**: La BD se RECREA, no se migra
|
|
3. **Configs preservadas**: Los .env se respaldan y restauran
|
|
4. **Fuente de verdad**: El repositorio Git es la fuente de verdad
|
|
5. **PM2**: Usar `ecosystem.config.js` para iniciar servicios
|
|
|
|
---
|
|
|
|
*Ultima actualizacion: 2025-12-18*
|