Infraestructura

Infraestructura

{{< include “compiled/infraestructura.md” >}}

Crear un nuevo proyecto

  1. Elegir slug y puerto libre (8101–8199).
  2. Crear carpeta + venv + .env + run.py.
  3. Instalar deps y definir /health.
  4. Crear unit systemd + vhost Caddy.
  5. Smoke tests local y público.
sudo mkdir -p /srv/projects/<slug> && cd /srv/projects/<slug>
python3 -m venv venv
echo PORT=<puerto> > .env
venv/bin/pip install fastapi uvicorn gunicorn flask python-dotenv
# (pegar run.py estándar de Deploy)

Mapa del sitio

Caddy v2

TLS via Cloudflare (DNS-01)

{ 
  acme_dns cloudflare {
    api_token {env.CLOUDFLARE_API_TOKEN}
  }
}
(import "includes/*.caddy")

Vhost típico

sub.dominio.tld {
  import tls_cf
  encode zstd gzip
  @health path /health
  handle_path /health* { reverse_proxy 127.0.0.1:PORT }
  reverse_proxy 127.0.0.1:PORT
}

Tips

  • Validar: sudo --preserve-env=CLOUDFLARE_API_TOKEN caddy validate --config /etc/caddy/Caddyfile
  • Logs: journalctl -u caddy -n 100 --no-pager
  • No duplicar el mismo host en más de un archivo (ambiguous site definition).

Handover / Contexto

Arquitectura rápida

  • Caddy v2 con (tls_cf) y health por subdominio.
  • Servicios web en 8101–8199; infra ≥ 3000/9000/19999/9090.
  • Monitor: infra.illanes00.cl (dashboard + docs).
  • Fuente de verdad: /etc/infra/sites.yaml.

Gotchas

  • Validar Caddy con token Cloudflare en entorno preservado.
  • Evitar hosts duplicados en múltiples archivos.
  • Si / 404 pero /health 200, crear índice mínimo o servir estático.