File size: 2,212 Bytes
5feba25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Multi-stage build for Medical Diagnosis AI
# Stage 1: Build React frontend with Node.js
# Stage 2: Python backend serving both API and static files

# ============================================================
# Stage 1: Build React Frontend
# ============================================================
FROM node:18-slim AS frontend-builder

WORKDIR /build/frontend

# Copy frontend source code
COPY frontend/package*.json ./
RUN npm install --frozen-lockfile

# Copy frontend source
COPY frontend/ .

# Build the frontend (creates dist/ folder)
RUN npm run build

# ============================================================
# Stage 2: Python Backend with Static File Serving
# ============================================================
FROM python:3.10-slim

# Set metadata
LABEL maintainer="Medical Diagnosis AI Team"
LABEL description="Medical Diagnosis AI - Full Stack Application"

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

# Create non-root user with UID 1000 (Hugging Face Spaces requirement)
RUN groupadd -r user && useradd -r -u 1000 -g user user

# Set working directory
WORKDIR /home/user/app

# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

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

# Copy backend application code
COPY app/ ./app/
COPY server.py .

# Copy the ML model (CRITICAL - needed for disease predictions)
COPY models/ ./models/

# Create frontend dist directory and copy built frontend from Stage 1
RUN mkdir -p frontend
COPY --from=frontend-builder /build/frontend/dist ./frontend/dist

# Change ownership of all files to the non-root user
RUN chown -R user:user /home/user/app

# Switch to non-root user
USER user

# Expose port 7860 (Hugging Face Spaces standard)
EXPOSE 7860

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Run the server
CMD ["python", "server.py"]