acpcchatbotadmin's picture
Create Dockerfile
504d13c verified
Raw History Blame
863 Bytes
# Stage 1: Build dependencies
FROM python:3.11-slim AS builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# Stage 2: Runtime
FROM python:3.11-slim AS runtime
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /root/.local /root/.local
ENV PATH=/root/.local/bin:$PATH
# Copy application code only (no tests, no eval)
COPY app/ ./app/
# HF Spaces runs as a non-root user (UID 1000)
# Create the user to match HF's runtime UID
RUN useradd -m -u 1000 user
USER user
# HF Spaces requires port 7860
EXPOSE 7860
# Single worker — HF free tier has ~16GB RAM but cold starts are common;
# single worker avoids OOM on smaller hardware tiers.
# Increase --workers to 2 only on upgraded hardware tiers.
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]