-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocker-compose.yml
242 lines (231 loc) · 5.26 KB
/
docker-compose.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
version: "3.8"
services:
# Frontend Web Application
web:
build:
context: ./src/web
dockerfile: Dockerfile
args:
- API_URL=http://api:3000
- NODE_ENV=production
ports:
- "80:80"
depends_on:
- api
networks:
- app_network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:80/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 5s
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
security_opt:
- no-new-privileges:true
read_only: true
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Backend API Service
api:
build:
context: ./src/backend
dockerfile: Dockerfile
args:
- NODE_ENV=production
ports:
- "3000:3000"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
environment:
- NODE_ENV=production
- PORT=3000
- DB_HOST=postgres
- DB_PORT=5432
- DB_NAME=saas_metrics
- DB_USER=postgres
- REDIS_HOST=redis
- REDIS_PORT=6379
- ELASTIC_HOST=elasticsearch
- ELASTIC_PORT=9200
networks:
- app_network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
security_opt:
- no-new-privileges:true
read_only: true
volumes:
- api_logs:/app/logs
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# PostgreSQL Database
postgres:
image: postgres:14-alpine
environment:
- POSTGRES_DB=saas_metrics
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- app_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
security_opt:
- no-new-privileges:true
# Redis Cache
redis:
image: redis:6.2-alpine
command: redis-server --requirepass ${REDIS_PASSWORD} --appendonly yes
volumes:
- redis_data:/data
networks:
- app_network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
security_opt:
- no-new-privileges:true
# Elasticsearch
elasticsearch:
image: elasticsearch:7.17.0
environment:
- node.name=es01
- cluster.name=saas-metrics-es
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
networks:
- app_network
healthcheck:
test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health | grep -vq '\"status\":\"red\"'"]
interval: 20s
timeout: 10s
retries: 3
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
ulimits:
memlock:
soft: -1
hard: -1
# Kibana
kibana:
image: kibana:7.17.0
depends_on:
- elasticsearch
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
networks:
- app_network
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
# Prometheus Metrics
prometheus:
image: prom/prometheus:v2.45.0
volumes:
- ./infrastructure/docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
networks:
- app_network
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
# Grafana Dashboards
grafana:
image: grafana/grafana:9.5.0
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD__FILE=/run/secrets/grafana_password
- GF_USERS_ALLOW_SIGN_UP=false
networks:
- app_network
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
volumes:
postgres_data:
driver: local
redis_data:
driver: local
elasticsearch_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
api_logs:
driver: local
networks:
app_network:
driver: bridge
internal: true
ipam:
driver: default
config:
- subnet: 172.20.0.0/16
driver_opts:
encrypted: "true"
secrets:
postgres_password:
file: ./secrets/postgres_password.txt
redis_password:
file: ./secrets/redis_password.txt
grafana_password:
file: ./secrets/grafana_password.txt