# syntax=docker/dockerfile:1 FROM python:3.12-slim # 1. Install system dependencies for OpenCV RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ && rm -rf /var/lib/apt/lists/* # 2. Create non-root user RUN useradd --create-home --shell /bin/bash --uid 1000 appuser # 3. Environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ HF_HOME=/home/appuser/huggingface \ PORT=7860 \ PATH=/home/appuser/.local/bin:$PATH # 4. Set working directory WORKDIR /home/appuser/app # 5. Install Python dependencies COPY requirements.txt . RUN pip install --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # 6. Copy code and set permissions COPY --chown=appuser:appuser . . # 7. Create huggingface directory with proper permissions RUN mkdir -p /home/appuser/huggingface && \ chown -R appuser:appuser /home/appuser # 8. Switch to non-root user USER appuser # 9. Expose port and run app EXPOSE 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]