-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
330 lines (320 loc) · 10.2 KB
/
docker-compose.yml
File metadata and controls
330 lines (320 loc) · 10.2 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
# =============================================================================
# SimpleSecCheck - Refactored Docker Compose Configuration
# =============================================================================
# Phase 1: Service Separation & Redis Addition
#
# Changes from original:
# - Split backend into separate FastAPI backend and scanner worker services
# - Added dedicated Redis service with persistence and health checks
# - Fixed circular dependencies and network issues
# - Added proper health checks for all services
# - Improved volume management for better isolation
# =============================================================================
services:
# PostgreSQL Database
postgres:
image: postgres:16-alpine
container_name: SimpleSecCheck_postgres
command: postgres -c log_min_messages=warning -c log_connections=off -c log_disconnections=off -c log_checkpoints=off -c log_lock_waits=off -c log_statement=none -c log_duration=off -c logging_collector=off
environment:
POSTGRES_DB: ${POSTGRES_DB:-simpleseccheck}
POSTGRES_USER: ${POSTGRES_USER:-ssc_user}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C.UTF-8"
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- app
- internal
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-ssc_user} -d ${POSTGRES_DB:-simpleseccheck}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
# Redis Queue Service
redis:
image: redis:7-alpine
container_name: SimpleSecCheck_redis
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru --loglevel warning --syslog-enabled no
volumes:
- redis_data:/data
networks:
- app
- internal
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
# FastAPI Backend Service
# Handles API requests, WebSocket connections, and serves frontend
backend:
build:
context: .
dockerfile: ./backend/Dockerfile
container_name: SimpleSecCheck_backend
volumes:
- ./results:/app/results
- ./uploads:/app/uploads
- .:/project:ro
env_file:
- .env
environment:
- SIMPLESECCHECK_ROOT=/app
- UPLOAD_STORAGE_PATH=/app/uploads
- PYTHONUNBUFFERED=1
- POSTGRES_HOST=${POSTGRES_HOST:-postgres}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- POSTGRES_USER=${POSTGRES_USER:-ssc_user}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB:-simpleseccheck}
- POSTGRES_SSL=${POSTGRES_SSL:-false}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
- LOG_LEVEL=${LOG_LEVEL:-INFO}
ports:
- "8080:8080"
networks:
- app
- internal
read_only: false
tmpfs:
- /tmp:noexec,nosuid,size=100m
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import requests,sys; sys.exit(0 if requests.get('http://localhost:8080/api/health').ok else 1)"]
interval: 30s
timeout: 5s
retries: 3
start_period: 20s
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Resource Limits (Phase 3)
deploy:
resources:
limits:
cpus: '${BACKEND_CPU_LIMIT:-2.0}'
memory: '${BACKEND_MEMORY_LIMIT:-2G}'
pids: 1000
reservations:
cpus: '${BACKEND_CPU_RESERVATION:-0.5}'
memory: '${BACKEND_MEMORY_RESERVATION:-512M}'
# Security Context (Phase 3)
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
# Additional Security (Phase 3)
working_dir: /app
shm_size: 64M
# Scanner Worker Service
# Orchestrates scan execution by managing job queue and starting scanner containers
# - Processes scan jobs from Redis queue
# - Starts scanner containers dynamically via Docker API
# - Provides API for scanner discovery (worker:8081/api/scanners/)
# - Does NOT execute scans itself - scanner container does that
worker:
build:
context: .
dockerfile: ./worker/Dockerfile
container_name: SimpleSecCheck_worker
# No user: - entrypoint runs as root, then drops privileges with gosu
# This is the standard pattern for containers that need Docker socket access
volumes:
- ./results:/app/results
- ./uploads:/app/uploads
- .:/project:ro
- /var/run/docker.sock:/var/run/docker.sock
env_file:
- .env
environment:
- POSTGRES_HOST=${POSTGRES_HOST:-postgres}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- POSTGRES_USER=${POSTGRES_USER:-ssc_user}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB:-simpleseccheck}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
- QUEUE_CONNECTION=${REDIS_URL:-redis://redis:6379}
- RESULTS_DIR_HOST=${PWD}/results
# Container paths (what Scanner container sees inside)
- RESULTS_DIR_CONTAINER=/app/results
# Uploads: backend extracts ZIPs here; worker mounts same path for uploaded_code scans
- UPLOAD_STORAGE_PATH=/app/uploads
ports:
- "8081:8081" # Worker API port for scanner discovery
networks:
- app
- internal
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "python3 -c \"import sys; sys.path.append('/app'); from worker.cli.worker_main import main; main(['--healthcheck'])\""]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Resource Limits (Phase 3)
deploy:
resources:
limits:
cpus: '${WORKER_CPU_LIMIT:-4.0}'
memory: '${WORKER_MEMORY_LIMIT:-4G}'
pids: 2000
reservations:
cpus: '${WORKER_CPU_RESERVATION:-1.0}'
memory: '${WORKER_MEMORY_RESERVATION:-1G}'
# Security Context (Phase 3)
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
- SYS_ADMIN # Required for Docker socket access
# Additional Security (Phase 3)
working_dir: /app
shm_size: 128M
# Scanner CLI Container (Standalone Executor)
# Standalone CLI tool that executes security scans
# - Used by worker: Worker starts this container dynamically for each scan
# - Used manually: docker compose run scanner (for CLI usage without WebUI)
# - Executes scans via scanner.core.orchestrator
# - Runs individual scanner plugins (OWASP, Trivy, etc.)
# - Container is ephemeral (temporary, auto-removed after scan)
scanner:
build:
context: .
dockerfile: ./scanner/Dockerfile
args:
VERSION: 2.0.0
image: simpleseccheck-scanner:latest
container_name: SimpleSecCheck_scanner
command: ["sleep", "infinity"]
volumes:
- ./results:/app/results
- .:/project:ro
environment:
- SCAN_TARGET=${SCAN_TARGET:-}
- TARGET_PATH_IN_CONTAINER=${TARGET_PATH_IN_CONTAINER:-/target}
- RESULTS_DIR_IN_CONTAINER=/app/results
- POSTGRES_HOST=${POSTGRES_HOST:-postgres}
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
- POSTGRES_USER=${POSTGRES_USER:-ssc_user}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB:-simpleseccheck}
- POSTGRES_SSL=${POSTGRES_SSL:-false}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
- NVD_API_KEY=${NVD_API_KEY:-}
- SNYK_TOKEN=${SNYK_TOKEN:-}
networks:
- app
- internal
restart: "no"
stdin_open: true
tty: true
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Resource Limits (Phase 3)
deploy:
resources:
limits:
cpus: '${SCANNER_CPU_LIMIT:-4.0}'
memory: '${SCANNER_MEMORY_LIMIT:-8G}'
pids: 4000
reservations:
cpus: '${SCANNER_CPU_RESERVATION:-1.0}'
memory: '${SCANNER_MEMORY_RESERVATION:-2G}'
# Security Context (Phase 3)
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
cap_add:
- CHOWN
- SETGID
- SETUID
# Additional Security (Phase 3)
working_dir: /app
shm_size: 256M
# Frontend WebUI Service
frontend:
build:
context: .
dockerfile: ./frontend/Dockerfile.nginx
container_name: SimpleSecCheck_frontend
volumes:
- ./results:/app/results
ports:
- "80:80"
environment:
- API_BASE_URL=${API_BASE_URL:-http://backend:8080}
- REDIS_URL=${REDIS_URL:-redis://redis:6379}
networks:
- app
read_only: false
tmpfs:
- /tmp:noexec,nosuid,size=100m
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:80"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
depends_on:
backend:
condition: service_healthy
# Security Context (Phase 3)
security_opt:
- no-new-privileges:true
networks:
app:
driver: bridge
internal:
driver: bridge
internal: true
volumes:
# Data persistence volumes
postgres_data:
driver: local
redis_data:
driver: local
results_data:
driver: local
logs_data:
driver: local
# =============================================================================
# Environment variables (reference)
# =============================================================================
# Required:
# - POSTGRES_PASSWORD: PostgreSQL password
# - REDIS_URL: default redis://redis:6379 if unset
#
# Optional tuning:
# - MAX_CONCURRENT_JOBS on worker (overrides DB); else DB max_concurrent_jobs; else 1
# - API_BASE_URL (default: http://backend:8080)
#
# Scanner resource limits:
# - SCANNER_CPU_LIMIT: Max CPU for scanner (default: 4.0)
# - SCANNER_MEMORY_LIMIT: Max memory for scanner (default: 8G)
# - SCANNER_CPU_RESERVATION: Reserved CPU for scanner (default: 1.0)
# - SCANNER_MEMORY_RESERVATION: Reserved memory for scanner (default: 2G)