-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.prod.yml
More file actions
271 lines (238 loc) · 9.15 KB
/
compose.prod.yml
File metadata and controls
271 lines (238 loc) · 9.15 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
# =========================================
# Compose PRODUCTION avec Infrastructure
# Traefik + PostgreSQL + Application
# =========================================
services:
# =====================================
# REVERSE PROXY - Traefik
# Ce service gère le routage, TLS, et la sécurité
# =====================================
traefik:
image: traefik:v3.0
restart: unless-stopped
security_opt:
- no-new-privileges:true
- label=disable
command:
# Dashboard et API
- "--ping=true" # Active le endpoint ping pour healthcheck
- "--api.dashboard=true"
- "--api.insecure=false"
# Logs
- "--log.level=${TRAEFIK_LOG_LEVEL:-INFO}"
- "--accesslog=true"
- "--accesslog.filepath=/logs/access.log"
# Providers
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=product-network"
- "--providers.file.directory=/etc/traefik/dynamic"
- "--providers.file.watch=true"
# Entrypoints
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
# Redirection HTTP -> HTTPS
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
# Metrics (optionnel)
- "--metrics.prometheus=true"
- "--metrics.prometheus.addEntryPointsLabels=true"
- "--metrics.prometheus.addServicesLabels=true"
ports:
- "${TRAEFIK_HTTP_PORT:-8888}:80"
- "${TRAEFIK_HTTPS_PORT:-5443}:443"
- "${TRAEFIK_DASHBOARD_PORT:-8080}:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik/dynamic:/etc/traefik/dynamic
- ./traefik/logs:/logs
- ./traefik/secrets:/run/secrets:ro
networks:
- product-network
labels:
# Dashboard sécurisé via middleware auth défini dans fichier dynamique
- "traefik.enable=true"
- "traefik.http.routers.dashboard.rule=Host(`traefik.${APP_DOMAIN:-localhost}`)"
- "traefik.http.routers.dashboard.entrypoints=websecure"
- "traefik.http.routers.dashboard.tls=true"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth@file"
healthcheck:
test: ["CMD", "traefik", "healthcheck", "--ping"]
interval: 10s
timeout: 5s
retries: 3
# =====================================
# BASE DE DONNÉES - PostgreSQL
# =====================================
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
LANG: en_US.UTF-8
LC_ALL: en_US.UTF-8
POSTGRES_DB: ${DB_NAME:-products}
POSTGRES_USER: ${DB_USER:-tpuser}
POSTGRES_PASSWORD: ${DB_PASSWORD:-Tp@2026}
# Options PostgreSQL pour performance
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
# Pas de port exposé sur l'hôte pour sécurité
# Accès uniquement via réseau interne
# expose:
# - "5432"
volumes:
- postgres_data:/var/lib/postgresql/data
# Scripts d'initialisation (optionnel)
- ./postgres/init:/docker-entrypoint-initdb.d
networks:
- product-network
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U ${DB_USER:-tpuser} -d ${DB_NAME:-products}",
]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# Limites de ressources (optionnel mais recommandé)
deploy:
resources:
limits:
cpus: "1.0"
memory: 512M
reservations:
cpus: "0.5"
memory: 256M
# =====================================
# APPLICATION - Product Catalog
# =====================================
product-catalog:
image: ${IMAGE_GROUP:-brunoe}/${IMAGE_NAME:-product-catalog}:${IMAGE_TAG:-1.0.0-jib}
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
traefik:
condition: service_healthy
environment:
# Configuration base de données
DB_HOST: postgres
DB_PORT: 5432
DB_USER: ${DB_USER:-tpuser}
DB_PASSWORD: ${DB_PASSWORD:-Tp@2026}
# Stratégie Hibernate (validate en production)
HIBERNATE_GENERATION: ${HIBERNATE_GENERATION:-validate}
# Logs (WARNING en production)
LOG_LEVEL: ${LOG_LEVEL:-WARN}
LOG_SQL: ${LOG_SQL:-false}
# JVM Options optimisées pour production
JAVA_OPTS: >-
-Xms512m
-Xmx1024m
-XX:+UseContainerSupport
-XX:MaxRAMPercentage=75.0
-XX:+UseG1GC
-XX:MaxGCPauseMillis=100
-XX:+DisableExplicitGC
# Pas de port exposé, uniquement via Traefik
expose:
- "8080"
networks:
- product-network
# Traefik labels : routage HTTPS sécurisé avec Let's Encrypt,
# redirection HTTP->HTTPS, load balancing et middlewares globaux (sécurité + rate limiting)
labels:
- "traefik.enable=true" # Active Traefik pour ce container
# Router HTTPS principal
- "traefik.http.routers.product-catalog.rule=Host(`${APP_DOMAIN:-products.localhost}`)" # Route vers le host de l'application
- "traefik.http.routers.product-catalog.entrypoints=websecure" # Utilise l'entrypoint HTTPS
- "traefik.http.routers.product-catalog.tls=true" # TLS activé
- "traefik.http.routers.product-catalog.tls.options=default" # Utilise le TLS self-signed défini dans dynamic.yml
- "traefik.http.routers.product-catalog.middlewares=secure-headers@file,rate-limit-global@file" # Middleware headers + rate-limit défini dans dynamic.yml
- "traefik.http.services.product-catalog.loadbalancer.server.port=8080" # Port interne de l'application
# Router HTTP → HTTPS (redirection)
- "traefik.http.routers.product-catalog-http.rule=Host(`${APP_DOMAIN:-products.localhost}`)" # Route HTTP vers le même host
- "traefik.http.routers.product-catalog-http.entrypoints=web" # Entrypoint HTTP
- "traefik.http.routers.product-catalog-http.middlewares=redirect-to-https@file" # Redirection HTTP → HTTPS
healthcheck:
test:
["CMD-SHELL", "curl -f http://localhost:8080/health/ready || exit 1"]
interval: 30s
timeout: 5s
retries: 5
start_period: 30s
# Limites de ressources
deploy:
resources:
limits:
cpus: "2.0"
memory: 1536M
reservations:
cpus: "1.0"
memory: 768M
# =====================================
# MONITORING - Prometheus (optionnel)
# =====================================
prometheus:
image: prom/prometheus:latest
restart: unless-stopped
profiles:
- monitoring
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--storage.tsdb.retention.time=30d"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:Z
- prometheus_data:/prometheus
networks:
- product-network
labels:
- "traefik.enable=true" # Active Traefik pour ce container
- "traefik.http.routers.prometheus.rule=Host(`prometheus.${APP_DOMAIN:-localhost}`)" # Route les requêtes HTTPS vers ce host
- "traefik.http.routers.prometheus.entrypoints=websecure" # Utilise l'entrypoint HTTPS
- "traefik.http.routers.prometheus.tls=true" # Active TLS sur ce router
- "traefik.http.routers.prometheus.tls.options=default" # Utilise le TLS self-signed défini dans dynamic.yml
- "traefik.http.routers.prometheus.middlewares=auth@file" # Middleware Basic Auth + redirection HTTP → HTTPS
- "traefik.http.services.prometheus.loadbalancer.server.port=9090" # Port interne sur lequel Prometheus écoute
# =====================================
# MONITORING - Grafana (optionnel)
# =====================================
grafana:
image: grafana/grafana:latest
restart: unless-stopped
profiles:
- monitoring
environment:
GF_SECURITY_ADMIN_USER: ${GRAFANA_USER:-admin}
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_PASSWORD:-admin}
GF_SERVER_ROOT_URL: https://grafana.${APP_DOMAIN:-localhost}
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards:Z
- ./grafana/datasources:/etc/grafana/provisioning/datasources:Z
networks:
- product-network
depends_on:
- prometheus
labels:
- "traefik.enable=true" # Active Traefik pour ce container
- "traefik.http.routers.grafana.rule=Host(`grafana.${APP_DOMAIN:-localhost}`)" # Route les requêtes vers le host Grafana
- "traefik.http.routers.grafana.entrypoints=websecure" # Utilise l'entrypoint HTTPS
- "traefik.http.routers.grafana.tls=true" # TLS activé
- "traefik.http.routers.grafana.tls.options=default" # Utilise le TLS self-signed défini dans dynamic.yml
- "traefik.http.routers.grafana.middlewares=auth@file" # Middleware Basic Auth + redirection HTTP → HTTPS
- "traefik.http.services.grafana.loadbalancer.server.port=3000" # Port interne Grafana
volumes:
postgres_data:
driver: local
prometheus_data:
driver: local
grafana_data:
driver: local
networks:
product-network:
driver: bridge
name: product-network