Runbook: Deploy de Aplicaciones
Overview
Section titled “Overview”Propósito: Deploy de Orchestrator (backend) y Sevastopol (frontend) desde desarrollo a producción.
Frecuencia: Semanal/quincenal (según roadmap)
Tiempo estimado: 30-45 minutos
Criticidad: 🔴 ALTA - Requiere downtime planificado
Prerequisites
Section titled “Prerequisites”Antes de iniciar deploy, verificar:
- SSH access a servidor de producción
- Git credentials configurados
- Variables de entorno production en
.env.production - Backup de base de datos completado (ver Runbook: Backup)
- Tests passing en CI/CD (GitHub Actions green)
- Downtime window aprobado por stakeholders
Procedure
Section titled “Procedure”-
Conectar a servidor de producción
Terminal window cd /opt/nostromo -
Pull latest code
Terminal window # Orchestratorcd /opt/nostromo/orchestrator && git pull origin main# Sevastopolcd /opt/nostromo/sevastopol && git pull origin main -
Install dependencies
Terminal window cd /opt/nostromo/orchestrator && npm cicd /opt/nostromo/sevastopol && npm ci -
Run database migrations
Terminal window cd /opt/nostromo/orchestrator && npm run migrate:production -
Build production bundles
Terminal window cd /opt/nostromo/orchestrator && npm run buildcd /opt/nostromo/sevastopol && npm run build -
Stop services
Terminal window pm2 stop orchestrator sevastopol -
Restart services
Terminal window pm2 start orchestrator sevastopol && sleep 30 -
Verify service status
Terminal window pm2 status
Verification
Section titled “Verification”Health Checks
Section titled “Health Checks”Ejecutar health checks para confirmar deploy exitoso:
# Orchestrator health endpointcurl http://localhost:8000/health# Expected: {"status":"ok","version":"1.2.3"}
# Sevastopol (via Nginx proxy)curl http://localhost:80/# Expected: HTTP 200 OKTest Sample API Call
Section titled “Test Sample API Call”# Login (obtener JWT)curl -X POST http://localhost:8000/api/command/auth/login \ -H "Content-Type: application/json" \
# Expected: {"token":"eyJhbGc..."}Monitor Logs
Section titled “Monitor Logs”# PM2 logspm2 logs orchestrator --lines 50pm2 logs sevastopol --lines 50
# systemd logssudo journalctl -u orchestrator -n 50 --no-pagersudo journalctl -u sevastopol -n 50 --no-pagerBuscar errores:
- ❌
ERROR,FATAL,UnhandledPromiseRejection - ✅
Server listening on port 8000,Build complete
Smoke Tests
Section titled “Smoke Tests”Ejecutar smoke tests mínimos:
- Login en Sevastopol funciona
- Dashboard carga datos
- API
/api/common/indicadoresretorna UF/UTM - Query a tenant específico funciona (verificar multi-tenancy)
Rollback
Section titled “Rollback”Si deploy falla o produce errores críticos:
-
Revert Git commits
Terminal window cd /opt/nostromo/orchestrator && git log --oneline -5git checkout <previous-commit-hash> -
Restore database backup
Ver Runbook: Backup - sección “Restore Procedure”.
Terminal window cd /opt/nostromo/backups && ls -lht | head -10psql -U postgres -d nostromo < backup_2026-01-18_pre-deploy.sql -
Rebuild with previous code
Terminal window npm ci && npm run build -
Restart services
Terminal window pm2 restart orchestrator sevastopol -
Verify rollback
Terminal window curl http://localhost:8000/health
Post-Deploy
Section titled “Post-Deploy”Update Changelog
Section titled “Update Changelog”Documentar deploy en changelog interno:
## 2026-01-18 - Production Deploy v1.2.3
**Changes**:
- Feature: Added admin endpoints for capital management- Fix: Corrected PPM calculation for regime B- Chore: Updated dependencies
**Migration**: 002_add_admin_indexes.sql**Downtime**: 3 minutes**Rolled back**: NoNotify Team
Section titled “Notify Team”Comunicar deploy exitoso:
- Slack:
#deploymentschannel - Email: stakeholders (si cambios mayores)
Monitor for 24h
Section titled “Monitor for 24h”Monitorear métricas post-deploy por 24 horas:
- Error rate (debe mantenerse baseline o bajar)
- Response time (no debe aumentar significativamente)
- User complaints (support tickets)
Troubleshooting
Section titled “Troubleshooting”Service won’t start
Section titled “Service won’t start”Síntoma: pm2 status muestra errored o stopped.
Debugging:
pm2 logs orchestrator --err --lines 100# Buscar stack traceCausas comunes:
- Puerto ya en uso:
Error: listen EADDRINUSE :::8000- Fix: Matar proceso anterior
kill -9 $(lsof -t -i:8000)
- Fix: Matar proceso anterior
- Missing env vars:
Error: JWT_SECRET is not defined- Fix: Verificar
.env.productionexiste y está poblado
- Fix: Verificar
- Database connection failed:
Error: connect ECONNREFUSED- Fix: Verificar PostgreSQL running
sudo systemctl status postgresql
- Fix: Verificar PostgreSQL running
Migrations fail
Section titled “Migrations fail”Síntoma: npm run migrate:production exits with error.
Debugging:
cat logs/migration.log# Ver error específicoCausas comunes:
- Syntax error en SQL:
ERROR: syntax error at or near "CRATE"- Fix: Corregir typo en migration file, commit, re-deploy
- Migration already applied:
ERROR: relation "users" already exists- Fix: Migration ya corrió (OK, continuar)
- Foreign key constraint:
ERROR: violates foreign key constraint- Fix: Verificar orden de migrations, puede necesitar seed data
High error rate post-deploy
Section titled “High error rate post-deploy”Síntoma: Grafana/logs muestran spike de errores después de deploy.
Action:
- Identify error pattern:
grep ERROR logs/orchestrator.log | head -20 - If critical (mayor a 10% error rate): Ejecutar rollback inmediatamente
- If non-critical (menor a 5% error rate): Investigar, puede ser issue menor
Automation (Futuro)
Section titled “Automation (Futuro)”Estado actual: Deploy es manual siguiendo este runbook.
Mejoras planeadas:
- CI/CD Pipeline: GitHub Actions auto-deploy a staging on merge to
develop - Blue-Green Deploy: Deploy a instancia nueva, switch traffic sin downtime
- Automated health checks: Script que valida todo antes de finalizar deploy
- Rollback automático: Si health checks fallan, rollback automático
Timeline: Q2 2026
Related Documentation
Section titled “Related Documentation”- Runbook: Backup - Backup antes de deploy
- Runbook: Recovery - Restore from catastrophic failure
- Infrastructure: Docker - Container setup
- Infrastructure: Networking - Ports y firewall
Changelog
Section titled “Changelog”| Fecha | Version | Cambios |
|---|---|---|
| 2026-01-18 | 1.0 | Runbook inicial creado |