# The whole stack: postgres + backend + OpenObserve behind podman compose. # # Credentials live in three places, never mixed (see README): # laptop the ${VAR:-default} interpolations below — `podman compose up` # works with zero extra files # CI the workflow's throwaway postgres sidecar (hezarfen/hezarfen) # VPS prod ~/hezarfen_backend/hezarfen_backend.env (0600, written by hand # from deploy/hezarfen_backend.env.example) # # Interpolation reads the --env-file arguments (hezarfen_backend.env first, # deploy-owned stack.env second). The `env_file:` on the backend passes the # same secrets file into the container so extra keys (OTEL_*, COOKIE_SECURE, # TRUST_PROXY, CORS_*, RATE_LIMIT_*) reach it without being listed in # `environment:`. `environment:` wins over `env_file`, which is why # DATABASE_URL is always constructed here: a leftover DATABASE_URL in the env # file cannot point the container at the host. services: postgres: image: docker.io/library/postgres:18-alpine container_name: hezarfen_backend_postgres # 500 connections: the test suite mints a control+school pool per test # (nextest runs ~a dozen concurrently), which exhausts the 100 default. command: ["postgres", "-c", "max_connections=500"] environment: POSTGRES_USER: ${POSTGRES_USER:-hezarfen} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-hezarfen} POSTGRES_DB: ${POSTGRES_DB:-hezarfen_control} ports: - "127.0.0.1:5432:5432" volumes: # postgres:18 declares VOLUME /var/lib/postgresql (PGDATA is # /var/lib/postgresql/18/docker); mounting the parent keeps the whole # data dir — including future major-version subdirs — in the volume. - hezarfen_backend_pgdata:/var/lib/postgresql restart: unless-stopped healthcheck: # $$ keeps compose from interpolating; the shell inside the container # expands the image's own POSTGRES_USER / POSTGRES_DB. test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 10s timeout: 5s retries: 5 start_period: 5s backend: build: context: . dockerfile: Containerfile # HEZARFEN_TAG comes from the deploy-owned stack.env (--env-file), or the # latest local build on a laptop. image: localhost/hezarfen_backend:${HEZARFEN_TAG:-latest} container_name: hezarfen_backend ports: # Loopback only: terminate TLS on a reverse proxy in front of this. - "127.0.0.1:7656:7656" # AI bridge (QUIC = UDP). Paired with AI_QUIC_ADDR below. - "8090:8090/udp" env_file: # Written once by the operator on the VPS (0600); absent on a laptop. - path: hezarfen_backend.env required: false environment: HOST: 0.0.0.0 PORT: "7656" # The control database: the school registry + the builder accounts. Each # school lives in a Postgres database of its own, named from its uuid (hex, no dashes). # Constructed from POSTGRES_* and always aimed at the compose postgres. DATABASE_URL: postgres://${POSTGRES_USER:-hezarfen}:${POSTGRES_PASSWORD:-hezarfen}@postgres:5432/${POSTGRES_DB:-hezarfen_control} # Hardcoded: must not pick up an old systemd host path from the env file. FILES_PATH: /data/files RUST_LOG: info,hezarfen_backend=debug # First-boot builder seed: the operator who creates and suspends schools, # created once if the username doesn't exist yet. BUILDER_USERNAME: ${BUILDER_USERNAME:-builder} BUILDER_PASSWORD: ${BUILDER_PASSWORD:-builder123} # AI bridge — the AI services dial IN over QUIC. Unset means off; a # bad address or a missing token fails the boot rather than leaving a # silently dead feature. Listening with no service connected is fine: # chat answers 503 until one registers `chat.reply`. AI_QUIC_ADDR: ${AI_QUIC_ADDR:-0.0.0.0:8090} # Every service must present this to register. AI_SHARED_TOKEN: ${AI_SHARED_TOKEN:-change-me} volumes: - hezarfen_backend_data:/data depends_on: postgres: condition: service_healthy restart: unless-stopped healthcheck: test: ["CMD", "curl", "-fsS", "http://127.0.0.1:7656/"] interval: 30s timeout: 5s retries: 3 start_period: 10s # ── Telemetry sink ──────────────────────────────────────────────────────── # OpenObserve is the only telemetry sink (no Grafana/Jaeger/Loki): one Rust # binary, its own storage, no container socket and no sidecar databases. It # speaks OTLP itself — HTTP on 5080 (also the UI and the search API), gRPC on # 5081. Both are published on loopback only. The backend exports to it only # when OTEL_* keys are present in hezarfen_backend.env (see the example). openobserve: image: docker.io/openobserve/openobserve:v1.0.0-rc2 container_name: hezarfen_backend_openobserve environment: # First-boot root account, created once. OpenObserve enforces a password # policy (8-128 chars, upper + lower + digit + special) and panics on # boot otherwise. ZO_ROOT_USER_EMAIL: ${ZO_ROOT_USER_EMAIL:-admin@hezarfen.local} ZO_ROOT_USER_PASSWORD: ${ZO_ROOT_USER_PASSWORD:-Hezarfen_dev1!} ZO_DATA_DIR: /data # Retention is per stream in days; this is the global default applied to # streams that don't override it (upstream default is 3650). ZO_COMPACT_DATA_RETENTION_DAYS: "90" ports: - "127.0.0.1:5080:5080" - "127.0.0.1:5081:5081" volumes: - hezarfen_backend_openobserve_data:/data restart: unless-stopped healthcheck: # corner-cut: the image is distroless (only /openobserve, no shell and no # HTTP client), so the container cannot probe its own /healthz. `node # list` is the closest in-image liveness signal — it succeeds only once # the node has registered itself in the cluster registry, which happens # after the server starts. Ceiling: it does not prove the HTTP listener # answers; from the host that is `curl -fsS http://127.0.0.1:5080/healthz`. test: ["CMD", "/openobserve", "node", "list"] interval: 30s timeout: 5s retries: 5 start_period: 10s volumes: hezarfen_backend_data: hezarfen_backend_pgdata: hezarfen_backend_openobserve_data: