-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
418 lines (405 loc) · 12.4 KB
/
docker-compose.yml
File metadata and controls
418 lines (405 loc) · 12.4 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# Villa Unified Docker Development Environment
# =============================================================================
# Single source of truth for all Docker development modes.
#
# Usage:
# docker compose up -d # Default: postgres only
# docker compose --profile dev up -d # Dev: postgres + caddy
# docker compose --profile test up # Test: postgres-test + tests
# docker compose --profile https up -d # HTTPS: caddy proxy only
# docker compose --profile full up -d # Full: all services
#
# Environment:
# Copy .env.docker to .env for local overrides
#
# Troubleshooting:
# See DOCKER.md for detailed documentation
# =============================================================================
services:
# ===========================================================================
# PostgreSQL - Development Database
# ===========================================================================
postgres:
image: postgres:17-alpine
container_name: villa-postgres
restart: unless-stopped
profiles:
- dev
- full
- "" # Default profile (runs with no profile specified)
environment:
POSTGRES_USER: ${POSTGRES_USER:-villa}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-villa_dev_password}
POSTGRES_DB: ${POSTGRES_DB:-villa_dev}
# Performance tuning
POSTGRES_SHARED_BUFFERS: ${POSTGRES_SHARED_BUFFERS:-256MB}
POSTGRES_MAX_CONNECTIONS: ${POSTGRES_MAX_CONNECTIONS:-100}
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./scripts/db-init.sql:/docker-entrypoint-initdb.d/init.sql:ro
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U ${POSTGRES_USER:-villa} -d ${POSTGRES_DB:-villa_dev}",
]
interval: 5s
timeout: 5s
retries: 5
start_period: 10s
networks:
- villa-net
# ===========================================================================
# PostgreSQL Test - Ephemeral Test Database
# ===========================================================================
postgres-test:
image: postgres:17-alpine
container_name: villa-postgres-test
profiles:
- test
environment:
POSTGRES_USER: ${POSTGRES_TEST_USER:-villa_test}
POSTGRES_PASSWORD: ${POSTGRES_TEST_PASSWORD:-test_password}
POSTGRES_DB: ${POSTGRES_TEST_DB:-villa_test}
# Optimize for speed over durability (test data is ephemeral)
POSTGRES_FSYNC: "off"
POSTGRES_SYNCHRONOUS_COMMIT: "off"
POSTGRES_FULL_PAGE_WRITES: "off"
ports:
- "${POSTGRES_TEST_PORT:-5433}:5432"
volumes:
- postgres_test_data:/var/lib/postgresql/data
- ./scripts/db-init.sql:/docker-entrypoint-initdb.d/init.sql:ro
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U ${POSTGRES_TEST_USER:-villa_test} -d ${POSTGRES_TEST_DB:-villa_test}",
]
interval: 3s
timeout: 3s
retries: 5
start_period: 5s
networks:
- villa-net
tmpfs:
# Use tmpfs for faster test performance (data lives in memory)
- /var/lib/postgresql/data:size=1G
# ===========================================================================
# Next.js Application - Development Server
# ===========================================================================
app:
build:
context: .
dockerfile: Dockerfile.dev
container_name: villa-app
profiles:
- full
ports:
- "${APP_PORT:-3000}:3000"
mem_limit: ${APP_MEM_LIMIT:-6g}
environment:
# Node
- NODE_ENV=${NODE_ENV:-development}
- NEXT_TELEMETRY_DISABLED=1
- WATCHPACK_POLLING=${WATCHPACK_POLLING:-true}
# Database
- DATABASE_URL=${DATABASE_URL:-postgresql://villa:villa_dev_password@postgres:5432/villa_dev}
# Porto
- NEXT_PUBLIC_PORTO_ENV=${NEXT_PUBLIC_PORTO_ENV:-stg}
- NEXT_PUBLIC_PORTO_DIALOG_HOST=${NEXT_PUBLIC_PORTO_DIALOG_HOST:-https://id.porto.sh}
# App
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000}
- NEXT_PUBLIC_CHAIN_ID=${NEXT_PUBLIC_CHAIN_ID:-84532}
- NEXT_PUBLIC_ENABLE_DEV_TOOLS=${NEXT_PUBLIC_ENABLE_DEV_TOOLS:-true}
- NEXT_PUBLIC_LOG_LEVEL=${NEXT_PUBLIC_LOG_LEVEL:-debug}
volumes:
# Mount source for hot reload
- ./apps/hub/src:/app/apps/hub/src
- ./packages/sdk/src:/app/packages/sdk/src
- ./packages/ui/src:/app/packages/ui/src
# Exclude node_modules and build artifacts
- /app/node_modules
- /app/.next
- /app/apps/hub/node_modules
- /app/apps/hub/.next
depends_on:
postgres:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:3000/api/health",
]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
- villa-net
# ===========================================================================
# Key Application - Passkey Management App (port 3001)
# ===========================================================================
key:
build:
context: .
dockerfile: Dockerfile.dev
args:
- APP_PATH=apps/key
container_name: villa-key
profiles:
- dev
- full
ports:
- "${KEY_PORT:-3001}:3001"
mem_limit: ${APP_MEM_LIMIT:-6g}
environment:
# Node
- NODE_ENV=${NODE_ENV:-development}
- NEXT_TELEMETRY_DISABLED=1
- WATCHPACK_POLLING=${WATCHPACK_POLLING:-true}
- PORT=3001
# Database
- DATABASE_URL=${DATABASE_URL:-postgresql://villa:villa_dev_password@postgres:5432/villa_dev}
# Porto
- NEXT_PUBLIC_PORTO_ENV=${NEXT_PUBLIC_PORTO_ENV:-stg}
- NEXT_PUBLIC_PORTO_DIALOG_HOST=${NEXT_PUBLIC_PORTO_DIALOG_HOST:-https://id.porto.sh}
# App
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_KEY_APP_URL:-https://local-key.villa.cash}
- NEXT_PUBLIC_HUB_URL=${NEXT_PUBLIC_HUB_URL:-https://local.villa.cash}
- NEXT_PUBLIC_CHAIN_ID=${NEXT_PUBLIC_CHAIN_ID:-84532}
- NEXT_PUBLIC_ENABLE_DEV_TOOLS=${NEXT_PUBLIC_ENABLE_DEV_TOOLS:-true}
- NEXT_PUBLIC_LOG_LEVEL=${NEXT_PUBLIC_LOG_LEVEL:-debug}
volumes:
# Mount source for hot reload
- ./apps/key/src:/app/apps/key/src
- ./packages/sdk/src:/app/packages/sdk/src
- ./packages/ui/src:/app/packages/ui/src
# Exclude node_modules and build artifacts
- /app/node_modules
- /app/.next
- /app/apps/key/node_modules
- /app/apps/key/.next
depends_on:
postgres:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:3001/api/health",
]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
- villa-net
# ===========================================================================
# Developers/Docs Application (port 3002)
# ===========================================================================
developers:
build:
context: .
dockerfile: Dockerfile.dev
args:
- APP_PATH=apps/developers
container_name: villa-developers
profiles:
- dev
- full
ports:
- "${DEVELOPERS_PORT:-3002}:3002"
mem_limit: ${APP_MEM_LIMIT:-4g}
environment:
- NODE_ENV=${NODE_ENV:-development}
- NEXT_TELEMETRY_DISABLED=1
- WATCHPACK_POLLING=${WATCHPACK_POLLING:-true}
- PORT=3002
volumes:
- ./apps/developers/src:/app/apps/developers/src
- ./packages/sdk/src:/app/packages/sdk/src
- /app/node_modules
- /app/.next
- /app/apps/developers/node_modules
- /app/apps/developers/.next
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:3002/",
]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s
networks:
- villa-net
# ===========================================================================
# Caddy - HTTPS Reverse Proxy
# ===========================================================================
# Provides HTTPS for passkey testing (WebAuthn requires secure context)
caddy:
image: caddy:2-alpine
container_name: villa-caddy
profiles:
- dev
- https
- full
ports:
- "${CADDY_HTTP_PORT:-80}:80"
- "${CADDY_HTTPS_PORT:-443}:443"
volumes:
# Use appropriate Caddyfile based on mode
- ${CADDYFILE:-./Caddyfile.local}:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
environment:
- CADDY_DOMAIN=${CADDY_DOMAIN:-local.villa.cash}
extra_hosts:
# Allow Caddy to reach host machine (for hybrid mode)
- "host.docker.internal:host-gateway"
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"--no-check-certificate",
"https://localhost/caddy-health",
]
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
restart: unless-stopped
networks:
- villa-net
depends_on:
# Only depend on app if full profile (app is in container)
app:
condition: service_healthy
required: false
# ===========================================================================
# Test Runner - Unit Tests
# ===========================================================================
test-unit:
build:
context: .
dockerfile: Dockerfile.dev
container_name: villa-test-unit
profiles:
- test
environment:
- NODE_ENV=test
- CI=${CI:-false}
volumes:
- .:/app
- /app/node_modules
command: bun test
networks:
- villa-net
# ===========================================================================
# Test Runner - E2E Tests (Playwright)
# ===========================================================================
test-e2e:
build:
context: .
dockerfile: Dockerfile.dev
container_name: villa-test-e2e
profiles:
- test
environment:
- NODE_ENV=test
- CI=${CI:-true}
- BASE_URL=${BASE_URL:-http://app:3000}
- DATABASE_URL=${DATABASE_URL:-postgresql://villa_test:test_password@postgres-test:5432/villa_test}
volumes:
- .:/app
- /app/node_modules
command: bun test:e2e:chromium
depends_on:
postgres-test:
condition: service_healthy
app:
condition: service_healthy
networks:
- villa-net
ipc: host # Playwright requires shared memory
# ===========================================================================
# API Service (Optional)
# ===========================================================================
api:
build:
context: ./apps/api
dockerfile: Dockerfile
container_name: villa-api
profiles:
- api
- full
ports:
- "${API_PORT:-3001}:3001"
environment:
- NODE_ENV=${NODE_ENV:-development}
- PORT=3001
- APP_ENV=${APP_ENV:-local}
- DATABASE_URL=${DATABASE_URL:-postgresql://villa:villa_dev_password@postgres:5432/villa_dev}
- LOG_LEVEL=${LOG_LEVEL:-debug}
depends_on:
postgres:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:3001/health",
]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
networks:
- villa-net
# =============================================================================
# Networks
# =============================================================================
networks:
villa-net:
name: villa-network
driver: bridge
# =============================================================================
# Volumes
# =============================================================================
volumes:
# Persistent data
postgres_data:
name: villa-postgres-data
# Ephemeral test data
postgres_test_data:
name: villa-postgres-test-data
# Caddy certificates and config
caddy_data:
name: villa-caddy-data
caddy_config:
name: villa-caddy-config