-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.prod.yml
More file actions
executable file
·397 lines (386 loc) · 9.77 KB
/
Copy pathdocker-compose.prod.yml
File metadata and controls
executable file
·397 lines (386 loc) · 9.77 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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# Production environment (full production deployment)
services:
app:
build:
context: .
dockerfile: Dockerfile
target: production
args:
BUILD_TARGET: ssr
restart: unless-stopped
environment:
- APP_ENV=production
- APP_DEBUG=false
- APP_URL=https://yourdomain.com
- DB_CONNECTION=pgsql
- DB_HOST=postgres
- DB_PORT=5432
- DB_DATABASE=baselaravel12react_prod
- DB_USERNAME=laravel
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_HOST=redis
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_PORT=6379
- CACHE_DRIVER=redis
- SESSION_DRIVER=redis
- QUEUE_CONNECTION=redis
- LOG_CHANNEL=stack
- LOG_STACK=single,slack,sentry
- LOG_LEVEL=error
- MAIL_MAILER=smtp
- SESSION_SECURE_COOKIE=true
- SANCTUM_STATEFUL_DOMAINS=yourdomain.com
- SESSION_DOMAIN=.yourdomain.com
- FILESYSTEM_DISK=minio
- MINIO_ACCESS_KEY=${MINIO_ACCESS_KEY}
- MINIO_SECRET_KEY=${MINIO_SECRET_KEY}
- MINIO_DEFAULT_REGION=us-east-1
- MINIO_BUCKET=laravel-prod
- MINIO_ENDPOINT=http://minio:9000
- MINIO_USE_PATH_STYLE_ENDPOINT=true
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
minio:
condition: service_healthy
networks:
- laravel
- traefik
volumes:
- storage_data:/app/storage/app
- logs_data:/app/storage/logs
labels:
- "traefik.enable=true"
- "traefik.http.routers.app-prod.rule=Host(`yourdomain.com`)"
- "traefik.http.routers.app-prod.tls=true"
- "traefik.http.routers.app-prod.tls.certresolver=letsencrypt"
- "traefik.http.services.app-prod.loadbalancer.server.port=80"
- "traefik.http.middlewares.app-prod-compress.compress=true"
- "traefik.http.middlewares.app-prod-ratelimit.ratelimit.burst=100"
- "traefik.http.middlewares.app-prod-ratelimit.ratelimit.average=50"
- "traefik.http.routers.app-prod.middlewares=app-prod-compress,app-prod-ratelimit"
deploy:
replicas: 3
resources:
limits:
memory: 2G
cpus: '1.0'
reservations:
memory: 1G
cpus: '0.5'
update_config:
parallelism: 1
delay: 10s
failure_action: rollback
order: start-first
rollback_config:
parallelism: 1
delay: 10s
restart_policy:
condition: any
delay: 5s
max_attempts: 3
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_DB: baselaravel12react_prod
POSTGRES_USER: laravel
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256 --auth-local=scram-sha-256"
volumes:
- postgres_prod_data:/var/lib/postgresql/data
- ./docker/postgres/prod-backup:/backup
- ./docker/postgres/postgresql.conf:/etc/postgresql/postgresql.conf
command: postgres -c config_file=/etc/postgresql/postgresql.conf
healthcheck:
test: ["CMD-SHELL", "pg_isready -U laravel"]
interval: 30s
timeout: 10s
retries: 5
networks:
- laravel
deploy:
resources:
limits:
memory: 2G
cpus: '1.0'
reservations:
memory: 1G
cpus: '0.5'
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
redis:
image: redis:7-alpine
restart: unless-stopped
command: >
redis-server
--requirepass ${REDIS_PASSWORD}
--appendonly yes
--maxmemory 512mb
--maxmemory-policy allkeys-lru
--save 900 1
--save 300 10
--save 60 10000
volumes:
- redis_prod_data:/data
- ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- laravel
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "3"
ssr:
build:
context: .
dockerfile: Dockerfile
target: production
restart: unless-stopped
environment:
- NODE_ENV=production
- SSR_PORT=13714
networks:
- laravel
command: node bootstrap/ssr/ssr.mjs
deploy:
replicas: 2
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "3"
worker:
build:
context: .
dockerfile: Dockerfile
target: production
restart: unless-stopped
environment:
- APP_ENV=production
- APP_DEBUG=false
- DB_CONNECTION=pgsql
- DB_HOST=postgres
- DB_PORT=5432
- DB_DATABASE=baselaravel12react_prod
- DB_USERNAME=laravel
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_HOST=redis
- REDIS_PASSWORD=${REDIS_PASSWORD}
- QUEUE_CONNECTION=redis
- LOG_LEVEL=error
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- laravel
volumes:
- storage_data:/app/storage/app
- logs_data:/app/storage/logs
command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600 --memory=512
deploy:
replicas: 5
resources:
limits:
memory: 1G
cpus: '0.5'
reservations:
memory: 512M
cpus: '0.25'
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
scheduler:
build:
context: .
dockerfile: Dockerfile
target: production
restart: unless-stopped
environment:
- APP_ENV=production
- APP_DEBUG=false
- DB_CONNECTION=pgsql
- DB_HOST=postgres
- DB_PORT=5432
- DB_DATABASE=baselaravel12react_prod
- DB_USERNAME=laravel
- DB_PASSWORD=${DB_PASSWORD}
- REDIS_HOST=redis
- REDIS_PASSWORD=${REDIS_PASSWORD}
depends_on:
postgres:
condition: service_healthy
networks:
- laravel
volumes:
- storage_data:/app/storage/app
- logs_data:/app/storage/logs
command: >
sh -c "while true; do
php artisan schedule:run --no-interaction
sleep 60
done"
deploy:
resources:
limits:
memory: 512M
cpus: '0.25'
reservations:
memory: 256M
cpus: '0.1'
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "3"
# Database backup service
backup:
image: postgres:16-alpine
restart: "no"
environment:
PGPASSWORD: ${DB_PASSWORD}
volumes:
- ./docker/postgres/prod-backup:/backup
- postgres_prod_data:/var/lib/postgresql/data:ro
networks:
- laravel
profiles:
- backup
command: >
sh -c "
timestamp=$$(date +%Y%m%d_%H%M%S)
pg_dump -h postgres -U laravel -d baselaravel12react_prod > /backup/prod_backup_$$timestamp.sql
find /backup -name 'prod_backup_*.sql' -mtime +7 -delete
echo 'Backup completed at $$timestamp'
"
# Log aggregator (optional)
log-aggregator:
image: fluent/fluent-bit:latest
restart: unless-stopped
volumes:
- ./docker/fluent-bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- logs_data:/var/log/app:ro
- /var/lib/docker/containers:/var/lib/docker/containers:ro
networks:
- laravel
profiles:
- logging
deploy:
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
# Monitoring (optional)
prometheus:
image: prom/prometheus:latest
restart: unless-stopped
volumes:
- ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
networks:
- laravel
- monitoring
profiles:
- monitoring
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
minio:
image: minio/minio:latest
restart: unless-stopped
environment:
- MINIO_ROOT_USER=${MINIO_ACCESS_KEY}
- MINIO_ROOT_PASSWORD=${MINIO_SECRET_KEY}
volumes:
- minio_prod_data:/data
networks:
- laravel
labels:
- "traefik.enable=true"
- "traefik.http.routers.minio-prod.rule=Host(`minio.yourdomain.com`)"
- "traefik.http.routers.minio-prod.tls=true"
- "traefik.http.routers.minio-prod.tls.certresolver=letsencrypt"
- "traefik.http.services.minio-prod.loadbalancer.server.port=9001"
command: server /data --console-address ":9001"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
reservations:
memory: 512M
cpus: '0.25'
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
volumes:
postgres_prod_data:
driver: local
driver_opts:
type: none
o: bind
device: /var/lib/docker/volumes/postgres_prod_data
redis_prod_data:
driver: local
storage_data:
driver: local
logs_data:
driver: local
prometheus_data:
driver: local
minio_prod_data:
driver: local
networks:
laravel:
driver: overlay
attachable: true
traefik:
external: true
monitoring:
external: true
name: monitoring