Repository navigation
Expand file tree
/
Copy pathdocker-compose.dev.yml
More file actions
245 lines (237 loc) · 9.11 KB
/
Copy pathdocker-compose.dev.yml
File metadata and controls
245 lines (237 loc) · 9.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# Pinned project name. Both compose files live in `deploy/`, so without
# this they'd both default to the project name `deploy` — and `make
# infra`'s `--remove-orphans` would delete the production stack's
# containers as "orphans" of the same project.
name: thinkwatch-dev
services:
postgres:
image: postgres:18-alpine
# Docker's default /dev/shm of 64MB is too small for parallel
# workers + auto-ANALYZE under the integration suite (one
# ephemeral DB per test, dozens of concurrent stat targets).
# Crashes show up as `could not resize shared memory segment "/PostgreSQL.…"
# to 33554432 bytes: No space left on device` and the container
# eventually goes unhealthy. 512MB clears the suite with headroom.
shm_size: 512m
command:
- postgres
# --- Memory ---
- -c
- shared_buffers=256MB
- -c
- effective_cache_size=768MB
- -c
- work_mem=8MB
- -c
- maintenance_work_mem=64MB
- -c
- wal_buffers=8MB
# --- WAL / Checkpoints ---
- -c
- checkpoint_completion_target=0.9
- -c
- wal_compression=zstd
# --- I/O ---
- -c
- random_page_cost=1.1
- -c
- effective_io_concurrency=200
# --- Connections & safety ---
- -c
- idle_in_transaction_session_timeout=30s
- -c
- statement_timeout=60s
# --- Planner ---
- -c
- default_statistics_target=200
- -c
- jit=off
# --- Slow query log (dev: log everything > 200ms) ---
- -c
- log_min_duration_statement=200
- -c
- log_lock_waits=on
environment:
POSTGRES_USER: ${DB_USER:-thinkwatch}
POSTGRES_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD is required}
POSTGRES_DB: ${DB_NAME:-think_watch}
ports:
- "5432:5432"
volumes:
- ./data-dev/postgres:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-thinkwatch}"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:8-alpine
command: redis-server /etc/redis/redis.conf --requirepass ${REDIS_PASSWORD:?REDIS_PASSWORD is required}
ports:
- "6379:6379"
volumes:
- ./data-dev/redis:/data
- ./redis/redis.conf:/etc/redis/redis.conf:ro
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 5s
timeout: 5s
retries: 5
# --- ClickHouse (log storage & search) ---
clickhouse:
image: clickhouse/clickhouse-server:26.8-alpine
command: ["--", "--listen_host=0.0.0.0"]
ports:
- "8123:8123" # HTTP interface
- "9000:9000" # Native TCP
environment:
CLICKHOUSE_USER: ${CLICKHOUSE_USER:-thinkwatch}
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD:?CLICKHOUSE_PASSWORD is required}
CLICKHOUSE_DB: ${CLICKHOUSE_DB:-think_watch}
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
volumes:
- ./data-dev/clickhouse:/var/lib/clickhouse
- ./clickhouse/initdb.d/:/docker-entrypoint-initdb.d/:ro
- ./clickhouse/config.d/:/etc/clickhouse-server/config.d/:ro
# NOT ./clickhouse/users.d — that directory is the production
# stack's, and this image's entrypoint WRITES default-user.xml
# into it from CLICKHOUSE_USER/PASSWORD. Sharing it meant one
# `make infra` silently rewrote the production ClickHouse
# credentials (which hot-reloads users.d), and every audit insert
# started failing AUTHENTICATION_FAILED against a stack nobody
# had touched. Dev needs no override at all: the entrypoint
# provisions the user from the env vars above.
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:8123/ping"]
interval: 5s
timeout: 5s
retries: 10
# --- Zitadel (OIDC / SSO provider for development) ---
zitadel:
image: ghcr.io/zitadel/zitadel:v4.19.5
command: start-from-init --masterkeyFromEnv --tlsMode disabled
environment:
ZITADEL_MASTERKEY: "${ZITADEL_MASTERKEY:?ZITADEL_MASTERKEY is required (32 chars)}"
ZITADEL_DATABASE_POSTGRES_HOST: zitadel_db
ZITADEL_DATABASE_POSTGRES_PORT: 5432
ZITADEL_DATABASE_POSTGRES_DATABASE: zitadel
ZITADEL_DATABASE_POSTGRES_USER_USERNAME: zitadel
ZITADEL_DATABASE_POSTGRES_USER_PASSWORD: ${ZITADEL_PG_PASSWORD:?ZITADEL_PG_PASSWORD is required}
ZITADEL_DATABASE_POSTGRES_USER_SSL_MODE: disable
ZITADEL_DATABASE_POSTGRES_ADMIN_USERNAME: postgres
ZITADEL_DATABASE_POSTGRES_ADMIN_PASSWORD: ${ZITADEL_PG_PASSWORD}
ZITADEL_DATABASE_POSTGRES_ADMIN_SSL_MODE: disable
ZITADEL_EXTERNALDOMAIN: localhost
# Host port 8082, not 8080: the production compose serves the web
# UI on ${WEB_PORT}, whose obvious local value is 8080, and the
# two stacks are routinely up back-to-back. This must match the
# published host port below — Zitadel bakes it into the OIDC
# issuer URL, so a mismatch breaks discovery.
ZITADEL_EXTERNALPORT: 8082
ZITADEL_EXTERNALSECURE: "false"
ZITADEL_FIRSTINSTANCE_ORG_HUMAN_USERNAME: "admin"
ZITADEL_FIRSTINSTANCE_ORG_HUMAN_PASSWORD: "${ZITADEL_ADMIN_PASSWORD:-${ZITADEL_PG_PASSWORD}!Aa1}"
ZITADEL_TELEMETRY_ENABLED: "false"
ports:
- "8082:8080"
depends_on:
zitadel_db:
condition: service_healthy
zitadel_db:
image: postgres:18-alpine
command:
- postgres
- -c
- shared_buffers=128MB
- -c
- effective_cache_size=384MB
- -c
- work_mem=4MB
- -c
- jit=off
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${ZITADEL_PG_PASSWORD:?ZITADEL_PG_PASSWORD is required}
POSTGRES_DB: zitadel
volumes:
- ./data-dev/zitadel_db:/var/lib/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 3s
retries: 10
# --- RustFS (S3-compatible object storage for audit body offload) ---
#
# Default backend for the audit body-offload pipeline (see
# crates/common/src/blob_store.rs). The server reads S3_* env vars at
# startup and points at this container when they're set; without them
# the offload pipeline runs InlineStore (truncation only). The bucket
# `thinkwatch-audit-bodies` is created by the rustfs_init one-shot below using
# `mc` against the same RustFS endpoint — without it the first body
# PUT 404s on a missing bucket and falls back to truncation forever.
rustfs:
image: rustfs/rustfs:latest
command: ["server", "/data", "--address", ":9000", "--console-address", ":9001"]
environment:
# RustFS uses the MinIO-style root credential pair. Keep them in
# sync with S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY in .env so
# the server can authenticate against this bucket.
RUSTFS_ROOT_USER: ${S3_ACCESS_KEY_ID:?S3_ACCESS_KEY_ID is required (used both by rustfs root creds and the gateway)}
RUSTFS_ROOT_PASSWORD: ${S3_SECRET_ACCESS_KEY:?S3_SECRET_ACCESS_KEY is required}
ports:
- "9100:9000" # S3 API — host port 9100 to avoid clashing with CH native 9000
- "9101:9001" # Admin console (read-only browse for operators)
volumes:
- ./data-dev/rustfs:/data
healthcheck:
# RustFS exposes `/health` (200 OK on a live server); the
# MinIO-style `/minio/health/live` path that earlier RustFS
# builds answered now 403s under root-creds mode, which kept
# the container permanently "unhealthy" — blocking the
# `rustfs_init` one-shot and leaving the bucket uncreated.
test: ["CMD-SHELL", "wget -q --spider http://localhost:9000/health || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# One-shot bucket bootstrap. Uses the official MinIO Client (`mc`)
# because RustFS speaks the MinIO admin API; runs to completion then
# exits 0. Idempotent — `mb --ignore-existing` makes the second-run
# case quiet.
rustfs_init:
image: minio/mc:latest
depends_on:
rustfs:
condition: service_healthy
environment:
S3_BUCKET: ${S3_BUCKET:-thinkwatch-audit-bodies}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?}
entrypoint:
- /bin/sh
- -c
- |
set -eu
mc alias set local http://rustfs:9000 "$$S3_ACCESS_KEY_ID" "$$S3_SECRET_ACCESS_KEY"
mc mb --ignore-existing "local/$$S3_BUCKET"
# Set an object-lifecycle rule that expires audit bodies at 60d
# — a buffer over the default 30-day column TTL in CH so a
# late-arriving body fetch still hits the bucket for a couple
# weeks past the row's body NULL-out. Operators can override
# by editing this file or applying their own lifecycle policy
# against the bucket.
cat > /tmp/lifecycle.json <<EOF
{
"Rules": [
{
"ID": "expire-audit-bodies",
"Status": "Enabled",
"Expiration": { "Days": 60 },
"Filter": { "Prefix": "bodies/" }
}
]
}
EOF
mc ilm import "local/$$S3_BUCKET" < /tmp/lifecycle.json || true
echo "rustfs bucket $$S3_BUCKET ready"
restart: "no"