# Builder stage
FROM nvidia/cuda:12.8.0-devel-ubuntu22.04 as builder

ENV DEBIAN_FRONTEND=noninteractive
ENV QT_XCB_GL_INTEGRATION=xcb_egl
ENV TORCH_CUDA_ARCH_LIST=86

RUN apt-get update && \
    apt-get install -y --no-install-recommends --no-install-suggests \
        build-essential \
        git \
        ninja-build \
        python3-pip \
        python3.10-dev \
        wget

WORKDIR /workspace/svraster

RUN pip3 config set global.break-system-packages true

RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

RUN git clone --recursive https://github.com/NVlabs/svraster.git /workspace/svraster
RUN pip3 install -r requirements.txt
RUN MAX_JOBS=8 pip3 install -e cuda/

RUN pip3 install "numpy<2.0.0" viser

RUN chmod -R go=u /usr/local/lib/python3.10

# Runtime stage
FROM nvidia/cuda:12.8.0-runtime-ubuntu22.04 as runtime

ENV TORCH_CUDA_ARCH_LIST=86
WORKDIR /workspace

RUN apt-get update && \
    apt-get install -y --no-install-recommends --no-install-suggests \
        build-essential \
        libgl1 \
        libglew2.2 \
        libglib2.0-0 \
        python-is-python3 \
        python3.10 \
        python3.10-dev && \
    rm -rf /var/lib/apt/lists/*

# Copy packages from builder stage.
COPY --from=builder /workspace /workspace
COPY --from=builder /usr/local/lib/python3.10/dist-packages/ /usr/local/lib/python3.10/dist-packages/

# Bash as default entrypoint.
CMD ["/bin/bash", "-l"]
