-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
274 lines (261 loc) · 10.3 KB
/
docker-compose.yml
File metadata and controls
274 lines (261 loc) · 10.3 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
version: '3.8'
services:
traefik:
image: traefik:latest
container_name: traefik
restart: unless-stopped
command:
- --providers.docker=true
- --providers.docker.exposedbydefault=false
- --providers.file.directory=/traefik/dynamic
- --providers.file.watch=true
- --entrypoints.web.address=:80
- --entrypoints.websecure.address=:443
- --api.insecure=true
- --log.level=INFO
- --accesslog=true
- --accesslog.bufferingsize=100
- --accesslog.filepath=/traefik/access.log
# Prometheus metrics configuration
- --metrics.prometheus=true
- --metrics.prometheus.buckets=0.1,0.3,1.0,3.0,5.0
- --metrics.prometheus.addEntryPointsLabels=true
- --metrics.prometheus.addServicesLabels=true
ports:
- "80:80"
- "443:443"
- "8080:8080" # API dashboard and Prometheus metrics
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik:/traefik
networks:
- traefik-network
- portlogistics-network
labels:
- "traefik.enable=true"
backend:
build:
context: .
dockerfile: Dockerfile.backend
# backend: do not publish host ports when using Traefik (Traefik will route)
deploy:
replicas: 3
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
environment:
- ASPNETCORE_ENVIRONMENT=Development
# Force HTTP only in local development to avoid Kestrel attempting to load a PFX
- ASPNETCORE_URLS=http://+:5000
- ASPNETCORE_Kestrel__Certificates__Default__Path=
- ASPNETCORE_Kestrel__Certificates__Default__Password=
- Database__Provider=sqlite
- ConnectionStrings__Sqlite=Data Source=/app/data/portlogistics.db
# For local development we don't mount a PFX; remove the Kestrel certificate
# env vars below or mount a valid PFX at ./certs/aspnetapp.pfx with correct permissions
volumes:
- ./data:/app/data
# Note: HTTPS certificate mount removed for local dev to avoid permission issues.
# To enable HTTPS in production, mount a valid PFX and set the Kestrel env vars.
networks:
- portlogistics-network
- traefik-network
labels:
- "traefik.enable=true"
# API routes
- "traefik.http.routers.portlogistics-backend.rule=Host(`api.portlogistics.local`) && PathPrefix(`/api`)"
- "traefik.http.routers.portlogistics-backend.entrypoints=web,websecure"
# Swagger route on main domain
- "traefik.http.routers.portlogistics-swagger.rule=Host(`portlogistics.local`) && PathPrefix(`/swagger`)"
- "traefik.http.routers.portlogistics-swagger.entrypoints=web,websecure"
- "traefik.http.routers.portlogistics-swagger.priority=100"
- "traefik.http.routers.portlogistics-swagger.service=portlogistics-backend"
# Middleware removed for load balancing testing
# - "traefik.http.routers.portlogistics-backend.middlewares=restrict-dei@file"
- "traefik.http.services.portlogistics-backend.loadbalancer.server.port=5000"
# Load balancing and sticky session configuration
- "traefik.http.services.portlogistics-backend.loadbalancer.sticky.cookie=true"
- "traefik.http.services.portlogistics-backend.loadbalancer.sticky.cookie.name=portlogistics_lb"
- "traefik.http.services.portlogistics-backend.loadbalancer.sticky.cookie.httponly=true"
# Health check configuration for Traefik's load balancer
- "traefik.http.services.portlogistics-backend.loadbalancer.healthcheck.path=/api/health"
- "traefik.http.services.portlogistics-backend.loadbalancer.healthcheck.interval=10s"
- "traefik.http.services.portlogistics-backend.loadbalancer.healthcheck.timeout=3s"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/api/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s
frontend:
build:
context: .
dockerfile: Dockerfile.frontend
container_name: portlogistics-frontend
depends_on:
- backend
networks:
- portlogistics-network
- traefik-network
# Lightweight app proxy service: exposes the SPA to Traefik on container port 80
app:
image: nginx:alpine
container_name: portlogistics-app
depends_on:
- frontend
networks:
- portlogistics-network
- traefik-network
volumes:
- ./traefik/app-proxy.conf:/etc/nginx/conf.d/default.conf:ro
labels:
- "traefik.enable=true"
# Router: route by host - adjust host to your deployment hostname as needed
- "traefik.http.routers.portlogistics.rule=Host(`portlogistics.local`)"
- "traefik.http.routers.portlogistics.entrypoints=web,websecure"
# Attach the file-based whitelist middleware
# Note: middleware removed for local testing. Re-add `restrict-dei@file` for DEI-only access in production.
# Tell Traefik to forward requests to the container port 80 (nginx listens on 80)
- "traefik.http.services.portlogistics-service.loadbalancer.server.port=80"
healthcheck:
test: ["CMD", "curl", "-f", "-I", "http://127.0.0.1/"]
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
oem-service:
build:
context: ./Application/OEMService
dockerfile: Dockerfile
deploy:
replicas: 3
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://+:5001
- Database__Provider=sqlite
- ConnectionStrings__DefaultConnection=Data Source=/app/data/OEMService.db
volumes:
- ./Application/OEMService/data:/app/data
networks:
- portlogistics-network
- traefik-network
labels:
- "traefik.enable=true"
# Route 1: api.portlogistics.local/api/oem/* (for direct API access)
- "traefik.http.routers.oem-service.rule=Host(`api.portlogistics.local`) && PathPrefix(`/api/oem`)"
- "traefik.http.routers.oem-service.entrypoints=web,websecure"
# Route 2: portlogistics.local/oem-api/* (for frontend access)
- "traefik.http.routers.oem-service-frontend.rule=Host(`portlogistics.local`) && PathPrefix(`/oem-api`)"
- "traefik.http.routers.oem-service-frontend.entrypoints=web,websecure"
- "traefik.http.routers.oem-service-frontend.middlewares=oem-stripprefix"
# Route 3: OEM Swagger at /oem-swagger (no strip, OEM serves at this path)
- "traefik.http.routers.oem-swagger.rule=Host(`portlogistics.local`) && PathPrefix(`/oem-swagger`)"
- "traefik.http.routers.oem-swagger.entrypoints=web,websecure"
- "traefik.http.routers.oem-swagger.priority=100"
- "traefik.http.routers.oem-swagger.service=oem-service"
# Middleware to convert /oem-api/* to /api/oem/*
- "traefik.http.middlewares.oem-stripprefix.replacepathregex.regex=^/oem-api/(.*)"
- "traefik.http.middlewares.oem-stripprefix.replacepathregex.replacement=/api/oem/$$1"
# Load balancer service configuration
- "traefik.http.services.oem-service.loadbalancer.server.port=5001"
# Load balancing and sticky session configuration
- "traefik.http.services.oem-service.loadbalancer.sticky.cookie=true"
- "traefik.http.services.oem-service.loadbalancer.sticky.cookie.name=oem_lb"
- "traefik.http.services.oem-service.loadbalancer.sticky.cookie.httponly=true"
# Health check configuration for Traefik's load balancer
- "traefik.http.services.oem-service.loadbalancer.healthcheck.path=/api/oem/health"
- "traefik.http.services.oem-service.loadbalancer.healthcheck.interval=10s"
- "traefik.http.services.oem-service.loadbalancer.healthcheck.timeout=3s"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5001/api/oem/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s
prolog:
image: swipl:latest
container_name: portlogistics-prolog
restart: unless-stopped
# Mount our prolog scripts into the container and start the server
volumes:
- ./Application/BackendService/Prolog:/prolog:ro
working_dir: /prolog
command: ["swipl", "-q", "-s", "/prolog/prolog_server.pl"]
ports:
- "5050:5050"
networks:
- portlogistics-network
prometheus:
image: prom/prometheus:latest
container_name: portlogistics-prometheus
restart: unless-stopped
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'
volumes:
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus-data:/prometheus
networks:
- traefik-network
- portlogistics-network
ports:
- "9090:9090"
depends_on:
- traefik
grafana:
image: grafana/grafana:latest
container_name: portlogistics-grafana
restart: unless-stopped
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=portlogistics2024
- GF_USERS_ALLOW_SIGN_UP=false
- GF_INSTALL_PLUGINS=grafana-piechart-panel
volumes:
- grafana-data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning:ro
- ./monitoring/grafana/dashboards:/var/lib/grafana/dashboards:ro
networks:
- traefik-network
- portlogistics-network
ports:
- "3000:3000"
depends_on:
- prometheus
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer-data:/data
networks:
- traefik-network
ports:
- "9000:9000"
labels:
- "traefik.enable=true"
- "traefik.http.routers.portainer.rule=Host(`portlogistics.local`) && PathPrefix(`/portainer`)"
- "traefik.http.routers.portainer.entrypoints=web,websecure"
- "traefik.http.routers.portainer.priority=100"
- "traefik.http.services.portainer.loadbalancer.server.port=9000"
networks:
portlogistics-network:
driver: bridge
traefik-network:
driver: bridge
volumes:
portlogistics-data:
prometheus-data:
driver: local
grafana-data:
driver: local
portainer-data:
driver: local