-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
192 lines (172 loc) · 4.34 KB
/
docker-compose.yml
File metadata and controls
192 lines (172 loc) · 4.34 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
services:
# PostgreSQL数据库
postgres:
image: postgres:14-alpine
container_name: online-compiler-db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: online_compiler
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./backend/prisma/migrations:/docker-entrypoint-initdb.d/initdb.sql:ro # 初始化SQL
networks:
- compiler-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d online_compiler"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
restart: unless-stopped
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
# Redis缓存和消息队列
redis:
image: redis:7-alpine
container_name: online-compiler-redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
networks:
- compiler-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
start_period: 10s
restart: unless-stopped
command: >
redis-server
--appendonly yes
--maxmemory 256mb
--maxmemory-policy allkeys-lru
deploy:
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
# 后端API服务
backend:
build:
context: ./backend
dockerfile: Dockerfile
args:
NODE_ENV: development
container_name: online-compiler-backend
ports:
- "8000:8000"
environment:
NODE_ENV: development
PORT: 8000
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/online_compiler?schema=public
REDIS_URL: redis://redis:6379
JWT_SECRET: your-secret-key-change-in-production-2025
JWT_EXPIRES_IN: 7d
CORS_ORIGIN: http://localhost:3000
LOG_LEVEL: info
# 执行限制
MAX_EXECUTION_TIME: 10
MAX_MEMORY: 256
MAX_CPU_CORES: 0.5
MAX_DISK_SPACE: 100
MAX_OUTPUT_SIZE: 1024
# 任务队列配置
WORKER_CONCURRENCY: 5
TASK_TIMEOUT: 30000
MAX_RETRY_ATTEMPTS: 3
# 速率限制
RATE_LIMIT_MAX: 100
RATE_LIMIT_WINDOW: 1
MAX_EXECUTIONS_PER_DAY: 500
# 默认管理员账号配置(首次启动自动创建)
DEFAULT_ADMIN_USERNAME: admin
DEFAULT_ADMIN_EMAIL: admin@example.com
DEFAULT_ADMIN_PASSWORD: admin123456
# Docker配置
DOCKER_HOST: unix:///var/run/docker.sock
DOCKER_API_VERSION: '1.41'
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Docker API访问
- /tmp/online-compiler:/tmp/online-compiler # 临时代码目录
- backend_logs:/app/logs # 日志目录
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- compiler-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: '1'
reservations:
memory: 512M
cpus: '0.5'
# 前端服务
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
args:
NODE_ENV: development
container_name: online-compiler-frontend
ports:
- "3000:80"
depends_on:
backend:
condition: service_healthy
networks:
- compiler-network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 5s
retries: 3
start_period: 40s
restart: unless-stopped
deploy:
resources:
limits:
memory: 256M
cpus: '0.25'
reservations:
memory: 128M
cpus: '0.1'
networks:
compiler-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: compiler-bridge
ipam:
config:
- subnet: 172.20.0.0/16
volumes:
postgres_data:
driver: local
redis_data:
driver: local
backend_logs:
driver: local