返回 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: change-this-jwt-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: minio/mc:latest
99 container_name: aitoearn-rustfs-init
100 depends_on:
101 rustfs:
102 condition: service_healthy
103 networks:
104 - aitoearn-network
105 entrypoint: >
106 /bin/sh -c "
107 mc alias set rustfs http://rustfs.local:9000 rustfsadmin rustfsadmin;
108 mc mb rustfs/aitoearn --ignore-existing;
109 mc anonymous set download rustfs/aitoearn;
110 exit 0;
111 "
112
113 aitoearn-ai:
114 image: aitoearn/aitoearn-ai:latest
115 pull_policy: always
116 container_name: aitoearn-ai
117 restart: unless-stopped
118 depends_on:
119 mongodb:
120 condition: service_healthy
121 redis:
122 condition: service_healthy
123 volumes:
124 - ./project/aitoearn-backend/apps/aitoearn-ai/config/config.yaml:/app/config.yaml:rw
125 networks:
126 - aitoearn-network
127 healthcheck:
128 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3010/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) })"]
129 interval: 30s
130 timeout: 10s
131 retries: 3
132 start_period: 60s
133
134 aitoearn-server:
135 image: aitoearn/aitoearn-server:latest
136 pull_policy: always
137 container_name: aitoearn-server
138 restart: unless-stopped
139 depends_on:
140 mongodb:
141 condition: service_healthy
142 redis:
143 condition: service_healthy
144 aitoearn-ai:
145 condition: service_healthy
146 volumes:
147 - ./project/aitoearn-backend/apps/aitoearn-server/config/config.yaml:/app/config.yaml:rw
148 networks:
149 - aitoearn-network
150 healthcheck:
151 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3002/health', (r) => { process.exit(r.statusCode === 200 ? 0 : 1) })"]
152 interval: 30s
153 timeout: 10s
154 retries: 3
155 start_period: 60s
156
157 aitoearn-web:
158 image: aitoearn/aitoearn-web:latest
159 pull_policy: always
160 container_name: aitoearn-web
161 restart: unless-stopped
162 depends_on:
163 aitoearn-server:
164 condition: service_healthy
165 aitoearn-init:
166 condition: service_completed_successfully
167 volumes:
168 - init-data:/data/init:ro
169 networks:
170 - aitoearn-network
171 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"]
172 environment:
173 NODE_ENV: production
174 NEXT_TELEMETRY_DISABLED: 1
175 healthcheck:
176 test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000', (r) => { process.exit(r.statusCode < 500 ? 0 : 1) }).on('error', () => process.exit(1))"]
177 interval: 10s
178 timeout: 5s
179 retries: 6
180 start_period: 30s
181
182 nginx:
183 image: nginx:alpine
184 container_name: aitoearn-nginx
185 restart: unless-stopped
186 depends_on:
187 aitoearn-web:
188 condition: service_healthy
189 aitoearn-server:
190 condition: service_healthy
191 aitoearn-ai:
192 condition: service_healthy
193 ports:
194 - "8080:80"
195 - "9000:9000"
196 volumes:
197 - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
198 networks:
199 - aitoearn-network
200 healthcheck:
201 test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/_nhealth"]
202 interval: 10s
203 timeout: 5s
204 retries: 3
205 start_period: 10s
206
207 networks:
208 aitoearn-network:
209 driver: bridge
210 name: aitoearn-network
211
212 volumes:
213 mongodb-data:
214 driver: local
215 mongodb-config:
216 driver: local
217 redis-data:
218 driver: local
219 rustfs-data:
220 driver: local
221 init-data:
222 driver: local
223
223 lines YAML