forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

compose.yaml138 lines, 6.3 KiBHistoryRawDownload
1# The whole stack: postgres + backend + OpenObserve behind podman compose.
2#
3# Credentials live in three places, never mixed (see README):
4# laptop the ${VAR:-default} interpolations below — `podman compose up`
5# works with zero extra files
6# CI the workflow's throwaway postgres sidecar (hezarfen/hezarfen)
7# VPS prod ~/hezarfen_backend/hezarfen_backend.env (0600, written by hand
8# from deploy/hezarfen_backend.env.example)
9#
10# Interpolation reads the --env-file arguments (hezarfen_backend.env first,
11# deploy-owned stack.env second). The `env_file:` on the backend passes the
12# same secrets file into the container so extra keys (OTEL_*, COOKIE_SECURE,
13# TRUST_PROXY, CORS_*, RATE_LIMIT_*) reach it without being listed in
14# `environment:`. `environment:` wins over `env_file`, which is why
15# DATABASE_URL is always constructed here: a leftover DATABASE_URL in the env
16# file cannot point the container at the host.
17
18services:
19 postgres:
20 image: docker.io/library/postgres:18-alpine
21 container_name: hezarfen_backend_postgres
22 # 500 connections: the test suite mints a control+school pool per test
23 # (nextest runs ~a dozen concurrently), which exhausts the 100 default.
24 command: ["postgres", "-c", "max_connections=500"]
25 environment:
26 POSTGRES_USER: ${POSTGRES_USER:-hezarfen}
27 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-hezarfen}
28 POSTGRES_DB: ${POSTGRES_DB:-hezarfen_control}
29 ports:
30 - "127.0.0.1:5432:5432"
31 volumes:
32 # postgres:18 declares VOLUME /var/lib/postgresql (PGDATA is
33 # /var/lib/postgresql/18/docker); mounting the parent keeps the whole
34 # data dir — including future major-version subdirs — in the volume.
35 - hezarfen_backend_pgdata:/var/lib/postgresql
36 restart: unless-stopped
37 healthcheck:
38 # $$ keeps compose from interpolating; the shell inside the container
39 # expands the image's own POSTGRES_USER / POSTGRES_DB.
40 test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
41 interval: 10s
42 timeout: 5s
43 retries: 5
44 start_period: 5s
45
46 backend:
47 build:
48 context: .
49 dockerfile: Containerfile
50 # HEZARFEN_TAG comes from the deploy-owned stack.env (--env-file), or the
51 # latest local build on a laptop.
52 image: localhost/hezarfen_backend:${HEZARFEN_TAG:-latest}
53 container_name: hezarfen_backend
54 ports:
55 # Loopback only: terminate TLS on a reverse proxy in front of this.
56 - "127.0.0.1:7656:7656"
57 # AI bridge (QUIC = UDP). Paired with AI_QUIC_ADDR below.
58 - "8090:8090/udp"
59 env_file:
60 # Written once by the operator on the VPS (0600); absent on a laptop.
61 - path: hezarfen_backend.env
62 required: false
63 environment:
64 HOST: 0.0.0.0
65 PORT: "7656"
66 # The control database: the school registry + the builder accounts. Each
67 # school lives in a Postgres database of its own, named from its uuid (hex, no dashes).
68 # Constructed from POSTGRES_* and always aimed at the compose postgres.
69 DATABASE_URL: postgres://${POSTGRES_USER:-hezarfen}:${POSTGRES_PASSWORD:-hezarfen}@postgres:5432/${POSTGRES_DB:-hezarfen_control}
70 # Hardcoded: must not pick up an old systemd host path from the env file.
71 FILES_PATH: /data/files
72 RUST_LOG: info,hezarfen_backend=debug
73 # First-boot builder seed: the operator who creates and suspends schools,
74 # created once if the username doesn't exist yet.
75 BUILDER_USERNAME: ${BUILDER_USERNAME:-builder}
76 BUILDER_PASSWORD: ${BUILDER_PASSWORD:-builder123}
77 # AI bridge — the AI services dial IN over QUIC. Unset means off; a
78 # bad address or a missing token fails the boot rather than leaving a
79 # silently dead feature. Listening with no service connected is fine:
80 # chat answers 503 until one registers `chat.reply`.
81 AI_QUIC_ADDR: ${AI_QUIC_ADDR:-0.0.0.0:8090}
82 # Every service must present this to register.
83 AI_SHARED_TOKEN: ${AI_SHARED_TOKEN:-change-me}
84 volumes:
85 - hezarfen_backend_data:/data
86 depends_on:
87 postgres:
88 condition: service_healthy
89 restart: unless-stopped
90 healthcheck:
91 test: ["CMD", "curl", "-fsS", "http://127.0.0.1:7656/"]
92 interval: 30s
93 timeout: 5s
94 retries: 3
95 start_period: 10s
96
97 # ── Telemetry sink ────────────────────────────────────────────────────────
98 # OpenObserve is the only telemetry sink (no Grafana/Jaeger/Loki): one Rust
99 # binary, its own storage, no container socket and no sidecar databases. It
100 # speaks OTLP itself — HTTP on 5080 (also the UI and the search API), gRPC on
101 # 5081. Both are published on loopback only. The backend exports to it only
102 # when OTEL_* keys are present in hezarfen_backend.env (see the example).
103 openobserve:
104 image: docker.io/openobserve/openobserve:v1.0.0-rc2
105 container_name: hezarfen_backend_openobserve
106 environment:
107 # First-boot root account, created once. OpenObserve enforces a password
108 # policy (8-128 chars, upper + lower + digit + special) and panics on
109 # boot otherwise.
110 ZO_ROOT_USER_EMAIL: ${ZO_ROOT_USER_EMAIL:-admin@hezarfen.local}
111 ZO_ROOT_USER_PASSWORD: ${ZO_ROOT_USER_PASSWORD:-Hezarfen_dev1!}
112 ZO_DATA_DIR: /data
113 # Retention is per stream in days; this is the global default applied to
114 # streams that don't override it (upstream default is 3650).
115 ZO_COMPACT_DATA_RETENTION_DAYS: "90"
116 ports:
117 - "127.0.0.1:5080:5080"
118 - "127.0.0.1:5081:5081"
119 volumes:
120 - hezarfen_backend_openobserve_data:/data
121 restart: unless-stopped
122 healthcheck:
123 # corner-cut: the image is distroless (only /openobserve, no shell and no
124 # HTTP client), so the container cannot probe its own /healthz. `node
125 # list` is the closest in-image liveness signal — it succeeds only once
126 # the node has registered itself in the cluster registry, which happens
127 # after the server starts. Ceiling: it does not prove the HTTP listener
128 # answers; from the host that is `curl -fsS http://127.0.0.1:5080/healthz`.
129 test: ["CMD", "/openobserve", "node", "list"]
130 interval: 30s
131 timeout: 5s
132 retries: 5
133 start_period: 10s
134
135volumes:
136 hezarfen_backend_data:
137 hezarfen_backend_pgdata:
138 hezarfen_backend_openobserve_data: