forked from AndreyTsibin/keywai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
286 lines (276 loc) · 9.13 KB
/
Copy pathdocker-compose.yml
File metadata and controls
286 lines (276 loc) · 9.13 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
services:
# ===========================================
# Infrastructure Services
# ===========================================
postgres:
image: postgres:16-alpine
container_name: keywai_postgres
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB:-keywai}
POSTGRES_USER: ${POSTGRES_USER:-keywai}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-keywai_secret}
ports:
# 127.0.0.1: БД не должна торчать наружу — доступ только с хоста
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
volumes:
# Bind mount - data persists on host filesystem
- ./data/postgres:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-keywai} -d ${POSTGRES_DB:-keywai}"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
container_name: keywai_redis
restart: always
ports:
# 127.0.0.1: Redis без auth — доступ только с хоста
- "127.0.0.1:${REDIS_PORT:-6379}:6379"
volumes:
# Bind mount - data persists on host filesystem
- ./data/redis:/data
command: redis-server --appendonly yes
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
# Mailpit - dev SMTP server (catches outgoing emails, web UI on 8025)
mailpit:
image: axllent/mailpit:latest
container_name: keywai_mailpit
restart: unless-stopped
ports:
# 127.0.0.1: web UI показывает ВСЕ письма (вкл. токены сброса пароля)
- "127.0.0.1:1025:1025" # SMTP
- "127.0.0.1:8025:8025" # Web UI
environment:
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
MP_MAX_MESSAGES: 5000
# ===========================================
# Application Services
# ===========================================
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: keywai_backend
restart: always
# Entrypoint: ждёт postgres, генерирует недостающие ключи, применяет миграции
entrypoint: ["/bin/sh", "/app/docker/entrypoint.sh"]
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- ./backend:/app
# Shared config (AI models)
- ./shared:/shared
# Static files
- ./data/static:/app/staticfiles
# Auto-generated keys (DJANGO_SECRET_KEY / FERNET_KEY) persist here
- ./data/keys:/keys
# Media served from backend/media/ via ./backend:/app mount
env_file:
# Optional: свежий форк стартует без backend/.env (ключи сгенерируются)
- path: ./backend/.env
required: false
environment:
# SERVICE_ROLE=backend — единственный, кто гоняет migrate и генерирует ключи
- SERVICE_ROLE=backend
- DB_HOST=postgres
# Дефолты совпадают с сервисом postgres — фреш-форк работает без .env
- DB_NAME=${POSTGRES_DB:-keywai}
- DB_USER=${POSTGRES_USER:-keywai}
- DB_PASSWORD=${POSTGRES_PASSWORD:-keywai_secret}
- REDIS_URL=redis://redis:6379/0
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health/')"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# WebSocket server (ASGI) for real-time updates
# Handles WebSocket connections for progress tracking
daphne:
build:
context: ./backend
dockerfile: Dockerfile
container_name: keywai_daphne
restart: always
entrypoint: ["/bin/sh", "/app/docker/entrypoint.sh"]
command: daphne -b 0.0.0.0 -p 8001 config.asgi:application
ports:
- "8001:8001"
volumes:
- ./backend:/app
- ./shared:/shared
- ./data/keys:/keys
# Media served from backend/media/ via ./backend:/app mount
env_file:
- path: ./backend/.env
required: false
environment:
- DB_HOST=postgres
- DB_NAME=${POSTGRES_DB:-keywai}
- DB_USER=${POSTGRES_USER:-keywai}
- DB_PASSWORD=${POSTGRES_PASSWORD:-keywai_secret}
- REDIS_URL=redis://redis:6379/0
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
# Ждём backend healthy: миграции применены, ключи сгенерированы
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import socket; s=socket.socket(); s.connect(('localhost', 8001)); s.close()"]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
# ===========================================
# Celery Workers (Priority Queues)
# ===========================================
# HIGH priority: User-facing tasks (parsing, clustering, competitors, content)
# These tasks are triggered by user actions and should be processed immediately
celery-high:
build:
context: ./backend
dockerfile: Dockerfile
container_name: keywai_celery_high
restart: always
entrypoint: ["/bin/sh", "/app/docker/entrypoint.sh"]
command: celery -A config worker -Q high,celery --concurrency=4 --loglevel=info -n worker-high@%h
volumes:
- ./backend:/app
- ./shared:/shared
- ./data/keys:/keys
# Media served from backend/media/ via ./backend:/app mount
env_file:
- path: ./backend/.env
required: false
environment:
- DB_HOST=postgres
- DB_NAME=${POSTGRES_DB:-keywai}
- DB_USER=${POSTGRES_USER:-keywai}
- DB_PASSWORD=${POSTGRES_PASSWORD:-keywai_secret}
- REDIS_URL=redis://redis:6379/0
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend:
condition: service_healthy
healthcheck:
# CMD-SHELL: $$HOSTNAME нужен shell для раскрытия (exec-форма слала литерал)
test: ["CMD-SHELL", "celery -A config inspect ping -d worker-high@$$HOSTNAME"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
# LOW priority: Background tasks (cache collection, cleanup, quota sync)
# These tasks run in the background and should not block user tasks
celery-low:
build:
context: ./backend
dockerfile: Dockerfile
container_name: keywai_celery_low
restart: always
entrypoint: ["/bin/sh", "/app/docker/entrypoint.sh"]
command: celery -A config worker -Q low --concurrency=2 --loglevel=info -n worker-low@%h
volumes:
- ./backend:/app
- ./shared:/shared
- ./data/keys:/keys
# Media served from backend/media/ via ./backend:/app mount
env_file:
- path: ./backend/.env
required: false
environment:
- DB_HOST=postgres
- DB_NAME=${POSTGRES_DB:-keywai}
- DB_USER=${POSTGRES_USER:-keywai}
- DB_PASSWORD=${POSTGRES_PASSWORD:-keywai_secret}
- REDIS_URL=redis://redis:6379/0
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "celery -A config inspect ping -d worker-low@$$HOSTNAME"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
celery-beat:
build:
context: ./backend
dockerfile: Dockerfile
container_name: keywai_celery_beat
restart: always
entrypoint: ["/bin/sh", "/app/docker/entrypoint.sh"]
command: celery -A config beat --loglevel=info
volumes:
- ./backend:/app
- ./shared:/shared
- ./data/keys:/keys
env_file:
- path: ./backend/.env
required: false
environment:
- DB_HOST=postgres
- DB_NAME=${POSTGRES_DB:-keywai}
- DB_USER=${POSTGRES_USER:-keywai}
- DB_PASSWORD=${POSTGRES_PASSWORD:-keywai_secret}
- REDIS_URL=redis://redis:6379/0
- REDIS_HOST=redis
- REDIS_PORT=6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend:
condition: service_healthy
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: keywai_frontend
restart: always
ports:
- "5173:5173"
volumes:
- ./frontend:/app
- /app/node_modules
- ./shared:/shared:ro
depends_on:
- backend
healthcheck:
test: ["CMD-SHELL", "node -e \"require('http').get('http://localhost:5173', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))\""]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
# No more named volumes - all data in ./data/ directory