-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
208 lines (200 loc) · 6.43 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
208 lines (200 loc) · 6.43 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
# =============================================================
# iTrade Production Docker Compose
# =============================================================
# Usage:
# docker compose -f docker-compose.prod.yml up -d
#
# Required env files on the host (created from deploy/env.*.template):
# /opt/itrade/.env.db
# /opt/itrade/.env.console
# /opt/itrade/.env.web
#
# SSL/proxy is handled externally by nginx-proxy-manager.
#
# Startup order:
# db (healthy) → schema-migrator (completed) → console + web
# =============================================================
services:
# ----------------------------------------------------------
# Shared Dependencies Base Image
# ----------------------------------------------------------
# This service builds the shared dependencies image that web,
# console, and schema-migrator all use. Building it first ensures
# dependencies are only installed once, saving significant build time.
# ----------------------------------------------------------
deps:
build:
context: .
dockerfile: Dockerfile.deps
image: itrade-deps:latest
# This service is a build-only target - it's built explicitly in the deploy workflow
# and then used by web, console, and schema-migrator Dockerfiles
profiles:
- build-only
# Prevent this service from running (it's just a base image)
entrypoint: ['/bin/sh', '-c', "echo 'This is a build-only service' && exit 0"]
# ----------------------------------------------------------
# PostgreSQL database
# ----------------------------------------------------------
# NOTE: We use the pgvector-bundled image (pgvector/pgvector:pg18) rather
# than vanilla postgres:18-alpine because the help-KB chatbot relies on
# the `vector` extension. The image is built on top of the official
# postgres:18 (Debian-slim) and remains volume-compatible with previous
# postgres:18 data directories.
# See: https://hub.docker.com/r/pgvector/pgvector
# ----------------------------------------------------------
db:
image: pgvector/pgvector:pg18
container_name: itrade-db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql
env_file:
- /opt/itrade/.env.db
restart: unless-stopped
healthcheck:
test:
[
'CMD-SHELL',
'pg_isready -U $${POSTGRES_USER:-postgres} -d $${POSTGRES_DB:-itrade}',
]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
networks:
- itrade-net
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '3'
# ----------------------------------------------------------
# Schema Migrator (init container — runs once and exits)
# ----------------------------------------------------------
schema-migrator:
image: ${SCHEMA_MIGRATOR_IMAGE:-itrade-schema-migrator:latest}
build:
context: .
dockerfile: apps/console/Dockerfile
target: schema-migrator
container_name: itrade-schema-migrator
env_file:
- /opt/itrade/.env.console # provides DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DB
depends_on:
db:
condition: service_healthy
restart: 'no' # ← run ONCE and exit (init container pattern)
networks:
- itrade-net
logging:
driver: 'json-file'
options:
max-size: '5m'
max-file: '2'
# ----------------------------------------------------------
# Trading Engine (console app)
# ----------------------------------------------------------
console:
image: ${CONSOLE_IMAGE:-itrade-console:latest}
build:
context: .
dockerfile: apps/console/Dockerfile
target: console
container_name: itrade-console
env_file:
- /opt/itrade/.env.console
volumes:
- /opt/itrade/firebase-service-account.json:/secrets/firebase-service-account.json:ro
depends_on:
schema-migrator:
condition: service_completed_successfully
restart: unless-stopped
# Give trading engine time to gracefully close WebSocket connections & flush state
stop_grace_period: 30s
networks:
- itrade-net
logging:
driver: 'json-file'
options:
max-size: '50m'
max-file: '5'
# ----------------------------------------------------------
# Adminer (Database Management UI)
# ----------------------------------------------------------
adminer:
image: adminer
container_name: itrade-adminer
restart: always
ports:
- '8080:8080'
depends_on:
db:
condition: service_healthy
networks:
- itrade-net
logging:
driver: 'json-file'
options:
max-size: '5m'
max-file: '2'
# ----------------------------------------------------------
# Web Application (Next.js)
# ----------------------------------------------------------
# Port 3002 is exposed to the host so that an external
# nginx-proxy-manager can reverse-proxy to it.
# ----------------------------------------------------------
web:
image: ${WEB_IMAGE:-itrade-web:latest}
build:
context: .
dockerfile: apps/web/Dockerfile
container_name: itrade-web
ports:
- '3002:3002'
env_file:
- /opt/itrade/.env.web
volumes:
- /opt/itrade/firebase-service-account.json:/secrets/firebase-service-account.json:ro
depends_on:
db:
condition: service_healthy
restart: unless-stopped
# Graceful shutdown: give Next.js time to finish in-flight requests
stop_grace_period: 15s
healthcheck:
test:
[
'CMD-SHELL',
'node -e "fetch(''http://localhost:3002/'').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"',
]
interval: 15s
timeout: 10s
retries: 3
start_period: 30s
networks:
- itrade-net
- proxy-net
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '3'
# ----------------------------------------------------------
# Volumes
# NOTE: postgres_data is a named volume — it PERSISTS across
# container rebuilds and `docker compose up --build`.
# Only `docker compose down -v` would delete it.
# ----------------------------------------------------------
volumes:
postgres_data:
driver: local
# ----------------------------------------------------------
# Networks
# ----------------------------------------------------------
networks:
itrade-net:
driver: bridge
proxy-net:
external: true