manasvikalyan commited on
Commit
d29de44
·
verified ·
1 Parent(s): bd3bacd

updated health

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -3
Dockerfile CHANGED
@@ -1,6 +1,9 @@
1
  # Use Python base image
2
  FROM python:3.10
3
 
 
 
 
4
  # Create user (required for HF Spaces)
5
  RUN useradd -m user
6
  USER user
@@ -18,7 +21,19 @@ RUN pip install --no-cache-dir -r requirements.txt
18
  EXPOSE 8000
19
  EXPOSE 8501
20
 
21
- # Start FastAPI in background + Streamlit in foreground
22
  CMD uvicorn api:app --host 0.0.0.0 --port 8000 & \
23
- streamlit run app_api.py --server.port 8501 --server.address 0.0.0.0
24
-
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Use Python base image
2
  FROM python:3.10
3
 
4
+ # Install curl for health checks
5
+ RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
6
+
7
  # Create user (required for HF Spaces)
8
  RUN useradd -m user
9
  USER user
 
21
  EXPOSE 8000
22
  EXPOSE 8501
23
 
24
+ # Start FastAPI in background, wait for health, then start Streamlit
25
  CMD uvicorn api:app --host 0.0.0.0 --port 8000 & \
26
+ for i in $(seq 1 30); do \
27
+ STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health || true); \
28
+ if [ "$STATUS" = "200" ]; then \
29
+ echo "API health check passed"; \
30
+ break; \
31
+ fi; \
32
+ echo "Waiting for API to be healthy... attempt $i"; \
33
+ sleep 1; \
34
+ done; \
35
+ if [ "$STATUS" != "200" ]; then \
36
+ echo "API failed health check, not starting Streamlit"; \
37
+ exit 1; \
38
+ fi; \
39
+ streamlit run app_api.py --server.port 8501 --server.address 0.0.0.0