This repository was archived by the owner on May 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
263 lines (249 loc) · 9.07 KB
/
Copy pathdocker-compose.yml
File metadata and controls
263 lines (249 loc) · 9.07 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
# Timeless-Heroes Docker Compose
# Distributed Architecture for Developer Idle Game
#
# Usage:
# docker compose up -d # Start all services
# docker compose --profile dev up -d # Include dev tools (Redis Commander)
# docker compose logs -f api-gateway # Follow service logs
#
# ARCHITECTURE:
# ┌──────────────────┐ ┌───────────────────┐ ┌──────────────────┐
# │ PowerShell Agent │───>│ API Gateway │───>│ NATS │
# │ (Local PC) │HTTP│ (NestJS Hybrid) │ │ (Message Bus) │
# └──────────────────┘ └───────────────────┘ └────────┬─────────┘
# │ │
# WebSocket + NATS ClientProxy
# │ ┌──────┴─────────┐
# ▼ ▼ ▼
# ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
# │ Frontend │ │ svc-progress │ │ svc-payment │
# │ (Next.js) │ │ (NATS MS) │ │ (Hybrid) │
# └──────────────┘ └──────────────┘ └──────────────┘
# │
# Redis + BullMQ
# │
# ┌──────────────┐
# │ worker-loop │
# │ (BullMQ+NATS)│
# └──────┬───────┘
# ▼
# ┌──────────────┐
# │ PostgreSQL │
# └──────────────┘
services:
# ============================================================================
# INFRASTRUCTURE
# ============================================================================
postgres:
image: postgres:16-alpine
container_name: timeless-postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-timeless}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-timeless_secret}
POSTGRES_DB: ${POSTGRES_DB:-timeless_heroes}
ports:
- '${POSTGRES_PORT:-5432}:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
# Seed script: runs automatically on first DB creation only
- ./scripts/db:/docker-entrypoint-initdb.d:ro
healthcheck:
test:
[
'CMD-SHELL',
'pg_isready -U ${POSTGRES_USER:-timeless} -d ${POSTGRES_DB:-timeless_heroes}',
]
interval: 5s
timeout: 5s
retries: 5
networks:
- timeless-net
redis:
image: redis:7-alpine
container_name: timeless-redis
restart: unless-stopped
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-redis_secret}
ports:
- '${REDIS_PORT:-6379}:6379'
volumes:
- redis_data:/data
healthcheck:
test:
['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD:-redis_secret}', 'ping']
interval: 5s
timeout: 5s
retries: 5
networks:
- timeless-net
nats:
image: nats:2-alpine
container_name: timeless-nats
restart: unless-stopped
ports:
- "4222:4222" # Client connections
- "8222:8222" # HTTP monitoring
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8222/healthz"]
interval: 5s
timeout: 5s
retries: 5
start_period: 5s
networks:
- timeless-net
# Redis Commander - Redis GUI (development only)
redis-commander:
image: rediscommander/redis-commander:latest
container_name: timeless-redis-commander
restart: unless-stopped
environment:
REDIS_HOSTS: local:redis:6379:0:${REDIS_PASSWORD:-redis_secret}
ports:
- '8081:8081'
depends_on:
redis:
condition: service_healthy
profiles:
- dev
networks:
- timeless-net
# ============================================================================
# APPLICATION SERVICES
# ============================================================================
api-gateway:
build:
context: .
dockerfile: ./apps/api-gateway/Dockerfile
container_name: timeless-api-gateway
restart: unless-stopped
ports:
- '${PORT:-3000}:3000'
environment:
NODE_ENV: ${NODE_ENV:-production}
PORT: 3000
DATABASE_URL: postgresql://${POSTGRES_USER:-timeless}:${POSTGRES_PASSWORD:-timeless_secret}@postgres:5432/${POSTGRES_DB:-timeless_heroes}
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-redis_secret}
JWT_SECRET: ${JWT_SECRET:?JWT_SECRET is required - set it in .env}
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-7d}
MAX_CPS: ${MAX_CPS:-100}
MAX_VIOLATIONS: ${MAX_VIOLATIONS:-50}
CORS_ORIGIN: ${CORS_ORIGIN:-*}
NATS_URL: nats://nats:4222
# Service discovery
SVC_USER_PROGRESSION_HOST: svc-user-progression
SVC_USER_PROGRESSION_PORT: 3001
SVC_PAYMENT_HOST: svc-payment
SVC_PAYMENT_PORT: 3003
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
nats:
condition: service_healthy
networks:
- timeless-net
svc-user-progression:
build:
context: .
dockerfile: ./apps/svc-user-progression/Dockerfile
container_name: timeless-svc-progression
restart: unless-stopped
expose:
- '3001'
environment:
NODE_ENV: ${NODE_ENV:-production}
PROGRESSION_PORT: 3001
DATABASE_URL: postgresql://${POSTGRES_USER:-timeless}:${POSTGRES_PASSWORD:-timeless_secret}@postgres:5432/${POSTGRES_DB:-timeless_heroes}
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-redis_secret}
NATS_URL: nats://nats:4222
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
nats:
condition: service_healthy
networks:
- timeless-net
worker-game-loop:
build:
context: .
dockerfile: ./apps/worker-game-loop/Dockerfile
container_name: timeless-worker-game-loop
restart: unless-stopped
# No HTTP port exposed — pure NATS microservice + BullMQ worker
environment:
NODE_ENV: ${NODE_ENV:-production}
DATABASE_URL: postgresql://${POSTGRES_USER:-timeless}:${POSTGRES_PASSWORD:-timeless_secret}@postgres:5432/${POSTGRES_DB:-timeless_heroes}
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-redis_secret}
NATS_URL: nats://nats:4222
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
nats:
condition: service_healthy
networks:
- timeless-net
svc-payment:
build:
context: .
dockerfile: ./apps/svc-payment/Dockerfile
container_name: timeless-svc-payment
restart: unless-stopped
expose:
- '3003'
environment:
NODE_ENV: ${NODE_ENV:-production}
PAYMENT_PORT: 3003
DATABASE_URL: postgresql://${POSTGRES_USER:-timeless}:${POSTGRES_PASSWORD:-timeless_secret}@postgres:5432/${POSTGRES_DB:-timeless_heroes}
REDIS_HOST: redis
REDIS_PORT: 6379
REDIS_PASSWORD: ${REDIS_PASSWORD:-redis_secret}
STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY:-sk_test_placeholder}
STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET:-whsec_placeholder}
NATS_URL: nats://nats:4222
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
nats:
condition: service_healthy
networks:
- timeless-net
web:
build:
context: .
dockerfile: ./apps/web/Dockerfile
container_name: timeless-web
restart: unless-stopped
ports:
- '${WEB_PORT:-8080}:3000'
environment:
NODE_ENV: ${NODE_ENV:-production}
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-http://api-gateway:3000}
depends_on:
- api-gateway
networks:
- timeless-net
# ============================================================================
# VOLUMES & NETWORKS
# ============================================================================
volumes:
postgres_data:
driver: local
redis_data:
driver: local
networks:
timeless-net:
name: timeless-network
driver: bridge