87 lines
3.5 KiB
YAML
87 lines
3.5 KiB
YAML
# Deploy on Dokploy (or `docker compose up --build` anywhere).
|
|
#
|
|
# The public domain is exposed once, on `web`: nginx serves the Vite bundle and
|
|
# proxies /api to the `api` container. That keeps the session cookie
|
|
# first-party (no SameSite=None needed) and makes the CORS preflight
|
|
# unnecessary. If you rather have the API on its own subdomain, drop the
|
|
# `location /api/` block from apps/web/nginx.conf and set VITE_API_URL when
|
|
# building web.
|
|
|
|
# Backend variables. The api container receives the whole `.env` next to this
|
|
# file through `env_file` (Dokploy writes it from the Environment tab before
|
|
# `docker compose up`; locally, copy .env.example). Every variable the API reads
|
|
# is documented in docs/environment.md: adding one there is enough, there is no
|
|
# list to keep in sync here.
|
|
#
|
|
# `environment` wins over `env_file`, so it only keeps what the compose has to
|
|
# force or validate:
|
|
# - the required ones, with `:?` so the deploy fails early instead of the API
|
|
# crashing at runtime;
|
|
# - BETTER_AUTH_URL, derived from WEB_URL (web and API share the domain);
|
|
# - defaults that differ from the code's, for this deployment (Traefik + nginx).
|
|
x-backend-env: &backend-env
|
|
NODE_ENV: production
|
|
DATABASE_URL: "${DATABASE_URL:?falta DATABASE_URL}"
|
|
WEB_URL: "${WEB_URL:?falta WEB_URL - origen publico de la app, sin barra final}"
|
|
BETTER_AUTH_URL: "${WEB_URL:?falta WEB_URL - origen publico de la app, sin barra final}"
|
|
BETTER_AUTH_SECRET: "${BETTER_AUTH_SECRET:?falta BETTER_AUTH_SECRET - generalo con openssl rand -base64 32}"
|
|
# Traefik + nginx delante de la API: la IP del cliente es la 2da desde el final
|
|
# de X-Forwarded-For (rate limit de "Pedir un link a mi mail"). El codigo usa 1.
|
|
TRUSTED_PROXY_HOPS: ${TRUSTED_PROXY_HOPS:-2}
|
|
|
|
services:
|
|
api:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.backend
|
|
target: api
|
|
env_file:
|
|
- path: .env
|
|
required: false
|
|
environment: *backend-env
|
|
restart: unless-stopped
|
|
expose:
|
|
- "4000"
|
|
networks:
|
|
default:
|
|
# nginx (web) proxies to this alias. It only exists on this stack's own
|
|
# network: the service name `api` is also registered on dokploy-network,
|
|
# where another stack from this repo (dev/prod on the same server) has an
|
|
# `api` too, and Docker DNS would mix them up.
|
|
aliases:
|
|
- gruperly-api
|
|
dokploy-network: {}
|
|
|
|
web:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile.web
|
|
target: web
|
|
args:
|
|
# Baked into the bundle. Empty = same origin (nginx's /api proxy).
|
|
VITE_API_URL: ${VITE_API_URL:-}
|
|
restart: unless-stopped
|
|
depends_on:
|
|
- api
|
|
# No host port: on Dokploy the domain goes to port 80 of the container
|
|
# through Traefik, and a published port would clash between stacks on the
|
|
# same server (dev/prod). For local testing, docker-compose.local.yml
|
|
# publishes 8080.
|
|
expose:
|
|
- "80"
|
|
networks:
|
|
- default
|
|
# Dokploy adds dokploy-network only to the service with a domain, so it has
|
|
# to be declared explicitly for Traefik to reach this container.
|
|
- dokploy-network
|
|
|
|
# Dokploy shared network: that is where the databases Dokploy manages live.
|
|
# Without it, the api container neither resolves nor reaches the database and
|
|
# Prisma fails with P1001 "Can't reach database server".
|
|
#
|
|
# Outside Dokploy you have to create it once, before the first `docker compose up`:
|
|
# docker network create dokploy-network
|
|
networks:
|
|
dokploy-network:
|
|
external: true
|