# Use Python 3.10-slim as base image FROM python:3.10-slim # Install system dependencies for OpenCV, FFmpeg, and debugging RUN apt-get update && apt-get install -y \ libgl1-mesa-glx \ libglib2.0-0 \ ffmpeg \ curl \ && rm -rf /var/lib/apt/lists/* # Create a non-root user and set up directories RUN useradd -m -u 1000 appuser && \ mkdir -p /tmp/Ultralytics /snapshots /app && \ chown -R appuser:appuser /tmp/Ultralytics /snapshots /app && \ chmod -R 777 /tmp/Ultralytics /snapshots /app # Set environment variables early ENV YOLO_CONFIG_DIR=/tmp/Ultralytics ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=/app # Set working directory WORKDIR /app # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Download YOLOv8n model weights if not present in project directory RUN curl -L -o yolov8n.pt https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt && \ chown appuser:appuser yolov8n.pt && \ chmod 644 yolov8n.pt # Copy application code COPY . . # Switch to non-root user USER appuser # Expose port 8000 for FastAPI EXPOSE 8000 # Run FastAPI app with uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]