File size: 1,349 Bytes
f589dab | 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 | # Multi-stage Dockerfile optimized for Hugging Face Spaces
# HF Spaces requirements: port 7860, runs as non-root user
FROM python:3.12-slim AS base
# Install system deps
RUN apt-get update && apt-get install -y --no-install-recommends \
curl git build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install uv (Rust-native Python package manager)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.cargo/bin:/root/.local/bin:$PATH"
WORKDIR /app
# Copy dependency files first for layer caching
COPY pyproject.toml ./
# Install dependencies with uv (10-100x faster than pip)
RUN uv pip install --system --no-cache \
fastapi uvicorn[standard] websockets pydantic pydantic-settings \
litellm groq qdrant-client fastembed \
redis[hiredis] aiokafka structlog httpx \
python-multipart xxhash neo4j python-dotenv orjson \
anyio tenacity prefect
# Copy source
COPY . .
# Create cache directory for FastEmbed model weights
RUN mkdir -p /tmp/fastembed_cache
# HF Spaces runs as user 1000
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app /tmp/fastembed_cache
USER appuser
# Expose HF Spaces standard port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
CMD ["python", "hf_main.py"]
|