# Use Python 3.12 slim image for a smaller footprint FROM python:3.12-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV HOME=/app # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with user ID 1000 (Required for Hugging Face Spaces) RUN useradd -m -u 1000 user # Copy requirements file COPY requirements.txt . # Install dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code COPY . . # Ensure the non-root user has ownership of the app directory to allow SQLite and ChromaDB to write RUN chown -R user:user /app # Switch to the non-root user USER user # Expose the API port required by Hugging Face Spaces EXPOSE 7860 # Command to run the application on Hugging Face port 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]