-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
187 lines (175 loc) · 5.1 KB
/
Copy pathdocker-compose.yml
File metadata and controls
187 lines (175 loc) · 5.1 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
# DevOps Task Manager — full local stack.
# All secrets are injected from the environment (.env); none are committed.
# Run: cp .env.example .env && docker compose up --build
x-logging: &default-logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
x-security: &hardening
security_opt:
- no-new-privileges:true
services:
# --- MongoDB ---
mongodb:
image: mongo:7.0
container_name: task-manager-db
restart: unless-stopped
<<: *hardening
logging: *default-logging
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME:-admin}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:?MONGO_PASSWORD is required}
MONGO_INITDB_DATABASE: taskmanager
# Bound to loopback only — not exposed on all host interfaces.
ports:
- "127.0.0.1:27017:27017"
volumes:
- mongodb_data:/data/db
networks:
- app-network
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 5s
retries: 5
# --- Backend API (FastAPI) ---
backend:
build:
context: ./backend
dockerfile: Dockerfile
image: task-manager-backend:local
container_name: task-manager-api
restart: unless-stopped
<<: *hardening
logging: *default-logging
environment:
PORT: 8000
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD}@mongodb:27017/taskmanager?authSource=admin
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://localhost:3000}
RATE_LIMIT: ${RATE_LIMIT:-100/minute}
ports:
- "127.0.0.1:8000:8000"
depends_on:
mongodb:
condition: service_healthy
networks:
- app-network
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 30s
timeout: 10s
retries: 3
# --- Frontend (React + nginx, unprivileged) ---
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
image: task-manager-frontend:local
container_name: task-manager-frontend
restart: unless-stopped
<<: *hardening
logging: *default-logging
# Host 3000 -> container 8080 (nginx-unprivileged), bound to loopback.
ports:
- "127.0.0.1:3000:8080"
depends_on:
- backend
networks:
- app-network
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/"]
interval: 30s
timeout: 10s
retries: 3
# --- Prometheus ---
prometheus:
image: prom/prometheus:v2.55.1
container_name: prometheus
restart: unless-stopped
<<: *hardening
logging: *default-logging
volumes:
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- ./monitoring/prometheus/alert_rules.yml:/etc/prometheus/alert_rules.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
ports:
- "127.0.0.1:9090:9090"
networks:
- app-network
# --- Alertmanager ---
alertmanager:
image: prom/alertmanager:v0.27.0
container_name: alertmanager
restart: unless-stopped
<<: *hardening
logging: *default-logging
volumes:
- ./monitoring/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--storage.path=/alertmanager'
ports:
- "127.0.0.1:9093:9093"
networks:
- app-network
# --- node-exporter (host metrics) ---
node-exporter:
image: prom/node-exporter:v1.8.2
container_name: node-exporter
restart: unless-stopped
<<: *hardening
logging: *default-logging
command:
- '--path.rootfs=/host'
volumes:
- /:/host:ro,rslave
networks:
- app-network
# --- mongodb-exporter (database metrics) ---
mongodb-exporter:
image: percona/mongodb_exporter:0.43.1
container_name: mongodb-exporter
restart: unless-stopped
<<: *hardening
logging: *default-logging
command:
- '--mongodb.uri=mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD}@mongodb:27017/admin'
- '--collect-all'
depends_on:
mongodb:
condition: service_healthy
networks:
- app-network
# --- Grafana ---
grafana:
image: grafana/grafana:11.4.0
container_name: grafana
restart: unless-stopped
<<: *hardening
logging: *default-logging
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:?GRAFANA_PASSWORD is required}
- GF_USERS_ALLOW_SIGN_UP=false
- GF_AUTH_ANONYMOUS_ENABLED=false
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
- ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources:ro
ports:
- "127.0.0.1:3002:3000"
depends_on:
- prometheus
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
mongodb_data:
prometheus_data:
grafana_data: