balaji958685 commited on
Commit
89d44b7
Β·
verified Β·
1 Parent(s): 6faa536

Add docker-compose.yml - 7-service stack

Browse files
Files changed (1) hide show
  1. docker-compose.yml +184 -0
docker-compose.yml ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: "3.9"
2
+
3
+ services:
4
+ # ─── Message Broker & Cache ───────────────────────────────────────
5
+ redis:
6
+ image: redis:7-alpine
7
+ container_name: smartclass-redis
8
+ ports:
9
+ - "6379:6379"
10
+ volumes:
11
+ - redis_data:/data
12
+ command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
13
+ healthcheck:
14
+ test: ["CMD", "redis-cli", "ping"]
15
+ interval: 10s
16
+ timeout: 3s
17
+ retries: 5
18
+ restart: unless-stopped
19
+ networks:
20
+ - smartclass-net
21
+
22
+ # ─── Primary Database ─────────────────────────────────────────────
23
+ postgres:
24
+ image: postgres:16-alpine
25
+ container_name: smartclass-postgres
26
+ ports:
27
+ - "5432:5432"
28
+ environment:
29
+ POSTGRES_USER: ${POSTGRES_USER:-sc_user}
30
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-sc_password}
31
+ POSTGRES_DB: ${POSTGRES_DB:-smartclass}
32
+ volumes:
33
+ - postgres_data:/var/lib/postgresql/data
34
+ - ./services/api/init_db.sql:/docker-entrypoint-initdb.d/init.sql:ro
35
+ healthcheck:
36
+ test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-sc_user} -d ${POSTGRES_DB:-smartclass}"]
37
+ interval: 10s
38
+ timeout: 5s
39
+ retries: 5
40
+ restart: unless-stopped
41
+ networks:
42
+ - smartclass-net
43
+
44
+ # ─── FastAPI Server ────────────────────────────────────────────────
45
+ api:
46
+ build:
47
+ context: ./services/api
48
+ dockerfile: Dockerfile
49
+ container_name: smartclass-api
50
+ ports:
51
+ - "8000:8000"
52
+ environment:
53
+ DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-sc_user}:${POSTGRES_PASSWORD:-sc_password}@postgres:5432/${POSTGRES_DB:-smartclass}
54
+ REDIS_URL: redis://redis:6379
55
+ JWT_SECRET_KEY: ${JWT_SECRET_KEY:?JWT_SECRET_KEY must be set}
56
+ CORS_ORIGINS: ${CORS_ORIGINS:-["http://localhost:5173"]}
57
+ ENVIRONMENT: ${ENVIRONMENT:-development}
58
+ LOG_LEVEL: ${LOG_LEVEL:-info}
59
+ depends_on:
60
+ redis:
61
+ condition: service_healthy
62
+ postgres:
63
+ condition: service_healthy
64
+ healthcheck:
65
+ test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health')"]
66
+ interval: 15s
67
+ timeout: 5s
68
+ retries: 3
69
+ start_period: 30s
70
+ restart: unless-stopped
71
+ networks:
72
+ - smartclass-net
73
+
74
+ # ─── Background Worker (Redis Consumer) ───────────────────────────
75
+ api_worker:
76
+ build:
77
+ context: ./services/api
78
+ dockerfile: Dockerfile
79
+ container_name: smartclass-worker
80
+ command: python -m app.worker
81
+ environment:
82
+ DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-sc_user}:${POSTGRES_PASSWORD:-sc_password}@postgres:5432/${POSTGRES_DB:-smartclass}
83
+ REDIS_URL: redis://redis:6379
84
+ ENVIRONMENT: ${ENVIRONMENT:-development}
85
+ LOG_LEVEL: ${LOG_LEVEL:-info}
86
+ depends_on:
87
+ redis:
88
+ condition: service_healthy
89
+ postgres:
90
+ condition: service_healthy
91
+ api:
92
+ condition: service_healthy
93
+ restart: unless-stopped
94
+ networks:
95
+ - smartclass-net
96
+
97
+ # ─── Edge Pipeline (Test Mode) ────────────────────────────────────
98
+ edge:
99
+ build:
100
+ context: .
101
+ dockerfile: Dockerfile
102
+ container_name: smartclass-edge
103
+ ports:
104
+ - "9100:9100"
105
+ environment:
106
+ REDIS_URL: redis://redis:6379
107
+ REDIS_PASSWORD: ${REDIS_PASSWORD:-}
108
+ EDGE_CONFIG_PATH: /opt/smartclass/config/edge_config.yaml
109
+ PYTHONPATH: /opt/smartclass/src
110
+ EDGE_MODE: ${EDGE_MODE:-test}
111
+ volumes:
112
+ - ./config:/opt/smartclass/config:ro
113
+ - ./models:/opt/smartclass/models:ro
114
+ - ./data:/opt/smartclass/data
115
+ depends_on:
116
+ redis:
117
+ condition: service_healthy
118
+ healthcheck:
119
+ test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:9100/metrics')"]
120
+ interval: 15s
121
+ timeout: 5s
122
+ retries: 3
123
+ start_period: 45s
124
+ restart: unless-stopped
125
+ networks:
126
+ - smartclass-net
127
+
128
+ # ─── Frontend (React + Nginx) ─────────────────────────────────────
129
+ frontend:
130
+ build:
131
+ context: ./frontend
132
+ dockerfile: Dockerfile
133
+ args:
134
+ VITE_API_URL: ${VITE_API_URL:-http://localhost:8000}
135
+ container_name: smartclass-frontend
136
+ ports:
137
+ - "5173:80"
138
+ depends_on:
139
+ api:
140
+ condition: service_healthy
141
+ healthcheck:
142
+ test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:80/"]
143
+ interval: 15s
144
+ timeout: 5s
145
+ retries: 3
146
+ restart: unless-stopped
147
+ networks:
148
+ - smartclass-net
149
+
150
+ # ─── Metrics Collection ───────────────────────────────────────────
151
+ prometheus:
152
+ image: prom/prometheus:v2.51.0
153
+ container_name: smartclass-prometheus
154
+ ports:
155
+ - "9090:9090"
156
+ volumes:
157
+ - ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
158
+ - ./monitoring/smartclass_alerts.yml:/etc/prometheus/rules/smartclass_alerts.yml:ro
159
+ - prometheus_data:/prometheus
160
+ command:
161
+ - '--config.file=/etc/prometheus/prometheus.yml'
162
+ - '--storage.tsdb.path=/prometheus'
163
+ - '--storage.tsdb.retention.time=30d'
164
+ - '--web.enable-lifecycle'
165
+ depends_on:
166
+ - api
167
+ - edge
168
+ healthcheck:
169
+ test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://127.0.0.1:9090/-/healthy"]
170
+ interval: 15s
171
+ timeout: 5s
172
+ retries: 3
173
+ restart: unless-stopped
174
+ networks:
175
+ - smartclass-net
176
+
177
+ volumes:
178
+ redis_data:
179
+ postgres_data:
180
+ prometheus_data:
181
+
182
+ networks:
183
+ smartclass-net:
184
+ driver: bridge