File size: 2,178 Bytes
4b81334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6be14c8
4b81334
 
 
 
 
 
 
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
# syntax=docker/dockerfile:1.7
# ---------- Stage 1: Build the Next.js frontend ----------
FROM node:20-bookworm-slim AS frontend-build

WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm install --no-audit --no-fund

COPY frontend/ ./
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build

# ---------- Stage 2: Runtime (Python 3.13 + Node 20) ----------
FROM python:3.13-slim-bookworm AS runtime

# Install Node 20 (needed to run `next start`) and minimal system libs
RUN apt-get update && apt-get install -y --no-install-recommends \
        curl ca-certificates gnupg build-essential \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y --no-install-recommends nodejs \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install uv (fast Python package manager)
RUN pip install --no-cache-dir uv

# HF Spaces requires the working dir to be writable by an arbitrary uid.
# We create /app and chmod it 777 so cache + lancedb dirs work at runtime.
WORKDIR /app

# ---- Backend ----
COPY backend/pyproject.toml backend/uv.lock* ./backend/
RUN cd backend && uv sync --no-dev --frozen 2>/dev/null || (cd backend && uv sync --no-dev)

COPY backend/ ./backend/

# ---- Frontend (built artifacts only) ----
COPY --from=frontend-build /app/frontend/.next ./frontend/.next
COPY --from=frontend-build /app/frontend/public ./frontend/public
COPY --from=frontend-build /app/frontend/package.json ./frontend/package.json
COPY --from=frontend-build /app/frontend/next.config.js ./frontend/next.config.js
COPY --from=frontend-build /app/frontend/node_modules ./frontend/node_modules

# ---- Entry script ----
COPY start.sh /app/start.sh
RUN chmod +x /app/start.sh

# Cache + data dirs (HF Spaces runs as random uid; make them world-writable)
RUN mkdir -p /app/.cache /app/.lancedb /app/.tmp_uploads \
    && chmod -R 777 /app

ENV HF_HOME=/app/.cache \
    LANCEDB_PATH=/app/.lancedb \
    TMP_UPLOAD_DIR=/app/.tmp_uploads \
    BACKEND_PORT=8000 \
    BACKEND_INTERNAL_URL=http://127.0.0.1:8000 \
    FRONTEND_PORT=7860 \
    NEXT_TELEMETRY_DISABLED=1 \
    PYTHONUNBUFFERED=1

EXPOSE 7860

CMD ["/app/start.sh"]