-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
236 lines (216 loc) · 5.88 KB
/
docker-compose.prod.yml
File metadata and controls
236 lines (216 loc) · 5.88 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
# ============================================================
# Docker Compose Production Override
# City Service Provider Application - Production Configuration
# Usage: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# ============================================================
version: '3.8'
services:
# ==================== POSTGRES PRODUCTION ====================
postgres:
restart: always
environment:
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256 --auth-local=scram-sha-256"
command: >
postgres
-c shared_preload_libraries=pg_stat_statements
-c pg_stat_statements.track=all
-c max_connections=200
-c shared_buffers=256MB
-c effective_cache_size=1GB
-c maintenance_work_mem=64MB
-c checkpoint_completion_target=0.9
-c wal_buffers=16MB
-c default_statistics_target=100
-c random_page_cost=1.1
-c effective_io_concurrency=200
-c work_mem=4MB
-c min_wal_size=1GB
-c max_wal_size=4GB
-c max_worker_processes=8
-c max_parallel_workers_per_gather=4
-c max_parallel_workers=8
-c max_parallel_maintenance_workers=4
deploy:
resources:
limits:
memory: 1G
cpus: '1.0'
reservations:
memory: 512M
cpus: '0.5'
# ==================== REDIS PRODUCTION ====================
redis:
restart: always
command: >
redis-server
--requirepass ${REDIS_PASSWORD}
--maxmemory 256mb
--maxmemory-policy allkeys-lru
--save 900 1
--save 300 10
--save 60 10000
--appendonly yes
--appendfsync everysec
deploy:
resources:
limits:
memory: 256M
cpus: '0.5'
reservations:
memory: 128M
cpus: '0.25'
# ==================== BACKEND PRODUCTION ====================
backend:
restart: always
environment:
# Production JVM settings
JAVA_OPTS: >-
-Xms1g
-Xmx2g
-XX:+UseG1GC
-XX:+UseContainerSupport
-XX:MaxRAMPercentage=75.0
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/app/logs/
-XX:+UseStringDeduplication
-XX:+OptimizeStringConcat
-Djava.security.egd=file:/dev/./urandom
-Dspring.profiles.active=prod
# Production Spring Boot settings
SPRING_PROFILES_ACTIVE: prod
SERVER_COMPRESSION_ENABLED: true
SERVER_HTTP2_ENABLED: true
# Database connection pool
SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE: 20
SPRING_DATASOURCE_HIKARI_MINIMUM_IDLE: 10
SPRING_DATASOURCE_HIKARI_CONNECTION_TIMEOUT: 20000
SPRING_DATASOURCE_HIKARI_IDLE_TIMEOUT: 300000
# Logging
LOGGING_LEVEL_ROOT: WARN
LOGGING_LEVEL_COM_EXAMPLE_SERVICEAPP: INFO
LOGGING_FILE_NAME: /app/logs/application.log
LOGGING_LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE: 10MB
LOGGING_LOGBACK_ROLLINGPOLICY_MAX_HISTORY: 30
volumes:
- backend_logs:/app/logs
- backend_uploads:/app/uploads
deploy:
replicas: 2
resources:
limits:
memory: 2G
cpus: '2.0'
reservations:
memory: 1G
cpus: '1.0'
restart_policy:
condition: on-failure
delay: 10s
max_attempts: 3
window: 120s
# Production health check with longer intervals
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/api/health"]
interval: 60s
timeout: 30s
retries: 3
start_period: 120s
# ==================== FRONTEND PRODUCTION ====================
frontend:
restart: always
environment:
# Production environment
REACT_APP_ENVIRONMENT: production
NODE_ENV: production
deploy:
replicas: 2
resources:
limits:
memory: 512M
cpus: '1.0'
reservations:
memory: 256M
cpus: '0.5'
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 60s
# Production health check
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 60s
timeout: 10s
retries: 3
start_period: 60s
# ==================== LOAD BALANCER ====================
nginx:
image: nginx:1.25-alpine
container_name: city-service-nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
- nginx_logs:/var/log/nginx
networks:
- city-service-network
depends_on:
- frontend
- backend
deploy:
resources:
limits:
memory: 256M
cpus: '0.5'
reservations:
memory: 128M
cpus: '0.25'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
# ==================== PRODUCTION VOLUMES ====================
volumes:
postgres_data:
driver: local
driver_opts:
type: none
o: bind
device: /var/lib/docker/volumes/city-service-postgres
redis_data:
driver: local
driver_opts:
type: none
o: bind
device: /var/lib/docker/volumes/city-service-redis
backend_logs:
driver: local
driver_opts:
type: none
o: bind
device: /var/log/city-service/backend
backend_uploads:
driver: local
driver_opts:
type: none
o: bind
device: /var/lib/city-service/uploads
nginx_logs:
driver: local
driver_opts:
type: none
o: bind
device: /var/log/nginx
# ==================== PRODUCTION NETWORKS ====================
networks:
city-service-network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
driver_opts:
com.docker.network.bridge.name: city-service-br0