FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
# OSMesa for headless cadquery/VTK (no display needed)
ENV PYOPENGL_PLATFORM=osmesa
ENV VTK_DEFAULT_EGL=0

# Runtime libraries for cadquery/VTK + Blender 5.x
RUN apt-get update && apt-get install -y \
    python3-pip \
    python3-dev \
    libxrender1 \
    libxi6 \
    libxkbcommon-x11-0 \
    libsm6 \
    libglib2.0-0 \
    libgl1-mesa-glx \
    libosmesa6 \
    libgomp1 \
    libxfixes3 \
    libxrandr2 \
    libxcursor1 \
    libxinerama1 \
    libwayland-client0 \
    libwayland-cursor0 \
    libwayland-egl1 \
    libvulkan1 \
    mesa-vulkan-drivers \
    libegl1 \
    libegl-mesa0 \
    libgbm1 \
    && rm -rf /var/lib/apt/lists/*

# Blender 5.0.1 is mounted from the host at /opt/blender (see docker-compose.yml)
ENV BLENDER_BIN=/opt/blender/blender

WORKDIR /app

COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8100

CMD ["python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8100"]
