FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV HOME=/home/user # Create a non-root user for Hugging Face RUN useradd -m -u 1000 user WORKDIR $HOME/app # Pre-create data directories with correct ownership RUN mkdir -p $HOME/app/data/index $HOME/app/data/sessions && \ chown -R user:user $HOME/app # Switch to non-root user USER user ENV PATH=$HOME/.local/bin:$PATH # Install dependencies COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Copy application code COPY --chown=user . . # Expose port EXPOSE 7860 # Start application CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]