FROM python:3.13-slim

WORKDIR /app

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

RUN pip install --upgrade pip

COPY app/ /app/

RUN pip install build123d

COPY wheels/ /tmp/

RUN for whl in /tmp/*.whl; do \
        if [ -f "$whl" ]; then \
            pip install "$whl"; \
        fi; \
    done

RUN if ls /tmp/partomatic-*.whl >/dev/null 2>&1; then \
        pip install "$(ls /tmp/partomatic-*.whl | head -n 1)[webui]"; \
    else \
        pip install partomatic[webui]; \
    fi

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