FROM ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddleqa:xpu-ubuntu2204-x86_64-gcc123-py310

WORKDIR /workspace
COPY requirements.txt .

RUN echo "\
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse \n\
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse \n\
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse" > /etc/apt/sources.list

RUN apt-get update && apt-get install -y libibverbs-dev librdmacm-dev cmake pybind11-dev

# uninstall existing package
RUN python -m pip uninstall paddlepaddle-gpu paddlepaddle-xpu fastdeploy-xpu -y
RUN python -m pip uninstall -y Pillow && rm -rf /usr/local/lib/python3.10/dist-packages/Pillow* && rm -rf /usr/local/lib/python3.10/dist-packages/pillow* && python -m pip install Pillow==11.3.0

# install paddlepaddle-xpu
ARG PADDLE_VERSION=nightly

RUN if [ "$PADDLE_VERSION" = "nightly" ]; then \
        python -m pip install --no-cache-dir --progress-bar off paddlepaddle-xpu -i https://www.paddlepaddle.org.cn/packages/nightly/xpu-p800/; \
    else \
        python -m pip install --no-cache-dir --progress-bar off paddlepaddle-xpu==${PADDLE_VERSION} -i https://www.paddlepaddle.org.cn/packages/stable/xpu-p800/; \
    fi

# install fastdeploy-xpu
ARG INSTALL_REQUIREMENTS=true
ARG INSTALL_FASTDEPLOY=true
ARG FASTDEPLOY_VERSION=2.5.0

RUN if [ "$INSTALL_FASTDEPLOY" = "true" ]; then \
        python -m pip install --no-cache-dir fastdeploy-xpu==${FASTDEPLOY_VERSION} -i https://www.paddlepaddle.org.cn/packages/stable/fastdeploy-xpu-p800/ --extra-index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple; \
    fi

RUN if [ "$INSTALL_REQUIREMENTS" = "true" ]; then \
        python -m pip install -r requirements.txt; \
    fi

RUN mkdir -p /workspace/deps && cd /workspace/deps && \
    wget https://klx-sdk-release-public.su.bcebos.com/xre/kl3-release/5.0.21.21/xre-Linux-x86_64-5.0.21.21.tar.gz && \
    tar -zxf xre-Linux-x86_64-5.0.21.21.tar.gz && mv xre-Linux-x86_64-5.0.21.21 xre

ENV PATH=/workspace/deps/xre/bin:$PATH
