File size: 2,482 Bytes
5c40041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a1fbdc
5c40041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ─────────────────────────────────────────────────────────────────────────────
# Stage 1 – Build the Vite / React frontend
# ─────────────────────────────────────────────────────────────────────────────
FROM node:20-slim AS frontend-builder

WORKDIR /app/ui

# Install deps first (better layer caching)
COPY ui/package.json ui/package-lock.json* ./
RUN npm ci --prefer-offline

# Copy all UI source
COPY ui/ ./

# Vite bakes VITE_* vars into the static bundle at build time.
# HF Spaces forwards the matching secrets as Docker build-args automatically
# when you set them in Space Settings β†’ Variables and secrets.
ARG VITE_HF_TOKEN=""
ARG VITE_HF_MODEL="meta-llama/Llama-3.1-8B-Instruct"
ENV VITE_HF_TOKEN=${VITE_HF_TOKEN}
ENV VITE_HF_MODEL=${VITE_HF_MODEL}

RUN npm run build


# ─────────────────────────────────────────────────────────────────────────────
# Stage 2 – Python backend + Nginx to serve frontend
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.11-slim

# System packages: nginx for static serving + reverse-proxy
RUN apt-get update && apt-get install -y --no-install-recommends \
    nginx \
    curl \
 && rm -rf /var/lib/apt/lists/*

WORKDIR /app

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

# Application source
COPY models.py .
COPY inference.py .
COPY server/ ./server/
COPY openenv.yaml .

# Nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf

# Built frontend from stage 1
COPY --from=frontend-builder /app/ui/dist ./ui/dist

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

# HF Spaces exposes port 7860
EXPOSE 7860

# Runtime environment (overridden by HF Space secrets at runtime)
ENV PORT=7860 \
    HF_MODEL="mistralai/Mistral-7B-Instruct-v0.2" \
    HF_TOKEN="" \
    PYTHONUNBUFFERED=1

CMD ["/start.sh"]