File size: 1,835 Bytes
db764ae 8042dc1 db764ae e29b232 db764ae e29b232 db764ae | 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 | # =============================================================
# Multi-stage Docker build for Contextual Similarity Engine
# Single container: React frontend + FastAPI backend
# Deploys to: HuggingFace Spaces (Docker SDK), local, Railway
# =============================================================
# Stage 1: Build frontend
FROM node:22-slim AS frontend-build
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build && node inline-assets.cjs
# Stage 2: Python runtime
FROM python:3.12-slim AS runtime
# Create non-root user (required by HF Spaces)
RUN useradd -m -u 1000 appuser
WORKDIR /app
# System deps for faiss-cpu and torch
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install uv for fast dependency resolution
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy dependency files first (cache layer)
COPY --chown=appuser pyproject.toml uv.lock ./
# Install Python dependencies
RUN uv sync --frozen --no-dev
# Copy backend source
COPY --chown=appuser *.py ./
# Copy pre-built frontend
COPY --chown=appuser --from=frontend-build /app/frontend/dist ./frontend/dist
# Data directories (HF cache, engine state, trained models)
RUN mkdir -p /data/huggingface /data/engine_state /data/w2v_state /data/trained_model \
&& chown -R appuser:appuser /app /data
ENV HF_HOME=/data/huggingface
ENV TRANSFORMERS_CACHE=/data/huggingface
ENV ENGINE_STATE_DIR=/data/engine_state
ENV W2V_STATE_DIR=/data/w2v_state
# Switch to non-root user
USER appuser
# Expose port (HF Spaces expects 7860, override via PORT env)
EXPOSE 7860
# Run the server — HOST and PORT configurable via env
ENV HOST=0.0.0.0
ENV PORT=7860
CMD ["uv", "run", "python", "server.py"]
|