FROM python:3.12-slim # Install system dependencies RUN apt-get update && apt-get install -y \ git \ build-essential \ cmake \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Install uv from the official image COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /app # Copy dependency files COPY pyproject.toml uv.lock ./ # Install core dependencies first # We force install torch separately to ensure it is present for detectron2's build RUN uv sync --frozen --no-dev # Install detectron2 # Note: --no-build-isolation is often required for detectron2 to find # the torch installed by uv # RUN .venv/bin/pip install 'git+https://github.com/facebookresearch/detectron2.git' --no-build-isolation # Copy the rest of your application code COPY . . # Set environment ENV PATH="/app/.venv/bin:$PATH" # Run the application CMD ["python", "app.py"]