forked from turms-im/turms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.standalone.yml
355 lines (321 loc) · 11.6 KB
/
docker-compose.standalone.yml
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
# Prerequisites:
# Make sure the loki driver is installed:
# docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
#
# Ways to Run:
# docker-compose -f docker-compose.standalone.yml up --force-recreate
#
# Run in a specific environment (e.g. "dev"):
# Powershell: $env:ENV="dev";docker-compose -f docker-compose.standalone.yml up --force-recreate
# Unix: ENV=dev docker-compose -f docker-compose.standalone.yml up --force-recreate
#
# Run with optional monitoring services (Prometheus+Grafana)
# Run with "--profile monitoring": docker-compose -f docker-compose.standalone.yml --profile monitoring up --force-recreate
#
# Note:
# 1. "mem_limit" is mentioned removed in v3 but still can work in fact if running with compose-v1.29.2
version: "3.9"
# Disable loki because it has a critical bug:
# https://github.com/grafana/loki/issues/2361
x-logging: &logging
logging:
driver: loki
options:
loki-url: "http://host.docker.internal:3100/loki/api/v1/push"
x-logging-mongo: &logging-mongo
logging:
driver: loki
options:
loki-url: "http://host.docker.internal:3100/loki/api/v1/push"
# See https://docs.mongodb.com/manual/reference/log-messages
loki-pipeline-stages: |
- json:
expressions:
time: t."$$date"
- timestamp:
format: RFC3339
source: time
x-logging-turms: &logging-turms
logging:
driver: loki
options:
loki-url: "http://host.docker.internal:3100/loki/api/v1/push"
# The regex has been optimized:
# it takes about 50 steps to parse a single log line
loki-pipeline-stages: |
- multiline:
firstline: '^\d{4}-\d{2}-\d{2}\s\d{1,2}\:'
- regex:
expression: '(?P<time>\d{4}-\d{2}-\d{2}\s\d{1,2}\:\d{2}\:\d{2}\.\d{3})\s+(?P<level>[A-Z]{4,5})\s+(?P<node_type>[A-Z])\s+(?P<node_id>\S*)\s+\[(?P<trace_id>.{19})\]\s+(?P<thread>\S*)\s+(?P<class>\S*)\s+:\s(?P<msg>.*)'
- labels:
node_type:
node_id:
- timestamp:
format: '2006-01-02 15:04:05.000'
source: time
services:
# MongoDB
mongodb-config:
image: mongo:4.4.10-focal
# depends_on:
# - loki
entrypoint: [ "mongod", "--port", "27017", "--configsvr", "--replSet", "rs-config", "--bind_ip_all" ]
healthcheck:
test: [ "CMD", "mongo", "--quiet", "--eval", "db.runCommand(\"ping\").ok" ]
interval: 10s
timeout: 5s
retries: 5
mem_limit: 2g
# <<: *logging-mongo
mongodb-shard:
image: mongo:4.4.10-focal
# depends_on:
# - loki
entrypoint: [ "mongod", "--port", "27017", "--shardsvr", "--replSet", "shard01", "--bind_ip_all" ]
healthcheck:
test: [ "CMD", "mongo", "--quiet", "--eval", "db.runCommand(\"ping\").ok" ]
interval: 10s
timeout: 5s
retries: 5
mem_limit: 2g
# <<: *logging-mongo
mongodb-router:
image: mongo:4.4.10-focal
# depends_on:
# - loki
entrypoint: [ "mongos", "--port", "27017", "--configdb", "rs-config/mongodb-config:27017", "--bind_ip_all" ]
healthcheck:
test: [ "CMD", "mongo", "--quiet", "--eval", "db.runCommand(\"ping\").ok" ]
interval: 10s
timeout: 5s
retries: 5
ports:
- "27017:27017"
mem_limit: 2g
# <<: *logging-mongo
mongodb-setup:
image: "mongo:4.4.10-focal"
depends_on:
mongodb-config:
condition: service_healthy
mongodb-shard:
condition: service_healthy
mongodb-router:
condition: service_started
# Wait 10s for the replica set to elect their primary
entrypoint:
- bash
- -c
- |
mongo --host mongodb-config:27017 --eval "rs.initiate({_id: 'rs-config', configsvr: true, version: 1, members: [ { _id: 0, host : 'mongodb-config:27017' } ] })"
mongo --host mongodb-shard:27017 --eval "rs.initiate({_id: 'shard01', version: 1, members: [ { _id: 0, host : 'mongodb-shard:27017' } ] })"
sleep 10
mongo --host mongodb-router:27017 --eval "sh.addShard('shard01/mongodb-shard:27017')"
restart: "no"
# Redis
redis:
image: redis:6.2-alpine
# depends_on:
# - loki
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
ports:
- "6379:6379"
# <<: *logging
# turms servers
turms-admin:
image: "ghcr.io/turms-im/turms-admin"
pull_policy: always
ports:
- "6510:6510"
# <<: *logging
turms-gateway:
image: "ghcr.io/turms-im/turms-gateway"
pull_policy: always
depends_on:
# loki:
# condition: service_started
mongodb-router:
condition: service_healthy
mongodb-setup:
condition: service_started
redis:
condition: service_healthy
# Wait for turms to ensure turms-gateway can fetch data from DB safely after turms has inited collections
turms-service:
condition: service_healthy
environment:
TURMS_GATEWAY_JVM_OPTS: >
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.port=8849
-Dcom.sun.management.jmxremote.rmi.port=8849
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
-Dspring.profiles.active=${ENV}
-Dturms.cluster.connection.server.port=7610
-Dturms.cluster.connection.server.port-auto-increment=false
-Dturms.cluster.discovery.address.advertise-strategy=advertise_address
-Dturms.cluster.discovery.address.advertise-host=turms-gateway
-Dturms.cluster.shared-config.mongo.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.gateway.mongo.admin.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.gateway.mongo.user.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.gateway.redis.session.uri-list[0]=redis://redis:6379
-Dturms.gateway.redis.location.uri-list[0]=redis://redis:6379
-Dturms.gateway.redis.ip-blocklist.uri=redis://redis:6379
-Dturms.gateway.redis.user-id-blocklist.uri=redis://redis:6379
healthcheck:
test: "curl --fail --silent --user turms:turms turms-gateway:9510/actuator/health | grep UP || exit 1"
interval: 10s
timeout: 5s
retries: 5
mem_limit: 2g
ports:
- "7610:7610" # RPC
- "8849:8849" # JMX
- "9510:9510" # Metrics APIs + Admin APIs
- "10510:10510" # WebSocket
- "11510:11510" # TCP
- "12510:12510" # UDP
ulimits:
nofile:
soft: 1024000
hard: 1024000
# volumes:
# - "./container/turms-gateway/hprof:/opt/turms/turms-gateway/hprof"
# - "./container/turms-gateway/jfr:/opt/turms/turms-gateway/jfr"
# - "./container/turms-gateway/log:/opt/turms/turms-gateway/log"
# - "./container/turms-gateway/config:/opt/turms/turms-gateway/config" # Includes "application.yaml" and "jvm.options"
# <<: *logging-turms
turms-service:
image: "ghcr.io/turms-im/turms-service"
pull_policy: always
depends_on:
# loki:
# condition: service_started
mongodb-router:
condition: service_healthy
mongodb-setup:
condition: service_started
redis:
condition: service_healthy
environment:
TURMS_SERVICE_JVM_OPTS: >
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.port=8839
-Dcom.sun.management.jmxremote.rmi.port=8839
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=localhost
-Dspring.profiles.active=${ENV}
-Dturms.security.password.initial-root-password=${INITIAL_ROOT_PASSWORD:-turms}
-Dturms.cluster.connection.server.port-auto-increment=false
-Dturms.cluster.discovery.address.advertise-strategy=advertise_address
-Dturms.cluster.discovery.address.advertise-host=turms
-Dturms.cluster.shared-config.mongo.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.mongo.admin.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.mongo.user.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.mongo.group.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.mongo.conversation.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.mongo.message.uri=mongodb://mongodb-router:27017/turms-standalone?authSource=admin
-Dturms.service.redis.sequence-id.uri-list[0]=redis://redis:6379
-Dturms.service.redis.session.uri-list[0]=redis://redis:6379
-Dturms.service.redis.location.uri-list[0]=redis://redis:6379
-Dturms.service.redis.ip-blocklist.uri=redis://redis:6379
-Dturms.service.redis.user-id-blocklist.uri=redis://redis:6379
mem_limit: 2g
healthcheck:
test: "curl --fail --silent --user turms:turms turms-service:8510/actuator/health | grep UP || exit 1"
interval: 10s
timeout: 5s
retries: 5
ports:
- "7510:7510" # RPC
- "8510:8510" # Metrics APIs + Admin APIs
- "8839:8839" # JMX
ulimits:
nofile:
soft: 65536
hard: 65536
# volumes:
# - "./container/turms-service/hprof:/opt/turms/turms-service/hprof"
# - "./container/turms-service/jfr:/opt/turms/turms-service/jfr"
# - "./container/turms-service/log:/opt/turms/turms-service/log"
# - "./container/turms-service/config:/opt/turms/turms-service/config" # Includes "application.yaml" and "jvm.options"
# <<: *logging-turms
# optional services for observability - metrics
grafana:
image: grafana/grafana:8.3.3
depends_on:
- prometheus
environment:
- GF_SECURITY_ADMIN_USER=turms
- GF_SECURITY_ADMIN_PASSWORD=turms
ports:
- "3000:3000"
profiles:
- monitoring
restart: unless-stopped
volumes:
- ./ops/grafana/provisioning/:/etc/grafana/provisioning/
prometheus:
image: prom/prometheus:v2.32.1
ports:
- "9090:9090"
profiles:
- monitoring
restart: unless-stopped
volumes:
- ./ops/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
node-exporter:
image: prom/node-exporter:v1.3.1
ports:
- "9100:9100"
profiles:
- monitoring
cadvisor:
# If your server is in China and suffers from the network problem,
# try "gcr.lank8s.cn/cadvisor/cadvisor:v0.43.0"
# or just comment out "cadvisor"
image: gcr.io/cadvisor/cadvisor:v0.43.0
ports:
- "8080:8080"
profiles:
- monitoring
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
# The exporter does NOT support ARM64 currently
# https://github.com/percona/mongodb_exporter/issues/362
mongo-exporter:
image: percona/mongodb_exporter:0.30.0
command:
- '--mongodb.uri=mongodb://mongodb-router:27017'
ports:
- "9216:9216"
profiles:
- monitoring
redis-exporter:
image: oliver006/redis_exporter:v1.33.0
depends_on:
- redis
environment:
- REDIS_ADDR=redis://redis:6379
ports:
- "9121:9121"
profiles:
- monitoring
# Services for observability - logging
# loki:
# image: grafana/loki:2.4.1
# ports:
# - "3100:3100"
# command: -config.file=/etc/loki/local-config.yaml