FROM python:3.13-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends libgl1 patch && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

COPY app/ /app/

RUN pip install cadquery-ocp build123d ocp_vscode

COPY comms-patch /tmp/comms.patch
RUN dst="$(python -c \"import ocp_vscode, os; print(os.path.join(os.path.dirname(ocp_vscode.__file__), 'static', 'js', 'comms.js'))\")" \
    && patch "$dst" /tmp/comms.patch \
    && echo "Patched $dst"

RUN pip install partomatic[webui];

CMD ["python", "server.py"]
