feat: docker-compose (postgres + api) e imagen nginx+node horneada
- api: una sola imagen con nginx (estáticos + proxy /api y /e) y node, build context en la raíz para hornear frontend/ (§5, lección Wonderloo) - override dev: puertos en 127.0.0.1 (80/3001/5432) y bind-mount de HTML - placeholders de checada.html y panel.html (páginas reales en Fases B/C)
This commit is contained in:
1 parent
fea201ae37
commit
3de41571e1
8 files changed
+197
No files matched your search
@@ -0,0 +1,11 @@
|
||||
# Context de build = raíz del repo (ver docker-compose.yml → api.build)
|
||||
.git
|
||||
node_modules
|
||||
backend/node_modules
|
||||
npm-debug.log
|
||||
.env
|
||||
.env.*
|
||||
docs
|
||||
*.md
|
||||
docker-compose*.yml
|
||||
.DS_Store
|
||||
@@ -0,0 +1,29 @@
|
||||
# Imagen única nginx + node (lección Wonderloo: bind-mounts en Coolify dan
|
||||
# problemas → frontend y config horneados en la imagen).
|
||||
# Build context = raíz del repo (ver docker-compose.yml).
|
||||
FROM node:20-alpine
|
||||
|
||||
# nginx sirve estáticos y proxyea /api/ y /e/ al node local.
|
||||
# su-exec para que node corra sin privilegios (nginx necesita root para :80).
|
||||
RUN apk add --no-cache nginx su-exec
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Dependencias
|
||||
COPY backend/package*.json ./
|
||||
RUN npm ci --omit=dev
|
||||
|
||||
# Código
|
||||
COPY --chown=node:node backend/src ./src
|
||||
|
||||
# Frontend + config nginx horneados.
|
||||
# --chmod garantiza lectura por el usuario nginx en runtime,
|
||||
# independientemente de los permisos del archivo fuente en el host.
|
||||
COPY --chmod=644 frontend/checada.html frontend/panel.html /usr/share/nginx/html/
|
||||
COPY --chmod=644 backend/nginx-default.conf /etc/nginx/http.d/default.conf
|
||||
COPY --chmod=755 backend/docker-entrypoint.sh /docker-entrypoint.sh
|
||||
|
||||
ENV NODE_ENV=production
|
||||
EXPOSE 80 3001
|
||||
|
||||
CMD ["/docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# El paquete nginx de Alpine espera su pidfile en /run/nginx
|
||||
mkdir -p /run/nginx
|
||||
|
||||
# nginx en background (daemon); node en foreground como proceso principal
|
||||
# para que docker stop → SIGTERM llegue a node (graceful shutdown).
|
||||
nginx
|
||||
|
||||
exec su-exec node node /app/src/index.js
|
||||
@@ -0,0 +1,40 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index checada.html;
|
||||
|
||||
# Frontend estático
|
||||
location = / {
|
||||
try_files /checada.html =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /checada.html =404;
|
||||
}
|
||||
|
||||
# Reverse proxy al API (node en el mismo container)
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:3001/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 30s;
|
||||
}
|
||||
|
||||
# Redirect de escaneo NFC/QR (endpoints de Fase C; el proxy queda listo)
|
||||
location /e/ {
|
||||
proxy_pass http://127.0.0.1:3001/e/;
|
||||
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 10s;
|
||||
}
|
||||
|
||||
client_max_body_size 1M;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# Overrides para desarrollo local.
|
||||
# Docker Compose lo merge automáticamente con docker-compose.yml.
|
||||
# Propósito:
|
||||
# - Exponer puertos en 127.0.0.1 del host Mac para curl / navegador.
|
||||
# - Bind-mount de los HTML para editar sin rebuild del container.
|
||||
# En producción (Coolify + Traefik) la imagen horneada trae el HTML adentro;
|
||||
# el bind-mount de aquí sería no-op porque el archivo del host es idéntico
|
||||
# al del clone del repo.
|
||||
|
||||
services:
|
||||
postgres:
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
|
||||
api:
|
||||
volumes:
|
||||
- ./frontend/checada.html:/usr/share/nginx/html/checada.html:ro
|
||||
- ./frontend/panel.html:/usr/share/nginx/html/panel.html:ro
|
||||
ports:
|
||||
# 80 → nginx (mismo path que producción: estáticos + proxy /api y /e)
|
||||
- "127.0.0.1:80:80"
|
||||
# 3001 → node directo, útil para depurar la API sin pasar por nginx
|
||||
- "127.0.0.1:3001:3001"
|
||||
@@ -0,0 +1,45 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: taboada_postgres
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
networks:
|
||||
- default
|
||||
|
||||
api:
|
||||
build:
|
||||
# Context en la raíz del repo: la imagen hornea nginx + node + frontend
|
||||
# (backend/Dockerfile no podría copiar ../frontend con context ./backend).
|
||||
context: .
|
||||
dockerfile: backend/Dockerfile
|
||||
container_name: taboada_api
|
||||
restart: unless-stopped
|
||||
env_file: .env
|
||||
environment:
|
||||
# Override: el container corre en modo producción (JSON logs, sin pino-pretty)
|
||||
# aunque .env esté en development para ejecuciones locales de npm run dev.
|
||||
NODE_ENV: production
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- default
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: taboada-internal
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Taboada — Registro de horas</title>
|
||||
<style>
|
||||
body { font-family: -apple-system, system-ui, sans-serif; display: grid;
|
||||
place-items: center; min-height: 100vh; margin: 0; background: #f4f4f5; }
|
||||
main { text-align: center; color: #3f3f46; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Taboada — Registro de horas</h1>
|
||||
<p>Flujo de checada en construcción (Fase C).</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Taboada — Panel de supervisión</title>
|
||||
<style>
|
||||
body { font-family: -apple-system, system-ui, sans-serif; display: grid;
|
||||
place-items: center; min-height: 100vh; margin: 0; background: #f4f4f5; }
|
||||
main { text-align: center; color: #3f3f46; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Taboada — Panel de supervisión</h1>
|
||||
<p>Panel en construcción (Fase B).</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user