File size: 1,973 Bytes
e6c104f | 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 | # syntax=docker/dockerfile:1
# --- frontend ---------------------------------------------------------------
FROM node:22-alpine AS frontend
WORKDIR /ui
COPY frontend/package.json frontend/package-lock.json* ./
RUN npm ci || npm install
COPY frontend/ ./
RUN npm run build
# --- backend ----------------------------------------------------------------
# Hugging Face Docker Spaces run as UID 1000. Install system packages as root,
# then drop privileges before baking weights or starting uvicorn.
FROM python:3.12-slim AS runtime
RUN useradd -m -u 1000 user
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
HOME=/home/user \
HF_HOME=/home/user/.cache/huggingface \
TRANSFORMERS_CACHE=/home/user/.cache/huggingface \
EMBEDDING_PROVIDER=local \
AGENT_MODE=live \
PORT=8080 \
PATH=/home/user/.local/bin:$PATH
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# CPU torch first so sentence-transformers does not pull a CUDA wheel.
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu
COPY backend/requirements.txt backend/requirements.txt
RUN pip install --no-cache-dir -r backend/requirements.txt
COPY --chown=user:user backend ./backend
COPY --chown=user:user data/alphabet_financials_structured.csv data/alphabet_financials_structured.csv
COPY --from=frontend --chown=user:user /ui/dist ./frontend/dist
USER user
# Bake model weights so the first Spaces request does not download HF models.
RUN python -c "from sentence_transformers import SentenceTransformer, CrossEncoder; \
SentenceTransformer('BAAI/bge-small-en-v1.5'); \
CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')"
EXPOSE 8080
CMD ["sh", "-c", "uvicorn backend.app.main:app --host 0.0.0.0 --port ${PORT:-8080}"]
|