Initial commit

This commit is contained in:
2026-01-12 08:17:17 -07:00
commit de5b6feef4
104 changed files with 12925 additions and 0 deletions

43
docker/Dockerfile.backend Normal file
View File

@@ -0,0 +1,43 @@
# FastAPI Backend Dockerfile
FROM python:3.11-slim
# Instalar dependencias del sistema
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Configurar directorio de trabajo
WORKDIR /app
# Copiar requirements y instalar dependencias Python
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Crear usuario no root
RUN useradd --create-home --shell /bin/bash app \
&& chown -R app:app /app
# Crear directorios necesarios
RUN mkdir -p /app/uploads /app/logs \
&& chown -R app:app /app/uploads /app/logs
# Copiar código de la aplicación
COPY . .
# Cambiar permisos
RUN chown -R app:app /app
# Cambiar a usuario no root
USER app
# Exponer puerto
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Comando por defecto
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

View File

@@ -0,0 +1,42 @@
# Frontend Dockerfile (reutilizable para client e internal)
FROM node:18-alpine
# Instalar dependencias del sistema
RUN apk add --no-cache \
git \
curl
# Configurar directorio de trabajo
WORKDIR /app
# Crear usuario no root
RUN addgroup -g 1001 -S nodejs \
&& adduser -S app -u 1001 -G nodejs
# Copiar package files
COPY package*.json ./
# Configurar npm para ignorar certificados SSL (solo para desarrollo)
RUN npm config set strict-ssl false
# Instalar dependencias
RUN npm install --legacy-peer-deps && npm cache clean --force
# Copiar código de la aplicación
COPY . .
# Cambiar permisos
RUN chown -R app:nodejs /app
# Cambiar a usuario no root
USER app
# Exponer puerto
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:3000 || exit 1
# Comando por defecto
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]

35
docker/Dockerfile.worker Normal file
View File

@@ -0,0 +1,35 @@
# Celery Worker Dockerfile
FROM python:3.11-slim
# Instalar dependencias del sistema
RUN apt-get update && apt-get install -y \
gcc \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Configurar directorio de trabajo
WORKDIR /app
# Copiar requirements y instalar dependencias Python
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Crear usuario no root
RUN useradd --create-home --shell /bin/bash app \
&& chown -R app:app /app
# Crear directorios necesarios
RUN mkdir -p /app/uploads /app/logs \
&& chown -R app:app /app/uploads /app/logs
# Copiar código de la aplicación
COPY . .
# Cambiar permisos
RUN chown -R app:app /app
# Cambiar a usuario no root
USER app
# Comando por defecto
CMD ["celery", "-A", "app.celery", "worker", "--loglevel=info"]

144
docker/nginx/default.conf Normal file
View File

@@ -0,0 +1,144 @@
# ServiceManager Nginx Configuration
upstream backend_api {
server backend:8000;
keepalive 32;
}
upstream client_frontend {
server frontend-client:3000;
keepalive 32;
}
upstream internal_frontend {
server frontend-internal:3000;
keepalive 32;
}
# Client Portal (clientes.servicemanager.local o puerto 3000)
server {
listen 80;
server_name clientes.servicemanager.local;
location / {
proxy_pass http://client_frontend;
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;
}
}
# Internal Portal (admin.servicemanager.local o puerto 3001)
server {
listen 80;
server_name admin.servicemanager.local;
location / {
proxy_pass http://internal_frontend;
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;
}
}
# API Backend (api.servicemanager.local o puerto 8000)
server {
listen 80;
server_name api.servicemanager.local;
# API endpoints con rate limiting
location /v1/ {
limit_req zone=api burst=20 nodelay;
proxy_pass http://backend_api;
proxy_http_version 1.1;
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_read_timeout 300;
proxy_connect_timeout 30;
proxy_send_timeout 300;
}
# Auth endpoints con rate limiting más estricto
location /v1/auth/ {
limit_req zone=login burst=10 nodelay;
proxy_pass http://backend_api;
proxy_http_version 1.1;
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;
}
# Health check
location /health {
proxy_pass http://backend_api;
access_log off;
}
# OpenAPI docs
location ~ ^/(docs|openapi\.json|redoc) {
proxy_pass http://backend_api;
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;
}
# Static files (uploads)
location /uploads/ {
alias /var/www/uploads/;
expires 1h;
add_header Cache-Control "public, immutable";
# Validar que el usuario tenga permisos (implementar en backend)
auth_request /auth;
}
# Auth subrequest para archivos protegidos
location = /auth {
internal;
proxy_pass http://backend_api/v1/auth/validate;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
}
# Default server (localhost - desarrollo)
server {
listen 80 default_server;
server_name _;
# Redirect to appropriate frontend based on path
location /admin {
return 301 http://localhost:3001/;
}
location /api/ {
proxy_pass http://backend_api/;
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;
}
location / {
return 301 http://localhost:3000/;
}
}

65
docker/nginx/nginx.conf Normal file
View File

@@ -0,0 +1,65 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'rt=$request_time uct="$upstream_connect_time" '
'uht="$upstream_header_time" urt="$upstream_response_time"';
access_log /var/log/nginx/access.log main;
# Performance
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 10M;
# Compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# Rate limiting
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
# Security headers
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
# Hide server version
server_tokens off;
# Include server configs
include /etc/nginx/conf.d/*.conf;
}