ARG VERSION=mmcv1.6_dtk26.04_v2.0_Hygon
FROM aicompute.tencentcloudcr.com/hyperdrive/hygon:${VERSION}

ARG COS_BASE_URL="https://haihub-model-1251001002.cos.ap-shanghai.myqcloud.com/HyperDrive/haiguang/hygon-bench/train"

SHELL ["/bin/bash", "-c"]


RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
    DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash

# Download Hyhal for compile if the base image does not already provide it.
RUN if [ -e /opt/hyhal/lib ]; then \
        echo "Use existing /opt/hyhal"; \
    else \
        aria2c --enable-color=false --show-console-readout=false -x 8 -s 8 -k 1M -d /tmp -o hyhal.tar.gz ${COS_BASE_URL}/common/hyhal.tar.gz && \
        mkdir -p /opt/hyhal && \
        tar -zxf /tmp/hyhal.tar.gz --strip-components=2 -C /opt/hyhal && \
        rm -rf /tmp/hyhal.tar.gz; \
    fi

COPY FlashOCC /workspace/FlashOCC
#COPY hyhal /opt/hyhal

#RUN export LD_LIBRARY_PATH=/opt/dtk/cuda/cuda-12:$LD_LIBRARY_PATH
#RUN ln -s /opt/dtk/cuda/cuda-12 /opt/dtk/cuda/cuda


#ENV FORCE_CUDA=1

RUN source /usr/local/bin/fastpt -C  && \
    pip uninstall -y mmdet3d && \
    cd /workspace/FlashOCC/mmdetection3d && python setup.py develop --no-deps && \
    cd /workspace/FlashOCC/projects && FORCE_CUDA=1 python setup.py develop --no-deps  && \
    (source /usr/local/bin/fastpt -E || true)

#RUN echo 'source /usr/local/bin/fastpt -E' >> /root/.bashrc
# 兼容 THPC 老模板
COPY build.sh /opt/build_flashocc.sh

COPY one_step_data.sh /workspace/FlashOCC/HyperDrive/tools/one_step_data.sh
COPY start_mmdet3d.sh /workspace/FlashOCC/tools/start_mmdet3d.sh

RUN rm -f /root/.bash_history

# Remove hyhal for runtime
RUN rm -rf /opt/hyhal

WORKDIR /workspace/FlashOCC
