-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
167 lines (157 loc) · 6.26 KB
/
Copy pathdocker-compose.yml
File metadata and controls
167 lines (157 loc) · 6.26 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
# ─────────────────────────────────────────────────────────────────────────────
# Ingrexa — docker-compose.yml
# ─────────────────────────────────────────────────────────────────────────────
# Spins up 5 services with a single command: docker-compose up
# 1. db — PostgreSQL database
# 2. redis — Redis broker + cache + result backend
# 3. backend — Django REST Framework (Gunicorn)
# 4. celery_worker — Celery worker for AI analysis tasks (heavy queue)
# 5. celery_email — Celery worker for email tasks (lightweight queue)
# 6. frontend — React + Vite dev server (or nginx in production)
# ─────────────────────────────────────────────────────────────────────────────
version: '3.9'
services:
# ── 1. PostgreSQL Database ─────────────────────────────────────────────────
db:
image: postgres:16-alpine
container_name: ingrexa_db
restart: unless-stopped
environment:
POSTGRES_DB: ingrexa
POSTGRES_USER: ingrexa_user
POSTGRES_PASSWORD: ingrexa_pass # Change in production!
volumes:
- postgres_data:/var/lib/postgresql/data # Persist data between restarts
ports:
- "5432:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ingrexa_user -d ingrexa" ]
interval: 10s
timeout: 5s
retries: 5
# ── 2. Redis (Broker + Cache + Result Backend) ─────────────────────────────
redis:
image: redis:7-alpine
container_name: ingrexa_redis
restart: unless-stopped
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: redis-server --appendonly yes # Persist task queue to disk
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 10s
timeout: 5s
retries: 5
# ── 3. Django Backend ──────────────────────────────────────────────────────
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: ingrexa_backend
restart: unless-stopped
env_file:
- ./backend/.env # Your real secrets live here (gitignored)
environment:
DATABASE_URL: postgresql://ingrexa_user:ingrexa_pass@db:5432/ingrexa
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/1
DEBUG: "False"
ALLOWED_HOSTS: "localhost,127.0.0.1,backend"
ports:
- "8000:8000"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ./backend:/app
- media_files:/app/media
command: >
sh -c "python manage.py migrate &&
python manage.py collectstatic --noinput &&
gunicorn foodview_api.wsgi:application
--bind 0.0.0.0:8000
--workers 4
--timeout 120
--log-level info"
# ── 4. Celery Worker — AI Analysis Queue (heavy tasks) ────────────────────
celery_worker:
build:
context: ./backend
dockerfile: Dockerfile
container_name: ingrexa_celery_analysis
restart: unless-stopped
env_file:
- ./backend/.env
environment:
DATABASE_URL: postgresql://ingrexa_user:ingrexa_pass@db:5432/ingrexa
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/1
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ./backend:/app
- media_files:/app/media
# concurrency=2: 2 parallel AI analysis tasks max (memory-intensive)
command: >
celery -A foodview_api worker
--loglevel=info
--queues=analysis
--concurrency=2
--hostname=worker-analysis@%h
# ── 5. Celery Worker — Email Queue (lightweight tasks) ────────────────────
celery_email:
build:
context: ./backend
dockerfile: Dockerfile
container_name: ingrexa_celery_email
restart: unless-stopped
env_file:
- ./backend/.env
environment:
DATABASE_URL: postgresql://ingrexa_user:ingrexa_pass@db:5432/ingrexa
REDIS_URL: redis://redis:6379/0
CELERY_BROKER_URL: redis://redis:6379/0
CELERY_RESULT_BACKEND: redis://redis:6379/1
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ./backend:/app
# concurrency=4: emails are fast I/O, we can handle more in parallel
command: >
celery -A foodview_api worker
--loglevel=info
--queues=email
--concurrency=4
--hostname=worker-email@%h
# ── 6. React Frontend ──────────────────────────────────────────────────────
frontend:
image: node:20-alpine
container_name: ingrexa_frontend
working_dir: /app
volumes:
- ./frontend:/app
- /app/node_modules # Prevent host node_modules from bleeding in
ports:
- "3000:3000"
environment:
VITE_API_URL: "http://localhost:8000"
command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
depends_on:
- backend
# ── Named Volumes ──────────────────────────────────────────────────────────
volumes:
postgres_data: # Database files (persisted)
redis_data: # Redis AOF / RDB snapshots (persisted)
media_files: # Uploaded images/media (persisted)