File size: 1,114 Bytes
bf10662
 
 
d29de44
 
 
bf10662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d29de44
bf10662
d29de44
 
 
 
 
 
 
 
 
 
 
 
 
b375242
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
# Use Python base image
FROM python:3.10

# Install curl for health checks
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*

# Create user (required for HF Spaces)
RUN useradd -m user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /home/user/app

# Copy all project files
COPY --chown=user . .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Expose ports
EXPOSE 8000
EXPOSE 8501

# Start FastAPI in background, wait for health, then start Streamlit
CMD uvicorn api:app --host 0.0.0.0 --port 8000 & \
    for i in $(seq 1 30); do \
      STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/health || true); \
      if [ "$STATUS" = "200" ]; then \
        echo "API health check passed"; \
        break; \
      fi; \
      echo "Waiting for API to be healthy... attempt $i"; \
      sleep 1; \
    done; \
    if [ "$STATUS" != "200" ]; then \
      echo "API failed health check, not starting Streamlit"; \
      exit 1; \
    fi; \
    streamlit run app.py --server.port 8501 --server.address 0.0.0.0