-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
203 lines (195 loc) · 8.66 KB
/
Copy pathMakefile
File metadata and controls
203 lines (195 loc) · 8.66 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
SHELL := /usr/bin/env bash
.SHELLFLAGS := -euo pipefail -c
.PHONY: start stop health configure demo help
.DEFAULT_GOAL := help
help: ## Show available targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}'
demo: ## Start in demo mode — no Ollama or model downloads; AI responses are pre-scripted
@if [ ! -f .env ]; then \
echo "ERROR: .env not found. Copy .env.example and fill in the values."; \
exit 1; \
fi
@printf '\n'
@printf '\033[0;33m╔════════════════════════════════════════════════════════════════╗\033[0m\n'
@printf '\033[0;33m║ ⚠ D E M O M O D E A C T I V E ⚠ ║\033[0m\n'
@printf '\033[0;33m╠════════════════════════════════════════════════════════════════╣\033[0m\n'
@printf '\033[0;33m║ Ollama and LLM models are NOT started. ║\033[0m\n'
@printf '\033[0;33m║ All AI responses are pre-scripted demo data. ║\033[0m\n'
@printf '\033[0;33m║ No large model downloads required (~0 MB vs ~8+ GB). ║\033[0m\n'
@printf '\033[0;33m║ ║\033[0m\n'
@printf '\033[0;33m║ To switch to FULL AI (requires Ollama + llama3/mistral): ║\033[0m\n'
@printf '\033[0;33m║ make stop && make start ║\033[0m\n'
@printf '\033[0;33m╚════════════════════════════════════════════════════════════════╝\033[0m\n'
@printf '\n'
@echo "==> Building and starting demo stack..."
docker compose -f docker-compose.yml -f docker-compose.demo.yml up --build -d
@echo ""; \
echo "==> Waiting for APIs to be ready..."; \
_wait_for() { \
local name=$$1 url=$$2; \
local attempts=0; \
until curl -sf "$$url" > /dev/null 2>&1; do \
attempts=$$((attempts + 1)); \
if [ $$attempts -ge 30 ]; then \
echo " TIMEOUT: $$name did not become ready in time."; \
return 1; \
fi; \
sleep 2; \
done; \
echo " OK $$name"; \
}; \
_wait_for "patient-api" "http://localhost:8001/health"; \
_wait_for "doctor-api" "http://localhost:8002/health"; \
_wait_for "postcare-api" "http://localhost:8003/health"; \
echo ""; \
echo "==> Demo stack is up."; \
echo ""; \
echo " Patient Portal http://localhost:3000 (demo banner visible)"; \
echo " Doctor Dashboard http://localhost:3001 (demo banner visible)"; \
echo " Patient API docs http://localhost:8001/docs"; \
echo " Doctor API docs http://localhost:8002/docs"; \
echo " PostCare API docs http://localhost:8003/docs"; \
echo ""; \
echo " NOTE: AI responses are pre-scripted. Run 'make stop && make start' for full AI."
start: ## Build and start all services, then wait for APIs to be ready
@if [ ! -f .env ]; then \
echo "ERROR: .env not found. Copy .env.example and fill in the values."; \
exit 1; \
fi
@echo "==> Building and starting all services..."
docker compose up --build -d
@echo ""; \
echo "==> Waiting for APIs to be ready..."; \
_wait_for() { \
local name=$$1 url=$$2; \
local attempts=0; \
until curl -sf "$$url" > /dev/null 2>&1; do \
attempts=$$((attempts + 1)); \
if [ $$attempts -ge 30 ]; then \
echo " TIMEOUT: $$name did not become ready in time."; \
return 1; \
fi; \
sleep 2; \
done; \
echo " OK $$name"; \
}; \
_wait_for "patient-api" "http://localhost:8001/health"; \
_wait_for "doctor-api" "http://localhost:8002/health"; \
_wait_for "postcare-api" "http://localhost:8003/health"; \
echo ""; \
echo "==> Stack is up."; \
echo ""; \
echo " Patient Portal http://localhost:3000"; \
echo " Doctor Dashboard http://localhost:3001"; \
echo " Patient API docs http://localhost:8001/docs"; \
echo " Doctor API docs http://localhost:8002/docs"; \
echo " PostCare API docs http://localhost:8003/docs"; \
echo ""; \
echo "Run 'make health' to check service status at any time."; \
echo "Run 'make stop' to shut everything down."
configure: ## Interactively set CORS_ORIGINS and COOKIE_DOMAIN in .env (creates .env from .env.example if missing)
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "==> Created .env from .env.example"; \
fi
@echo ""
@echo "==> CORS & Cookie Configuration"
@echo " Leave blank to keep the current value shown in brackets."
@echo ""
@current_cors=$$(grep -E '^CORS_ORIGINS=' .env | cut -d= -f2-); \
printf " CORS_ORIGINS [$$current_cors]: "; \
read new_cors; \
if [ -n "$$new_cors" ]; then \
if grep -q '^CORS_ORIGINS=' .env; then \
sed -i.bak "s|^CORS_ORIGINS=.*|CORS_ORIGINS=$$new_cors|" .env && rm -f .env.bak; \
else \
echo "CORS_ORIGINS=$$new_cors" >> .env; \
fi; \
echo " Updated CORS_ORIGINS=$$new_cors"; \
fi
@current_domain=$$(grep -E '^COOKIE_DOMAIN=' .env | cut -d= -f2-); \
printf " COOKIE_DOMAIN [$$current_domain]: "; \
read new_domain; \
if [ -n "$$new_domain" ]; then \
if grep -q '^COOKIE_DOMAIN=' .env; then \
sed -i.bak "s|^COOKIE_DOMAIN=.*|COOKIE_DOMAIN=$$new_domain|" .env && rm -f .env.bak; \
else \
echo "COOKIE_DOMAIN=$$new_domain" >> .env; \
fi; \
echo " Updated COOKIE_DOMAIN=$$new_domain"; \
fi
@echo ""
@echo "==> Done. Run 'make start' to apply changes."
stop: ## Stop all services (data volumes preserved; use 'docker compose down -v' to remove)
@echo "==> Stopping all services..."
docker compose down
@echo "==> Done. Data volumes are preserved (postgres_data, ollama_data)."
@echo " To also delete all data: docker compose down -v"
health: ## Check container status and API health endpoints
@GREEN='\033[0;32m'; RED='\033[0;31m'; YELLOW='\033[0;33m'; NC='\033[0m'; \
_check_http() { \
local name=$$1 url=$$2 body status; \
if body=$$(curl -sf --max-time 3 "$$url" 2>/dev/null); then \
status=$$(echo "$$body" | grep -o '"status":"[^"]*"' | head -1 | cut -d'"' -f4); \
if [ "$$status" = "ok" ]; then \
echo -e " $${GREEN}OK$${NC} $$name ($$url)"; \
elif [ "$$status" = "degraded" ]; then \
echo -e " $${YELLOW}DEGRADED$${NC} $$name ($$url)"; \
echo " $$body"; \
else \
echo -e " $${GREEN}UP$${NC} $$name ($$url)"; \
fi; \
else \
echo -e " $${RED}DOWN$${NC} $$name ($$url)"; \
fi; \
}; \
_check_docker() { \
local name=$$1 service=$$2 state; \
state=$$(docker compose ps --format json "$$service" 2>/dev/null \
| grep -o '"State":"[^"]*"' | head -1 | cut -d'"' -f4); \
if [ "$$state" = "running" ]; then \
echo -e " $${GREEN}RUNNING$${NC} $$name"; \
elif [ -z "$$state" ]; then \
echo -e " $${RED}NOT FOUND$${NC} $$name (not started)"; \
else \
echo -e " $${RED}$$state$${NC} $$name"; \
fi; \
}; \
echo ""; \
echo "=== Container Status ==="; \
_check_docker "postgres" "postgres"; \
_check_docker "redis" "redis"; \
_check_docker "ollama" "ollama"; \
_check_docker "patient-api" "patient-api"; \
_check_docker "doctor-api" "doctor-api"; \
_check_docker "postcare-api" "postcare-api"; \
_check_docker "patient-portal" "patient-portal"; \
_check_docker "doctor-portal" "doctor-portal"; \
echo ""; \
echo "=== API Health ==="; \
_check_http "patient-api" "http://localhost:8001/health"; \
_check_http "doctor-api" "http://localhost:8002/health"; \
_check_http "postcare-api" "http://localhost:8003/health"; \
echo ""; \
echo "=== Ollama ==="; \
if curl -sf --max-time 3 "http://localhost:11434/api/tags" > /dev/null 2>&1; then \
models=$$(curl -sf --max-time 3 "http://localhost:11434/api/tags" \
| grep -o '"name":"[^"]*"' | cut -d'"' -f4 | tr '\n' ' '); \
if [ -n "$$models" ]; then \
echo -e " $${GREEN}UP$${NC} Models available: $$models"; \
else \
echo -e " $${YELLOW}UP$${NC} No models pulled yet."; \
echo " Pull one: docker exec -it medical-ai-platform-ollama-1 ollama pull llama3"; \
fi; \
else \
echo -e " $${RED}DOWN$${NC} Ollama not reachable at http://localhost:11434"; \
fi; \
echo ""; \
echo "=== URLs ==="; \
echo " Patient Portal http://localhost:3000"; \
echo " Doctor Dashboard http://localhost:3001"; \
echo " Patient API docs http://localhost:8001/docs"; \
echo " Doctor API docs http://localhost:8002/docs"; \
echo " PostCare API docs http://localhost:8003/docs"; \
echo ""