-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
197 lines (190 loc) · 6.28 KB
/
docker-compose.yml
File metadata and controls
197 lines (190 loc) · 6.28 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
# RCE Backend - Unified Docker Configuration
# Controlled by ENV variable (development|test|production)
# Features automatic port allocation if ports are busy
# Usage:
# Development: ENV=development docker compose up
# Testing: ENV=test docker compose up
# Production: ENV=production docker compose up
services:
# MongoDB Database
mongodb:
image: mongo:7-jammy
container_name: rce-mongodb-${ENV:-development}
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME:-admin}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-devpassword}
MONGO_INITDB_DATABASE: ${MONGO_DB:-safeexec_dev}
ports:
# Auto-allocate ports if default is busy
- '${MONGO_PORT:-27017}:27017'
volumes:
- mongodb_data:/data/db
networks:
- rce-network
healthcheck:
test: ['CMD', 'mongosh', '--eval', "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3
# Redis Cache
redis:
image: redis:7-alpine
container_name: rce-redis-${ENV:-development}
restart: unless-stopped
ports:
# Auto-allocate ports if default is busy
- '${REDIS_PORT:-6379}:6379'
volumes:
- redis_data:/data
networks:
- rce-network
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 30s
timeout: 10s
retries: 3
command: >
sh -c "
if [ '${ENV:-development}' = 'production' ] && [ -n '${REDIS_PASSWORD}' ]; then
redis-server --requirepass ${REDIS_PASSWORD}
else
redis-server
fi
"
# Main RCE API Application
rce-api:
build:
context: .
dockerfile: Dockerfile
target: ${ENV:-development}
container_name: rce-api-${ENV:-development}
restart: unless-stopped
ports:
# Auto-allocate ports if default is busy
- '${API_PORT:-5000}:5000'
- '${DEBUG_PORT:-9229}:9229'
environment:
NODE_ENV: ${ENV:-development}
PORT: ${PORT:-5000}
MONGO_USERNAME: ${MONGO_USERNAME:-admin}
MONGO_PASSWORD: ${MONGO_PASSWORD:-devpassword}
MONGO_DB: ${MONGO_DB:-safeexec_dev}
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-safeexec_dev}?authSource=admin&maxPoolSize=50&minPoolSize=5
REDIS_URI: redis://${REDIS_PASSWORD:+:${REDIS_PASSWORD}@}redis:6379
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-change-in-production}
JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-24h}
DOCKER_HOST: /var/run/docker.sock
LOG_LEVEL: ${LOG_LEVEL:-info}
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-http://localhost:3000}
API_BASE_URL: ${API_BASE_URL:-http://localhost}
SWAGGER_UI_ENABLED: ${SWAGGER_UI_ENABLED:-true}
MAX_SUBMISSIONS_PER_MINUTE: ${MAX_SUBMISSIONS_PER_MINUTE:-100}
MAX_SUBMISSIONS_PER_HOUR: ${MAX_SUBMISSIONS_PER_HOUR:-1000}
MAX_SUBMISSIONS_PER_DAY: ${MAX_SUBMISSIONS_PER_DAY:-10000}
EXECUTOR_TIMEOUT_MS: ${EXECUTOR_TIMEOUT_MS:-30000}
EXECUTOR_MEMORY_LIMIT_MB: ${EXECUTOR_MEMORY_LIMIT_MB:-256}
EXECUTOR_CPU_LIMIT: ${EXECUTOR_CPU_LIMIT:-1.0}
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
- app_logs:/app/logs
# Development: Source code mounting disabled due to path with spaces
# For development, rebuild the image after code changes using yarn docker:dev:build
# Run as root to access Docker socket - this is acceptable for development
user: 'root'
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
networks:
- rce-network
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:5000/health']
interval: 30s
timeout: 10s
retries: 3
command: >
sh -c "
if [ '${ENV:-development}' = 'development' ]; then
yarn dev
elif [ '${ENV:-development}' = 'test' ]; then
yarn test
else
yarn start
fi
"
# Queue Worker (Production and Development)
rce-worker:
build:
context: .
dockerfile: Dockerfile
target: ${ENV:-development}
container_name: rce-worker-${ENV:-development}
restart: unless-stopped
environment:
NODE_ENV: ${ENV:-development}
MONGO_USERNAME: ${MONGO_USERNAME:-admin}
MONGO_PASSWORD: ${MONGO_PASSWORD:-devpassword}
MONGO_DB: ${MONGO_DB:-safeexec_dev}
MONGODB_URI: mongodb://${MONGO_USERNAME:-admin}:${MONGO_PASSWORD:-devpassword}@mongodb:27017/${MONGO_DB:-safeexec_dev}?authSource=admin&maxPoolSize=50&minPoolSize=5
REDIS_URI: redis://${REDIS_PASSWORD:+:${REDIS_PASSWORD}@}redis:6379
JWT_SECRET: ${JWT_SECRET:-dev-jwt-secret-change-in-production}
DOCKER_HOST: /var/run/docker.sock
LOG_LEVEL: ${LOG_LEVEL:-info}
EXECUTOR_TIMEOUT_MS: ${EXECUTOR_TIMEOUT_MS:-30000}
EXECUTOR_MEMORY_LIMIT_MB: ${EXECUTOR_MEMORY_LIMIT_MB:-256}
EXECUTOR_CPU_LIMIT: ${EXECUTOR_CPU_LIMIT:-1.0}
volumes:
- /var/run/docker.sock:/var/run/docker.sock:rw
- app_logs:/app/logs
# Run as root to access Docker socket - this is acceptable for development
user: 'root'
depends_on:
mongodb:
condition: service_healthy
redis:
condition: service_healthy
networks:
- rce-network
command: yarn worker
deploy:
replicas: ${WORKER_REPLICAS:-4} # Increased default workers for better performance
# Nginx Reverse Proxy
nginx:
build:
context: .
dockerfile: docker/nginx/Dockerfile
container_name: rce-nginx-${ENV:-development}
restart: unless-stopped
ports:
# Auto-allocate ports if default is busy
- '${NGINX_HTTP_PORT:-80}:80'
- '${NGINX_HTTPS_PORT:-443}:443'
depends_on:
- rce-api
networks:
- rce-network
environment:
- NGINX_ENV=${ENV:-development}
- BACKEND_HOST=rce-api
- BACKEND_PORT=5000
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost/health']
interval: 30s
timeout: 10s
retries: 3
networks:
rce-network:
driver: bridge
name: rce-network-${ENV:-development}
volumes:
mongodb_data:
driver: local
name: rce-mongodb-data-${ENV:-development}
redis_data:
driver: local
name: rce-redis-data-${ENV:-development}
app_logs:
driver: local
name: rce-app-logs-${ENV:-development}