docs: add comprehensive documentation
- Add README.md with project overview, features, quick start guide, project structure, environment variables, and scripts - Add docs/API.md with complete API reference for all endpoints - Add docs/DEPLOYMENT.md with production deployment guide covering PM2, Nginx, SSL, and Docker options - Add docker-compose.yml for containerized deployment - Add Dockerfile with multi-stage build for optimized production image - Add .dockerignore for efficient Docker builds Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
44
.dockerignore
Normal file
44
.dockerignore
Normal file
@@ -0,0 +1,44 @@
|
||||
# Dependencies
|
||||
node_modules
|
||||
**/node_modules
|
||||
|
||||
# Build outputs
|
||||
.next
|
||||
**/dist
|
||||
**/.turbo
|
||||
|
||||
# Development files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# IDE
|
||||
.vscode
|
||||
.idea
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Docker
|
||||
Dockerfile
|
||||
docker-compose*.yml
|
||||
.dockerignore
|
||||
|
||||
# Documentation (not needed in image)
|
||||
docs
|
||||
*.md
|
||||
!README.md
|
||||
|
||||
# Tests
|
||||
**/*.test.*
|
||||
**/*.spec.*
|
||||
coverage
|
||||
|
||||
# Misc
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
86
Dockerfile
Normal file
86
Dockerfile
Normal file
@@ -0,0 +1,86 @@
|
||||
# Dockerfile para Padel Pro
|
||||
# Multi-stage build para optimizar el tamano de la imagen
|
||||
|
||||
# ============================================
|
||||
# Stage 1: Dependencias
|
||||
# ============================================
|
||||
FROM node:20-alpine AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Instalar pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@8.15.0 --activate
|
||||
|
||||
# Copiar archivos de configuracion de dependencias
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
|
||||
COPY apps/web/package.json ./apps/web/
|
||||
COPY packages/shared/package.json ./packages/shared/
|
||||
|
||||
# Instalar dependencias
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# ============================================
|
||||
# Stage 2: Builder
|
||||
# ============================================
|
||||
FROM node:20-alpine AS builder
|
||||
RUN apk add --no-cache libc6-compat
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Instalar pnpm
|
||||
RUN corepack enable && corepack prepare pnpm@8.15.0 --activate
|
||||
|
||||
# Copiar dependencias instaladas
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
|
||||
COPY --from=deps /app/packages/shared/node_modules ./packages/shared/node_modules
|
||||
|
||||
# Copiar codigo fuente
|
||||
COPY . .
|
||||
|
||||
# Generar cliente Prisma
|
||||
RUN cd apps/web && pnpm db:generate
|
||||
|
||||
# Construir la aplicacion
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
RUN pnpm build
|
||||
|
||||
# ============================================
|
||||
# Stage 3: Runner (Produccion)
|
||||
# ============================================
|
||||
FROM node:20-alpine AS runner
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Configurar entorno de produccion
|
||||
ENV NODE_ENV production
|
||||
ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
# Crear usuario no-root
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# Copiar archivos necesarios para produccion
|
||||
COPY --from=builder /app/apps/web/public ./apps/web/public
|
||||
|
||||
# Copiar archivos de Next.js standalone
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
|
||||
|
||||
# Copiar schema de Prisma para migraciones
|
||||
COPY --from=builder /app/apps/web/prisma ./apps/web/prisma
|
||||
COPY --from=builder /app/apps/web/node_modules/.prisma ./apps/web/node_modules/.prisma
|
||||
COPY --from=builder /app/apps/web/node_modules/@prisma ./apps/web/node_modules/@prisma
|
||||
|
||||
# Cambiar a usuario no-root
|
||||
USER nextjs
|
||||
|
||||
# Exponer puerto
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT 3000
|
||||
ENV HOSTNAME "0.0.0.0"
|
||||
|
||||
# Comando de inicio
|
||||
CMD ["node", "apps/web/server.js"]
|
||||
276
README.md
Normal file
276
README.md
Normal file
@@ -0,0 +1,276 @@
|
||||
# Padel Pro
|
||||
|
||||
Sistema integral de gestion para clubes de padel. Una solucion moderna y completa para administrar reservas, ventas, torneos, membresias y multiples sedes.
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
---
|
||||
|
||||
## Caracteristicas Principales
|
||||
|
||||
### Sistema de Reservas
|
||||
- Calendario visual con vista diaria/semanal
|
||||
- Gestion de disponibilidad por cancha
|
||||
- Precios dinamicos (horario regular vs premium)
|
||||
- Integracion automatica con membresias
|
||||
- Reservas recurrentes
|
||||
|
||||
### Punto de Venta (POS)
|
||||
- Gestion de productos y categorias
|
||||
- Control de inventario con alertas de stock bajo
|
||||
- Multiples metodos de pago
|
||||
- Caja registradora con apertura/cierre
|
||||
- Historial de ventas detallado
|
||||
|
||||
### Torneos
|
||||
- Formatos: Eliminacion simple/doble, Round Robin, Liga
|
||||
- Inscripciones online
|
||||
- Generacion automatica de brackets
|
||||
- Seguimiento de partidos y resultados
|
||||
|
||||
### Membresias
|
||||
- Planes personalizables
|
||||
- Horas de cancha incluidas
|
||||
- Descuentos en reservas y tienda
|
||||
- Renovacion automatica opcional
|
||||
- Alertas de vencimiento
|
||||
|
||||
### Multi-Sede
|
||||
- Gestion centralizada de multiples ubicaciones
|
||||
- Usuarios con acceso por sede
|
||||
- Reportes por sede o consolidados
|
||||
- Configuracion independiente por sede
|
||||
|
||||
---
|
||||
|
||||
## Capturas de Pantalla
|
||||
|
||||
<!-- TODO: Agregar capturas de pantalla del sistema -->
|
||||
```
|
||||
[Dashboard] [Reservas] [POS]
|
||||
[Torneos] [Membresias] [Clientes]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Inicio Rapido
|
||||
|
||||
### Requisitos Previos
|
||||
|
||||
- Node.js 20.x o superior
|
||||
- PostgreSQL 16.x
|
||||
- pnpm 8.15.0 o superior
|
||||
|
||||
### Instalacion
|
||||
|
||||
```bash
|
||||
# Clonar el repositorio
|
||||
git clone https://github.com/tu-organizacion/padel-pro.git
|
||||
cd padel-pro
|
||||
|
||||
# Instalar dependencias
|
||||
pnpm install
|
||||
|
||||
# Configurar variables de entorno
|
||||
cp apps/web/.env.example apps/web/.env
|
||||
# Editar .env con tus credenciales
|
||||
|
||||
# Generar cliente Prisma
|
||||
pnpm db:generate
|
||||
|
||||
# Crear tablas en la base de datos
|
||||
pnpm db:push
|
||||
|
||||
# Sembrar datos iniciales (opcional)
|
||||
cd apps/web && pnpm db:seed && cd ../..
|
||||
|
||||
# Iniciar en modo desarrollo
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
La aplicacion estara disponible en `http://localhost:3000`
|
||||
|
||||
---
|
||||
|
||||
## Estructura del Proyecto
|
||||
|
||||
```
|
||||
padel-pro/
|
||||
├── apps/
|
||||
│ └── web/ # Aplicacion Next.js principal
|
||||
│ ├── app/
|
||||
│ │ ├── api/ # API Routes
|
||||
│ │ │ ├── auth/ # Autenticacion (NextAuth)
|
||||
│ │ │ ├── bookings/ # Reservas
|
||||
│ │ │ ├── cash-register/ # Caja registradora
|
||||
│ │ │ ├── clients/ # Clientes
|
||||
│ │ │ ├── courts/ # Canchas
|
||||
│ │ │ ├── dashboard/ # Estadisticas
|
||||
│ │ │ ├── membership-plans/ # Planes de membresia
|
||||
│ │ │ ├── memberships/# Membresias
|
||||
│ │ │ ├── products/ # Productos
|
||||
│ │ │ ├── sales/ # Ventas
|
||||
│ │ │ ├── sites/ # Sedes
|
||||
│ │ │ └── tournaments/# Torneos
|
||||
│ │ └── (admin)/ # Paginas del panel de administracion
|
||||
│ ├── components/ # Componentes React reutilizables
|
||||
│ ├── lib/ # Utilidades y configuraciones
|
||||
│ ├── prisma/ # Schema y migraciones
|
||||
│ └── types/ # Definiciones de tipos TypeScript
|
||||
├── packages/
|
||||
│ └── shared/ # Codigo compartido (tipos, validaciones)
|
||||
├── docs/ # Documentacion
|
||||
├── package.json
|
||||
├── pnpm-workspace.yaml
|
||||
└── turbo.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Variables de Entorno
|
||||
|
||||
Crear un archivo `.env` en `apps/web/` con las siguientes variables:
|
||||
|
||||
```env
|
||||
# Base de datos
|
||||
DATABASE_URL="postgresql://usuario:password@localhost:5432/padel_pro?schema=public"
|
||||
|
||||
# NextAuth
|
||||
NEXTAUTH_SECRET="tu-clave-secreta-aqui"
|
||||
NEXTAUTH_URL="http://localhost:3000"
|
||||
|
||||
# Aplicacion
|
||||
NEXT_PUBLIC_APP_URL="http://localhost:3000"
|
||||
```
|
||||
|
||||
### Variables Requeridas
|
||||
|
||||
| Variable | Descripcion | Ejemplo |
|
||||
|----------|-------------|---------|
|
||||
| `DATABASE_URL` | URL de conexion a PostgreSQL | `postgresql://user:pass@localhost:5432/db` |
|
||||
| `NEXTAUTH_SECRET` | Clave secreta para JWT (min 32 caracteres) | Generar con `openssl rand -base64 32` |
|
||||
| `NEXTAUTH_URL` | URL base de la aplicacion | `http://localhost:3000` |
|
||||
| `NEXT_PUBLIC_APP_URL` | URL publica de la aplicacion | `http://localhost:3000` |
|
||||
|
||||
---
|
||||
|
||||
## Scripts Disponibles
|
||||
|
||||
### Desarrollo
|
||||
|
||||
```bash
|
||||
pnpm dev # Iniciar servidor de desarrollo
|
||||
pnpm build # Construir para produccion
|
||||
pnpm lint # Ejecutar ESLint
|
||||
pnpm type-check # Verificar tipos TypeScript
|
||||
```
|
||||
|
||||
### Base de Datos
|
||||
|
||||
```bash
|
||||
pnpm db:generate # Generar cliente Prisma
|
||||
pnpm db:push # Sincronizar schema con DB
|
||||
pnpm db:studio # Abrir Prisma Studio (UI para DB)
|
||||
pnpm db:seed # Sembrar datos iniciales
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Resumen de API
|
||||
|
||||
La API REST sigue convenciones estandar. Todas las rutas requieren autenticacion excepto las indicadas.
|
||||
|
||||
### Endpoints Principales
|
||||
|
||||
| Recurso | Ruta Base | Descripcion |
|
||||
|---------|-----------|-------------|
|
||||
| Auth | `/api/auth/*` | Autenticacion NextAuth |
|
||||
| Courts | `/api/courts` | Gestion de canchas |
|
||||
| Bookings | `/api/bookings` | Reservas |
|
||||
| Clients | `/api/clients` | Clientes |
|
||||
| Products | `/api/products` | Productos del POS |
|
||||
| Sales | `/api/sales` | Ventas |
|
||||
| Cash Register | `/api/cash-register` | Caja registradora |
|
||||
| Tournaments | `/api/tournaments` | Torneos |
|
||||
| Memberships | `/api/memberships` | Membresias |
|
||||
| Membership Plans | `/api/membership-plans` | Planes de membresia |
|
||||
| Sites | `/api/sites` | Sedes |
|
||||
| Dashboard | `/api/dashboard/stats` | Estadisticas |
|
||||
|
||||
Ver documentacion completa en [docs/API.md](docs/API.md)
|
||||
|
||||
---
|
||||
|
||||
## Credenciales por Defecto
|
||||
|
||||
Despues de ejecutar el seed, puedes acceder con:
|
||||
|
||||
| Usuario | Password | Rol |
|
||||
|---------|----------|-----|
|
||||
| `admin@padelpro.com` | `admin123` | Super Admin |
|
||||
| `recepcion@padelpro.com` | `recepcion123` | Recepcionista |
|
||||
|
||||
> **IMPORTANTE:** Cambiar estas credenciales inmediatamente en entornos de produccion.
|
||||
|
||||
---
|
||||
|
||||
## Contribuir
|
||||
|
||||
1. Fork el repositorio
|
||||
2. Crear una rama para tu feature (`git checkout -b feature/nueva-funcionalidad`)
|
||||
3. Commit tus cambios (`git commit -m 'feat: agregar nueva funcionalidad'`)
|
||||
4. Push a la rama (`git push origin feature/nueva-funcionalidad`)
|
||||
5. Abrir un Pull Request
|
||||
|
||||
### Convenciones de Commits
|
||||
|
||||
Usamos [Conventional Commits](https://www.conventionalcommits.org/):
|
||||
|
||||
- `feat:` Nueva funcionalidad
|
||||
- `fix:` Correccion de bug
|
||||
- `docs:` Cambios en documentacion
|
||||
- `style:` Cambios de formato (no afectan codigo)
|
||||
- `refactor:` Refactorizacion de codigo
|
||||
- `test:` Agregar o modificar tests
|
||||
- `chore:` Tareas de mantenimiento
|
||||
|
||||
---
|
||||
|
||||
## Documentacion Adicional
|
||||
|
||||
- [API Reference](docs/API.md) - Documentacion completa de endpoints
|
||||
- [Deployment Guide](docs/DEPLOYMENT.md) - Guia de despliegue
|
||||
|
||||
---
|
||||
|
||||
## Licencia
|
||||
|
||||
Este proyecto esta bajo la Licencia MIT. Ver el archivo [LICENSE](LICENSE) para mas detalles.
|
||||
|
||||
```
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Padel Pro
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
```
|
||||
61
docker-compose.yml
Normal file
61
docker-compose.yml
Normal file
@@ -0,0 +1,61 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# Base de datos PostgreSQL
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
container_name: padel-pro-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-padel_user}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-padel_password}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-padel_pro}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init.sql:ro
|
||||
ports:
|
||||
- "5432:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-padel_user} -d ${POSTGRES_DB:-padel_pro}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks:
|
||||
- padel-network
|
||||
|
||||
# Aplicacion Web Next.js
|
||||
web:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: padel-pro-web
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DATABASE_URL: postgresql://${POSTGRES_USER:-padel_user}:${POSTGRES_PASSWORD:-padel_password}@db:5432/${POSTGRES_DB:-padel_pro}?schema=public
|
||||
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
|
||||
NEXTAUTH_URL: ${NEXTAUTH_URL:-http://localhost:3000}
|
||||
NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL:-http://localhost:3000}
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./apps/web/public:/app/apps/web/public:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3000/api/auth/session"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
networks:
|
||||
- padel-network
|
||||
|
||||
networks:
|
||||
padel-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
1271
docs/API.md
Normal file
1271
docs/API.md
Normal file
File diff suppressed because it is too large
Load Diff
663
docs/DEPLOYMENT.md
Normal file
663
docs/DEPLOYMENT.md
Normal file
@@ -0,0 +1,663 @@
|
||||
# Guia de Despliegue - Padel Pro
|
||||
|
||||
Esta guia cubre el proceso completo para desplegar Padel Pro en un entorno de produccion.
|
||||
|
||||
## Tabla de Contenidos
|
||||
|
||||
1. [Requisitos Previos](#requisitos-previos)
|
||||
2. [Configuracion del Entorno](#configuracion-del-entorno)
|
||||
3. [Configuracion de Base de Datos](#configuracion-de-base-de-datos)
|
||||
4. [Despliegue con PM2](#despliegue-con-pm2)
|
||||
5. [Configuracion de Nginx](#configuracion-de-nginx)
|
||||
6. [SSL con Lets Encrypt](#ssl-con-lets-encrypt)
|
||||
7. [Despliegue con Docker](#despliegue-con-docker)
|
||||
8. [Monitoreo y Mantenimiento](#monitoreo-y-mantenimiento)
|
||||
|
||||
---
|
||||
|
||||
## Requisitos Previos
|
||||
|
||||
### Software Requerido
|
||||
|
||||
| Software | Version | Proposito |
|
||||
|----------|---------|-----------|
|
||||
| Node.js | 20.x LTS | Runtime de JavaScript |
|
||||
| PostgreSQL | 16.x | Base de datos |
|
||||
| pnpm | 8.15.0+ | Gestor de paquetes |
|
||||
| Git | 2.x | Control de versiones |
|
||||
| Nginx | 1.24+ | Servidor web / Proxy inverso |
|
||||
| PM2 | 5.x | Gestor de procesos (opcional) |
|
||||
| Docker | 24.x | Contenedores (opcional) |
|
||||
|
||||
### Recursos del Servidor
|
||||
|
||||
**Minimos:**
|
||||
- CPU: 2 cores
|
||||
- RAM: 4 GB
|
||||
- Disco: 20 GB SSD
|
||||
|
||||
**Recomendados:**
|
||||
- CPU: 4 cores
|
||||
- RAM: 8 GB
|
||||
- Disco: 50 GB SSD
|
||||
|
||||
---
|
||||
|
||||
## Configuracion del Entorno
|
||||
|
||||
### 1. Instalar Node.js 20
|
||||
|
||||
```bash
|
||||
# Usando nvm (recomendado)
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
|
||||
source ~/.bashrc
|
||||
nvm install 20
|
||||
nvm use 20
|
||||
nvm alias default 20
|
||||
|
||||
# Verificar instalacion
|
||||
node --version # v20.x.x
|
||||
```
|
||||
|
||||
### 2. Instalar pnpm
|
||||
|
||||
```bash
|
||||
npm install -g pnpm
|
||||
pnpm --version # 8.x.x
|
||||
```
|
||||
|
||||
### 3. Clonar el Repositorio
|
||||
|
||||
```bash
|
||||
cd /var/www
|
||||
git clone https://github.com/tu-organizacion/padel-pro.git
|
||||
cd padel-pro
|
||||
```
|
||||
|
||||
### 4. Configurar Variables de Entorno
|
||||
|
||||
```bash
|
||||
cp apps/web/.env.example apps/web/.env
|
||||
```
|
||||
|
||||
Editar el archivo `.env`:
|
||||
|
||||
```env
|
||||
# Base de datos - Produccion
|
||||
DATABASE_URL="postgresql://padel_user:PASSWORD_SEGURO@localhost:5432/padel_pro?schema=public"
|
||||
|
||||
# NextAuth - IMPORTANTE: Generar clave unica
|
||||
NEXTAUTH_SECRET="$(openssl rand -base64 32)"
|
||||
NEXTAUTH_URL="https://tudominio.com"
|
||||
|
||||
# Aplicacion
|
||||
NEXT_PUBLIC_APP_URL="https://tudominio.com"
|
||||
NODE_ENV="production"
|
||||
```
|
||||
|
||||
> **IMPORTANTE:** Nunca usar las credenciales de ejemplo en produccion. Generar una clave secreta unica con `openssl rand -base64 32`.
|
||||
|
||||
### 5. Instalar Dependencias
|
||||
|
||||
```bash
|
||||
pnpm install --frozen-lockfile
|
||||
```
|
||||
|
||||
### 6. Construir la Aplicacion
|
||||
|
||||
```bash
|
||||
pnpm build
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Base de Datos
|
||||
|
||||
### 1. Instalar PostgreSQL 16
|
||||
|
||||
```bash
|
||||
# Ubuntu/Debian
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt install postgresql-16
|
||||
|
||||
# Iniciar servicio
|
||||
sudo systemctl start postgresql
|
||||
sudo systemctl enable postgresql
|
||||
```
|
||||
|
||||
### 2. Crear Base de Datos y Usuario
|
||||
|
||||
```bash
|
||||
sudo -u postgres psql
|
||||
```
|
||||
|
||||
```sql
|
||||
-- Crear usuario
|
||||
CREATE USER padel_user WITH PASSWORD 'PASSWORD_SEGURO';
|
||||
|
||||
-- Crear base de datos
|
||||
CREATE DATABASE padel_pro OWNER padel_user;
|
||||
|
||||
-- Otorgar permisos
|
||||
GRANT ALL PRIVILEGES ON DATABASE padel_pro TO padel_user;
|
||||
|
||||
-- Salir
|
||||
\q
|
||||
```
|
||||
|
||||
### 3. Configurar Conexion Remota (si es necesario)
|
||||
|
||||
Editar `/etc/postgresql/16/main/postgresql.conf`:
|
||||
|
||||
```conf
|
||||
listen_addresses = 'localhost' # o '*' para conexiones remotas
|
||||
```
|
||||
|
||||
Editar `/etc/postgresql/16/main/pg_hba.conf`:
|
||||
|
||||
```conf
|
||||
# Conexion local
|
||||
local all padel_user md5
|
||||
|
||||
# Conexion remota (si es necesario)
|
||||
host padel_pro padel_user 192.168.1.0/24 md5
|
||||
```
|
||||
|
||||
Reiniciar PostgreSQL:
|
||||
|
||||
```bash
|
||||
sudo systemctl restart postgresql
|
||||
```
|
||||
|
||||
### 4. Ejecutar Migraciones
|
||||
|
||||
```bash
|
||||
cd /var/www/padel-pro
|
||||
pnpm db:generate
|
||||
pnpm db:push
|
||||
```
|
||||
|
||||
### 5. Sembrar Datos Iniciales (Opcional)
|
||||
|
||||
```bash
|
||||
cd apps/web
|
||||
pnpm db:seed
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Despliegue con PM2
|
||||
|
||||
### 1. Instalar PM2
|
||||
|
||||
```bash
|
||||
npm install -g pm2
|
||||
```
|
||||
|
||||
### 2. Crear Archivo de Configuracion
|
||||
|
||||
Crear `ecosystem.config.js` en la raiz del proyecto:
|
||||
|
||||
```javascript
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
name: 'padel-pro',
|
||||
cwd: '/var/www/padel-pro/apps/web',
|
||||
script: 'node_modules/next/dist/bin/next',
|
||||
args: 'start',
|
||||
instances: 'max',
|
||||
exec_mode: 'cluster',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 3000
|
||||
},
|
||||
env_production: {
|
||||
NODE_ENV: 'production',
|
||||
PORT: 3000
|
||||
},
|
||||
// Configuracion de logs
|
||||
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
|
||||
error_file: '/var/log/padel-pro/error.log',
|
||||
out_file: '/var/log/padel-pro/out.log',
|
||||
merge_logs: true,
|
||||
// Reinicio automatico
|
||||
max_memory_restart: '1G',
|
||||
exp_backoff_restart_delay: 100
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
### 3. Crear Directorio de Logs
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /var/log/padel-pro
|
||||
sudo chown $USER:$USER /var/log/padel-pro
|
||||
```
|
||||
|
||||
### 4. Iniciar la Aplicacion
|
||||
|
||||
```bash
|
||||
pm2 start ecosystem.config.js --env production
|
||||
```
|
||||
|
||||
### 5. Configurar Inicio Automatico
|
||||
|
||||
```bash
|
||||
pm2 startup
|
||||
pm2 save
|
||||
```
|
||||
|
||||
### 6. Comandos Utiles de PM2
|
||||
|
||||
```bash
|
||||
# Ver estado
|
||||
pm2 status
|
||||
|
||||
# Ver logs
|
||||
pm2 logs padel-pro
|
||||
|
||||
# Reiniciar
|
||||
pm2 restart padel-pro
|
||||
|
||||
# Recargar sin downtime
|
||||
pm2 reload padel-pro
|
||||
|
||||
# Detener
|
||||
pm2 stop padel-pro
|
||||
|
||||
# Monitoreo
|
||||
pm2 monit
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Configuracion de Nginx
|
||||
|
||||
### 1. Instalar Nginx
|
||||
|
||||
```bash
|
||||
sudo apt install nginx
|
||||
```
|
||||
|
||||
### 2. Crear Configuracion del Sitio
|
||||
|
||||
Crear `/etc/nginx/sites-available/padel-pro`:
|
||||
|
||||
```nginx
|
||||
# Redirigir HTTP a HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name tudominio.com www.tudominio.com;
|
||||
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
# Let's Encrypt challenge
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
}
|
||||
|
||||
# Configuracion HTTPS
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name tudominio.com www.tudominio.com;
|
||||
|
||||
# SSL (sera configurado por Certbot)
|
||||
ssl_certificate /etc/letsencrypt/live/tudominio.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/tudominio.com/privkey.pem;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_session_cache shared:SSL:50m;
|
||||
ssl_session_tickets off;
|
||||
|
||||
# Configuracion SSL moderna
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
# HSTS
|
||||
add_header Strict-Transport-Security "max-age=63072000" always;
|
||||
|
||||
# Logs
|
||||
access_log /var/log/nginx/padel-pro.access.log;
|
||||
error_log /var/log/nginx/padel-pro.error.log;
|
||||
|
||||
# Tamano maximo de subida
|
||||
client_max_body_size 10M;
|
||||
|
||||
# Gzip
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
||||
|
||||
# Proxy a Next.js
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# Cache para assets estaticos
|
||||
location /_next/static {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_cache_valid 60m;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Archivos estaticos
|
||||
location /static {
|
||||
alias /var/www/padel-pro/apps/web/public;
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Habilitar el Sitio
|
||||
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/padel-pro /etc/nginx/sites-enabled/
|
||||
|
||||
# Verificar configuracion
|
||||
sudo nginx -t
|
||||
|
||||
# Recargar Nginx
|
||||
sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## SSL con Lets Encrypt
|
||||
|
||||
### 1. Instalar Certbot
|
||||
|
||||
```bash
|
||||
sudo apt install certbot python3-certbot-nginx
|
||||
```
|
||||
|
||||
### 2. Obtener Certificado
|
||||
|
||||
```bash
|
||||
sudo certbot --nginx -d tudominio.com -d www.tudominio.com
|
||||
```
|
||||
|
||||
### 3. Renovacion Automatica
|
||||
|
||||
Certbot configura automaticamente la renovacion. Verificar:
|
||||
|
||||
```bash
|
||||
sudo certbot renew --dry-run
|
||||
```
|
||||
|
||||
### 4. Configurar Cron (si es necesario)
|
||||
|
||||
```bash
|
||||
sudo crontab -e
|
||||
```
|
||||
|
||||
Agregar:
|
||||
|
||||
```cron
|
||||
0 12 * * * /usr/bin/certbot renew --quiet
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Despliegue con Docker
|
||||
|
||||
### 1. Archivo docker-compose.yml
|
||||
|
||||
El archivo `docker-compose.yml` ya esta incluido en el proyecto. Ubicado en `/root/Padel/docker-compose.yml`.
|
||||
|
||||
### 2. Configurar Variables
|
||||
|
||||
Crear `.env` en la raiz del proyecto:
|
||||
|
||||
```env
|
||||
POSTGRES_USER=padel_user
|
||||
POSTGRES_PASSWORD=PASSWORD_SEGURO
|
||||
POSTGRES_DB=padel_pro
|
||||
DATABASE_URL=postgresql://padel_user:PASSWORD_SEGURO@db:5432/padel_pro?schema=public
|
||||
NEXTAUTH_SECRET=tu-clave-secreta-generada
|
||||
NEXTAUTH_URL=https://tudominio.com
|
||||
NEXT_PUBLIC_APP_URL=https://tudominio.com
|
||||
```
|
||||
|
||||
### 3. Construir e Iniciar
|
||||
|
||||
```bash
|
||||
# Construir imagenes
|
||||
docker compose build
|
||||
|
||||
# Iniciar servicios
|
||||
docker compose up -d
|
||||
|
||||
# Ver logs
|
||||
docker compose logs -f
|
||||
|
||||
# Ejecutar migraciones
|
||||
docker compose exec web pnpm db:push
|
||||
|
||||
# Sembrar datos (opcional)
|
||||
docker compose exec web pnpm db:seed
|
||||
```
|
||||
|
||||
### 4. Comandos Utiles
|
||||
|
||||
```bash
|
||||
# Detener servicios
|
||||
docker compose down
|
||||
|
||||
# Reiniciar
|
||||
docker compose restart
|
||||
|
||||
# Ver estado
|
||||
docker compose ps
|
||||
|
||||
# Acceder al contenedor
|
||||
docker compose exec web sh
|
||||
|
||||
# Backup de base de datos
|
||||
docker compose exec db pg_dump -U padel_user padel_pro > backup.sql
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Monitoreo y Mantenimiento
|
||||
|
||||
### Monitoreo con PM2
|
||||
|
||||
```bash
|
||||
# Dashboard en tiempo real
|
||||
pm2 monit
|
||||
|
||||
# Metricas web (opcional)
|
||||
pm2 install pm2-server-monit
|
||||
```
|
||||
|
||||
### Backup de Base de Datos
|
||||
|
||||
Crear script `/opt/scripts/backup-padel.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
BACKUP_DIR="/var/backups/padel-pro"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
FILENAME="padel_pro_$DATE.sql.gz"
|
||||
|
||||
mkdir -p $BACKUP_DIR
|
||||
|
||||
# Crear backup
|
||||
pg_dump -U padel_user padel_pro | gzip > "$BACKUP_DIR/$FILENAME"
|
||||
|
||||
# Eliminar backups antiguos (mantener 7 dias)
|
||||
find $BACKUP_DIR -name "*.sql.gz" -mtime +7 -delete
|
||||
|
||||
echo "Backup completado: $FILENAME"
|
||||
```
|
||||
|
||||
Configurar cron:
|
||||
|
||||
```bash
|
||||
chmod +x /opt/scripts/backup-padel.sh
|
||||
crontab -e
|
||||
```
|
||||
|
||||
```cron
|
||||
0 2 * * * /opt/scripts/backup-padel.sh
|
||||
```
|
||||
|
||||
### Actualizaciones
|
||||
|
||||
```bash
|
||||
cd /var/www/padel-pro
|
||||
|
||||
# Obtener cambios
|
||||
git pull origin main
|
||||
|
||||
# Instalar dependencias
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
# Construir
|
||||
pnpm build
|
||||
|
||||
# Ejecutar migraciones (si hay)
|
||||
pnpm db:push
|
||||
|
||||
# Reiniciar aplicacion
|
||||
pm2 reload padel-pro
|
||||
```
|
||||
|
||||
### Logs
|
||||
|
||||
```bash
|
||||
# Logs de la aplicacion
|
||||
pm2 logs padel-pro --lines 100
|
||||
|
||||
# Logs de Nginx
|
||||
tail -f /var/log/nginx/padel-pro.error.log
|
||||
|
||||
# Logs de PostgreSQL
|
||||
tail -f /var/log/postgresql/postgresql-16-main.log
|
||||
```
|
||||
|
||||
### Health Check
|
||||
|
||||
Crear script `/opt/scripts/health-check.sh`:
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
HEALTH_URL="https://tudominio.com/api/health"
|
||||
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $HEALTH_URL)
|
||||
|
||||
if [ $RESPONSE != "200" ]; then
|
||||
echo "ERROR: Health check failed with status $RESPONSE"
|
||||
# Enviar alerta (email, Slack, etc.)
|
||||
pm2 restart padel-pro
|
||||
fi
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Seguridad
|
||||
|
||||
### Firewall (UFW)
|
||||
|
||||
```bash
|
||||
sudo ufw allow ssh
|
||||
sudo ufw allow 'Nginx Full'
|
||||
sudo ufw enable
|
||||
```
|
||||
|
||||
### Fail2ban
|
||||
|
||||
```bash
|
||||
sudo apt install fail2ban
|
||||
sudo systemctl enable fail2ban
|
||||
```
|
||||
|
||||
### Headers de Seguridad
|
||||
|
||||
Agregar a la configuracion de Nginx:
|
||||
|
||||
```nginx
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Solucion de Problemas
|
||||
|
||||
### La aplicacion no inicia
|
||||
|
||||
```bash
|
||||
# Verificar logs
|
||||
pm2 logs padel-pro --err
|
||||
|
||||
# Verificar puertos
|
||||
netstat -tlnp | grep 3000
|
||||
|
||||
# Verificar conexion a DB
|
||||
psql -U padel_user -h localhost padel_pro -c "SELECT 1"
|
||||
```
|
||||
|
||||
### Error de conexion a base de datos
|
||||
|
||||
```bash
|
||||
# Verificar servicio
|
||||
sudo systemctl status postgresql
|
||||
|
||||
# Verificar logs
|
||||
tail -f /var/log/postgresql/postgresql-16-main.log
|
||||
|
||||
# Probar conexion
|
||||
psql "postgresql://padel_user:PASSWORD@localhost:5432/padel_pro"
|
||||
```
|
||||
|
||||
### Nginx devuelve 502
|
||||
|
||||
```bash
|
||||
# Verificar que la app este corriendo
|
||||
pm2 status
|
||||
|
||||
# Verificar configuracion
|
||||
sudo nginx -t
|
||||
|
||||
# Ver logs
|
||||
tail -f /var/log/nginx/padel-pro.error.log
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Checklist de Produccion
|
||||
|
||||
- [ ] Variables de entorno configuradas correctamente
|
||||
- [ ] Base de datos con password seguro
|
||||
- [ ] NEXTAUTH_SECRET generado de forma segura
|
||||
- [ ] SSL/HTTPS configurado
|
||||
- [ ] Firewall configurado
|
||||
- [ ] Backups automaticos
|
||||
- [ ] Monitoreo configurado
|
||||
- [ ] Logs rotados
|
||||
- [ ] Credenciales por defecto cambiadas
|
||||
- [ ] Rate limiting configurado
|
||||
- [ ] Health checks implementados
|
||||
Reference in New Issue
Block a user