返回 AiToEarn
docker-compose.yml
根目录 / docker-compose.yml
1 services:
2 mongodb:
3 image: mongo:latest
4 container_name: aitoearn-mongodb
5 restart: unless-stopped
6 entrypoint: ["bash", "-c", "openssl rand -base64 756 > /data/mongodb-keyfile && chmod 400 /data/mongodb-keyfile && chown mongodb:mongodb /data/mongodb-keyfile && exec docker-entrypoint.sh mongod --replSet rs0 --keyFile /data/mongodb-keyfile"]
7 environment:
8 MONGO_INITDB_ROOT_USERNAME: admin
9 MONGO_INITDB_ROOT_PASSWORD: password
10 ports:
11 - "27017:27017"
12 volumes:
13 - mongodb-data:/data/db
14 - mongodb-config:/data/configdb
15 networks:
16 - aitoearn-network
17 healthcheck:
18 test: ["CMD-SHELL", "mongosh mongodb://admin:password@localhost:27017/?authSource=admin --quiet --eval \"try { quit(rs.status().ok === 1 ? 0 : 1) } catch(e) { quit(1) }\""]
19 interval: 10s
20 timeout: 5s
21 retries: 10
22 start_period: 40s
23
24 mongodb-rs-init:
25 image: mongo:latest
26 container_name: aitoearn-mongodb-rs-init
27 depends_on:
28 mongodb:
29 condition: service_started
30 entrypoint: ["/bin/sh", "-c", "until mongosh mongodb://admin:password@mongodb:27017/?authSource=admin --quiet --eval \"db.adminCommand('ping').ok\" >/dev/null 2>&1; do sleep 2; done; mongosh mongodb://admin:password@mongodb:27017/?authSource=admin --eval \"try { rs.initiate({_id:'rs0', members:[{_id:0, host:'mongodb:27017'}]}) } catch(e) { if (e.codeName!=='AlreadyInitialized') throw e }\""]
31 restart: "no"
32 networks:
33 - aitoearn-network
34
35 redis:
36 image: redis:latest
37 container_name: aitoearn-redis
38 restart: unless-stopped
39 command: redis-server --requirepass password
40 ports:
41 - "6379:6379"
42 volumes:
43 - redis-data:/data
44 networks:
45 - aitoearn-network
46 healthcheck:
47 test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
48 interval: 10s
49 timeout: 3s
50 retries: 5
51 start_period: 30s
52
53 rustfs:
54 image: rustfs/rustfs:latest
55 container_name: aitoearn-rustfs
56 hostname: rustfs.local
57 restart: unless-stopped
58 environment:
59 RUSTFS_ACCESS_KEY: rustfsadmin
60 RUSTFS_SECRET_KEY: rustfsadmin
61 ports:
62 - "9001:9001"
63 volumes:
64 - rustfs-data:/data
65 networks:
66 aitoearn-network:
67 aliases:
68 - rustfs.local
69 healthcheck:
70 test: ["CMD", "curl", "-f", "http://localhost:9000/health"]
71 interval: 10s
72 timeout: 5s
73 retries: 5
74 start_period: 30s
75
76 aitoearn-init:
77 image: node:lts-alpine
78 container_name: aitoearn-init
79 restart: "no"
80 depends_on:
81 mongodb:
82 condition: service_healthy
83 volumes:
84 - ./scripts/init.mjs:/app/init.mjs:ro
85 - ./scripts/init-package.json:/app/package.json:ro
86 - init-data:/data/init
87 working_dir: /app
88 environment:
89 MONGO_URI: mongodb://admin:password@mongodb:27017
90 JWT_SECRET: ${JWT_SECRET:?Set JWT_SECRET to the same random key as backend auth.secret}
91 DB_NAME: aitoearn
92 AUTO_LOGIN_TOKEN_PATH: /data/init/token.txt
93 entrypoint: /bin/sh -c "npm install --omit=dev 2>/dev/null && node init.mjs"
94 networks:
95 - aitoearn-network
96
97 rustfs-init:
98 image: amazon/aws-cli:latest
99 container_name: aitoearn-rustfs-init
100 depends_on:
101 rustfs:
102 condition: service_healthy
103 environment:
104 AWS_ACCESS_KEY_ID: rustfsadmin
105 AWS_SECRET_ACCESS_KEY: rustfsadmin
106 AWS_DEFAULT_REGION: us-east-1
107 AWS_EC2_METADATA_DISABLED: "true"
108 networks:
109 - aitoearn-network
110 entrypoint: >
111 /bin/sh -c "
112 aws --endpoint-url http://rustfs.local:9000 s3 mb s3://aitoearn || true;
113 aws --endpoint-url http://rustfs.local:9000 s3api put-bucket-policy --bucket aitoearn --policy '{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::aitoearn/*\"}]}';
114 exit 0;
115 "
116
117 aitoearn-ai:
118 image: aitoearn/aitoearn-ai:latest
119 pull_policy: always
120 container_name: aitoearn-ai
121 restart: unless-stopped
122 depends_on:
123 mongodb:
124 condition: service_healthy
125 redis:
126 condition: service_healthy
127 volumes:
128 - ./project/aitoearn-backend/apps/aitoearn-ai/config/config.yaml:/app/config.yaml:rw
129 networks:
130 - aitoearn-network
131 healthcheck:
132 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3010/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) })"]
133 interval: 30s
134 timeout: 10s
135 retries: 3
136 start_period: 60s
137
138 aitoearn-server:
139 image: aitoearn/aitoearn-server:latest
140 pull_policy: always
141 container_name: aitoearn-server
142 restart: unless-stopped
143 depends_on:
144 mongodb:
145 condition: service_healthy
146 redis:
147 condition: service_healthy
148 aitoearn-ai:
149 condition: service_healthy
150 volumes:
151 - ./project/aitoearn-backend/apps/aitoearn-server/config/config.yaml:/app/config.yaml:rw
152 networks:
153 - aitoearn-network
154 healthcheck:
155 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3002/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) })"]
156 interval: 30s
157 timeout: 10s
158 retries: 3
159 start_period: 60s
160
161 aitoearn-web:
162 image: aitoearn/aitoearn-web:latest
163 pull_policy: always
164 container_name: aitoearn-web
165 restart: unless-stopped
166 depends_on:
167 aitoearn-server:
168 condition: service_healthy
169 aitoearn-init:
170 condition: service_completed_successfully
171 volumes:
172 - init-data:/data/init:ro
173 networks:
174 - aitoearn-network
175 command: ["/bin/sh", "-c", "AUTO_LOGIN_TOKEN=$$(cat /data/init/token.txt 2>/dev/null || true); if [ -z \"$$AUTO_LOGIN_TOKEN\" ]; then echo 'AUTO_LOGIN_TOKEN is missing. Check the aitoearn-init container logs.' >&2; exit 1; fi; export AUTO_LOGIN_TOKEN; exec node server.js"]
176 environment:
177 NODE_ENV: production
178 NEXT_TELEMETRY_DISABLED: 1
179 healthcheck:
180 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000', (r) => { process.exit(r.statusCode < 500 ? 0 : 1) }).on('error', () => process.exit(1))"]
181 interval: 10s
182 timeout: 5s
183 retries: 6
184 start_period: 30s
185
186 nginx:
187 image: nginx:alpine
188 container_name: aitoearn-nginx
189 restart: unless-stopped
190 depends_on:
191 aitoearn-web:
192 condition: service_healthy
193 aitoearn-server:
194 condition: service_healthy
195 aitoearn-ai:
196 condition: service_healthy
197 ports:
198 - "8080:80"
199 - "9000:9000"
200 volumes:
201 - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
202 networks:
203 - aitoearn-network
204 healthcheck:
205 test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/_nhealth"]
206 interval: 10s
207 timeout: 5s
208 retries: 3
209 start_period: 10s
210
211 networks:
212 aitoearn-network:
213 driver: bridge
214 name: aitoearn-network
215
216 volumes:
217 mongodb-data:
218 driver: local
219 mongodb-config:
220 driver: local
221 redis-data:
222 driver: local
223 rustfs-data:
224 driver: local
225 init-data:
226 driver: local
227
227 lines YAML