Some checks failed
Build / Build Backend (push) Has been cancelled
Build / Build Mobile (TypeScript Check) (push) Has been cancelled
Lint / Lint Backend (push) Has been cancelled
Lint / Lint Mobile (push) Has been cancelled
Test / Backend E2E Tests (push) Has been cancelled
Test / Mobile Unit Tests (push) Has been cancelled
Build / Build Docker Image (push) Has been cancelled
- Add exports module with PDF/CSV/Excel generation - Add reports module for inventory analytics - Add POS integrations module - Add database migrations for exports, movements and integrations - Add GitHub Actions CI/CD workflow with Docker support - Add mobile export and reports screens with tests - Update epic documentation with traceability - Add deployment and security guides Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
234 lines
4.0 KiB
Markdown
234 lines
4.0 KiB
Markdown
---
|
|
id: GUIA-DESPLIEGUE
|
|
type: Guide
|
|
status: Vigente
|
|
version: "1.0.0"
|
|
created_date: 2026-01-13
|
|
updated_date: 2026-01-13
|
|
simco_version: "4.0.0"
|
|
author: "Agente Arquitecto de Documentación"
|
|
---
|
|
|
|
# Guía de Despliegue - MiInventario
|
|
|
|
## 1. Requisitos Previos
|
|
|
|
### 1.1 Software Requerido
|
|
|
|
| Software | Versión | Propósito |
|
|
|----------|---------|-----------|
|
|
| Docker | 24.x+ | Contenedores |
|
|
| Docker Compose | 2.x+ | Orquestación |
|
|
| Node.js | 18.x+ | Runtime |
|
|
| npm | 9.x+ | Gestión de paquetes |
|
|
|
|
### 1.2 Recursos Mínimos
|
|
|
|
- **CPU:** 2 cores
|
|
- **RAM:** 4 GB
|
|
- **Disco:** 10 GB libres
|
|
|
|
## 2. Despliegue Local (Desarrollo)
|
|
|
|
### 2.1 Clonar Repositorio
|
|
|
|
```bash
|
|
git clone <repo-url> miinventario
|
|
cd miinventario
|
|
```
|
|
|
|
### 2.2 Configurar Variables de Entorno
|
|
|
|
```bash
|
|
# Copiar template de variables
|
|
cp .env.example .env
|
|
|
|
# Editar variables obligatorias
|
|
nano .env
|
|
```
|
|
|
|
Variables obligatorias:
|
|
- `JWT_SECRET` - Generar con: `openssl rand -base64 32`
|
|
- `STRIPE_SECRET_KEY` - Obtener de dashboard Stripe
|
|
- `AI_API_KEY` - API key de OpenAI o Anthropic
|
|
|
|
### 2.3 Iniciar Servicios Docker
|
|
|
|
```bash
|
|
# Levantar PostgreSQL, Redis, MinIO
|
|
docker-compose up -d
|
|
|
|
# Verificar que los servicios están corriendo
|
|
docker-compose ps
|
|
```
|
|
|
|
### 2.4 Instalar Dependencias
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
### 2.5 Ejecutar Migraciones
|
|
|
|
```bash
|
|
npm run db:migrate
|
|
```
|
|
|
|
### 2.6 Cargar Datos Iniciales (Seeds)
|
|
|
|
```bash
|
|
npm run db:seed
|
|
```
|
|
|
|
### 2.7 Iniciar Aplicación
|
|
|
|
```bash
|
|
# Backend (puerto 3142)
|
|
npm run dev:backend
|
|
|
|
# Mobile (puerto 8082)
|
|
npm run dev:mobile
|
|
```
|
|
|
|
## 3. Despliegue Producción
|
|
|
|
### 3.1 Build de Producción
|
|
|
|
```bash
|
|
# Backend
|
|
npm run build:backend
|
|
|
|
# Mobile (generar APK/IPA)
|
|
cd apps/mobile
|
|
eas build --platform android --profile production
|
|
eas build --platform ios --profile production
|
|
```
|
|
|
|
### 3.2 Variables de Producción
|
|
|
|
Asegurar que estas variables estén configuradas:
|
|
|
|
| Variable | Descripción |
|
|
|----------|-------------|
|
|
| `NODE_ENV` | `production` |
|
|
| `DATABASE_URL` | URL PostgreSQL producción |
|
|
| `REDIS_URL` | URL Redis producción |
|
|
| `S3_ENDPOINT` | Endpoint S3/MinIO producción |
|
|
| `STRIPE_SECRET_KEY` | Key producción Stripe |
|
|
| `STRIPE_WEBHOOK_SECRET` | Secret para webhooks |
|
|
|
|
### 3.3 Docker Compose Producción
|
|
|
|
```bash
|
|
docker-compose -f docker-compose.prod.yml up -d
|
|
```
|
|
|
|
## 4. Verificación de Despliegue
|
|
|
|
### 4.1 Health Check Backend
|
|
|
|
```bash
|
|
curl http://localhost:3142/api/health
|
|
# Respuesta esperada: { "status": "ok" }
|
|
```
|
|
|
|
### 4.2 Verificar Base de Datos
|
|
|
|
```bash
|
|
docker exec -it miinventario-postgres psql -U postgres -d miinventario_dev -c "\dt"
|
|
# Debe mostrar 21 tablas
|
|
```
|
|
|
|
### 4.3 Verificar Redis
|
|
|
|
```bash
|
|
docker exec -it miinventario-redis redis-cli ping
|
|
# Respuesta esperada: PONG
|
|
```
|
|
|
|
### 4.4 Verificar MinIO
|
|
|
|
Acceder a `http://localhost:9003` con credenciales:
|
|
- Usuario: `minioadmin`
|
|
- Contraseña: `minioadmin`
|
|
|
|
## 5. Troubleshooting
|
|
|
|
### 5.1 Error: Puerto ya en uso
|
|
|
|
```bash
|
|
# Identificar proceso usando el puerto
|
|
lsof -i :3142
|
|
|
|
# Matar proceso
|
|
kill -9 <PID>
|
|
```
|
|
|
|
### 5.2 Error: Conexión a PostgreSQL rechazada
|
|
|
|
```bash
|
|
# Verificar que el contenedor está corriendo
|
|
docker-compose ps postgres
|
|
|
|
# Ver logs del contenedor
|
|
docker-compose logs postgres
|
|
```
|
|
|
|
### 5.3 Error: Migraciones fallan
|
|
|
|
```bash
|
|
# Recrear base de datos
|
|
./database/scripts/recreate-db.sh
|
|
|
|
# Volver a ejecutar migraciones
|
|
npm run db:migrate
|
|
```
|
|
|
|
### 5.4 Error: MinIO no accesible
|
|
|
|
```bash
|
|
# Verificar permisos del bucket
|
|
docker exec -it miinventario-minio mc ls local/miinventario
|
|
```
|
|
|
|
## 6. Monitoreo
|
|
|
|
### 6.1 Logs en Tiempo Real
|
|
|
|
```bash
|
|
# Todos los servicios
|
|
docker-compose logs -f
|
|
|
|
# Solo backend
|
|
docker-compose logs -f backend
|
|
|
|
# Solo base de datos
|
|
docker-compose logs -f postgres
|
|
```
|
|
|
|
### 6.2 Métricas de Recursos
|
|
|
|
```bash
|
|
docker stats
|
|
```
|
|
|
|
## 7. Backup y Restauración
|
|
|
|
### 7.1 Backup de Base de Datos
|
|
|
|
```bash
|
|
docker exec -t miinventario-postgres pg_dump -U postgres miinventario_dev > backup.sql
|
|
```
|
|
|
|
### 7.2 Restaurar Base de Datos
|
|
|
|
```bash
|
|
docker exec -i miinventario-postgres psql -U postgres miinventario_dev < backup.sql
|
|
```
|
|
|
|
---
|
|
|
|
**Documento creado:** 2026-01-13
|
|
**Última actualización:** 2026-01-13
|
|
**Versión:** 1.0.0
|