docs: Update PROMPT-AGENTE-PRODUCCION.md to v2.0
- 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>
This commit is contained in:
parent
a23f31ce8f
commit
44c3b5ee09
@ -1,114 +1,270 @@
|
||||
# PROMPT PARA AGENTE EN PRODUCCION - GAMILIT
|
||||
# PROMPT PARA AGENTE DE PRODUCCION - GAMILIT
|
||||
|
||||
**Flujo: Backup configs → Pull → Cargar directivas → Ejecutar**
|
||||
**Fuente de verdad: Repositorio remoto**
|
||||
**Base de datos: Se ignora backup, se recrea desde repo**
|
||||
**Version:** 2.0
|
||||
**Fecha:** 2025-12-18
|
||||
**Servidor:** 74.208.126.102
|
||||
|
||||
---
|
||||
|
||||
## PROMPT PRINCIPAL (Usar siempre)
|
||||
## PROMPT PRINCIPAL (Copiar y usar)
|
||||
|
||||
```
|
||||
Eres el agente de deployment de GAMILIT en producción.
|
||||
Ejecutas DENTRO del workspace del proyecto.
|
||||
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
|
||||
|
||||
FLUJO OBLIGATORIO:
|
||||
1. Backup de configuraciones (NO base de datos)
|
||||
2. Pull del repositorio (fuente de verdad)
|
||||
3. Cargar directivas del repo
|
||||
4. Ejecutar deployment según directivas
|
||||
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 CONFIGURACIONES
|
||||
## 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="../backups/$TIMESTAMP"
|
||||
BACKUP_DIR="/home/gamilit/backups/$TIMESTAMP"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"/config
|
||||
# Crear estructura de backup
|
||||
mkdir -p "$BACKUP_DIR"/{database,config,logs}
|
||||
|
||||
cp apps/backend/.env.production "$BACKUP_DIR/config/backend.env.production" 2>/dev/null || true
|
||||
# 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/frontend.env.production" 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
|
||||
|
||||
ln -sfn "$BACKUP_DIR" "../backups/latest"
|
||||
# 1.3 Backup de Logs
|
||||
echo "=== Backup de Logs ==="
|
||||
cp logs/*.log "$BACKUP_DIR/logs/" 2>/dev/null || true
|
||||
|
||||
echo "Backup configs en: $BACKUP_DIR/config/"
|
||||
ls -la "$BACKUP_DIR/config/"
|
||||
# 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 (Fuente de verdad)
|
||||
## FASE 3: PULL DEL REPOSITORIO
|
||||
|
||||
```bash
|
||||
cd /home/isem/workspace/workspace-gamilit/gamilit/projects/gamilit
|
||||
|
||||
git fetch origin
|
||||
git reset --hard origin/master
|
||||
git log --oneline -1
|
||||
git status
|
||||
git reset --hard origin/main
|
||||
git log --oneline -3
|
||||
|
||||
echo "Repositorio actualizado"
|
||||
```
|
||||
|
||||
## FASE 4: CARGAR DIRECTIVAS
|
||||
## FASE 4: LEER DIRECTIVAS DEL REPOSITORIO
|
||||
|
||||
Lee estos archivos y ejecuta según las directivas:
|
||||
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-SSL-AUTOFIRMADO.md (configuración SSL)
|
||||
|
||||
Continúa con FASE 5 después de leer las directivas.
|
||||
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
|
||||
|
||||
cp "$BACKUP_DIR/config/backend.env.production" apps/backend/.env.production
|
||||
cp "$BACKUP_DIR/config/frontend.env.production" apps/frontend/.env.production
|
||||
```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 ../..
|
||||
|
||||
## FASE 6: EJECUTAR DIRECTIVAS
|
||||
echo "Configuraciones restauradas"
|
||||
```
|
||||
|
||||
Sigue el proceso definido en DIRECTIVA-DEPLOYMENT.md
|
||||
## FASE 6: RECREAR BASE DE DATOS (Carga Limpia)
|
||||
|
||||
---
|
||||
Si algo falla, reporta el error y el paso donde ocurrió.
|
||||
```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 ==="
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ESTRUCTURA DE BACKUPS
|
||||
|
||||
```
|
||||
../backups/
|
||||
├── 20251218_163045/
|
||||
│ └── config/
|
||||
│ ├── backend.env.production
|
||||
│ ├── backend.env
|
||||
│ ├── frontend.env.production
|
||||
│ ├── frontend.env
|
||||
│ └── ecosystem.config.js
|
||||
└── latest -> 20251218_163045/
|
||||
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
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## DIRECTIVAS EN EL REPOSITORIO
|
||||
## VARIABLES DE ENTORNO REQUERIDAS
|
||||
|
||||
Después del pull, el agente debe leer:
|
||||
El agente necesita estas variables configuradas:
|
||||
|
||||
| Archivo | Propósito |
|
||||
```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` | Proceso de deployment |
|
||||
| `docs/95-guias-desarrollo/GUIA-SSL-AUTOFIRMADO.md` | Configuración SSL |
|
||||
| `docs/95-guias-desarrollo/GUIA-CREAR-BASE-DATOS.md` | Recrear BD |
|
||||
| `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 |
|
||||
|
||||
---
|
||||
|
||||
## NOTAS
|
||||
## SCRIPTS DE PRODUCCION DISPONIBLES
|
||||
|
||||
1. **Backup solo configs** - La BD se recrea desde el repo
|
||||
2. **Repo es fuente de verdad** - Todo viene del remoto
|
||||
3. **Directivas en el repo** - Después del pull, leer docs/
|
||||
4. **Rutas relativas** - Backups en ../backups/
|
||||
| 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
|
||||
|
||||
---
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user