File size: 2,908 Bytes
4ba0371
 
 
 
 
98917ae
4ba0371
 
 
 
 
 
98917ae
4ba0371
98917ae
 
4ba0371
 
 
 
 
98917ae
4ba0371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b706f2e
4ba0371
 
98917ae
 
4ba0371
98917ae
 
58e2bd0
4ba0371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ── Stage 1: Build the Next.js frontend ──────────────────────────
FROM node:20-slim AS frontend-build

WORKDIR /app/frontend
COPY src/frontend/package.json src/frontend/package-lock.json* ./
RUN npm ci 2>/dev/null || npm install

COPY src/frontend/ ./

# Build-time env: WebSocket and API go through the same origin via nginx
ENV NEXT_PUBLIC_WS_URL=""
ENV NEXT_PUBLIC_API_URL=""
ENV NEXT_TELEMETRY_DISABLED=1

# Limit Node memory for constrained HF Space build environment
RUN NODE_OPTIONS=--max-old-space-size=1536 npm run build


# ── Stage 2: Production image ────────────────────────────────────
FROM python:3.10-slim

# System deps: nginx + node (for Next.js standalone server)
RUN apt-get update && apt-get install -y --no-install-recommends \
        nginx \
        curl \
        && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
        && apt-get install -y --no-install-recommends nodejs \
        && rm -rf /var/lib/apt/lists/*

# ── Python backend ───────────────────────────────────────────────
WORKDIR /app/backend
COPY src/backend/requirements.txt ./

# Install Python deps (skip torch/transformers β€” we use API mode only)
RUN pip install --no-cache-dir \
        fastapi==0.115.0 \
        "uvicorn[standard]==0.30.6" \
        websockets==12.0 \
        pydantic-settings==2.5.2 \
        python-dotenv==1.0.1 \
        openai==1.51.0 \
        httpx==0.27.2 \
        chromadb==0.5.7 \
        sentence-transformers==3.1.1 \
        python-multipart==0.0.10

# Copy backend source (ChromaDB will auto-build from app/data/clinical_guidelines.json on first run)
COPY src/backend/app/ ./app/

# ── Frontend standalone build ────────────────────────────────────
# Next.js standalone output: self-contained server, no node_modules needed
WORKDIR /app/frontend
COPY --from=frontend-build /app/frontend/.next/standalone ./
COPY --from=frontend-build /app/frontend/.next/static ./.next/static
RUN mkdir -p ./public

# ── Nginx config ─────────────────────────────────────────────────
COPY space/nginx.conf /etc/nginx/nginx.conf

# ── Startup script ───────────────────────────────────────────────
COPY space/start.sh /app/start.sh
RUN chmod +x /app/start.sh

# HF Spaces expects port 7860
EXPOSE 7860

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

CMD ["/app/start.sh"]