ARG VERSION=mmcv1.6_dtk26.04_v1.0_HygonBW1101
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
RUN 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

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 && \
    cd /workspace/FlashOCC/projects && FORCE_CUDA=1 python setup.py develop  && \
    source /usr/local/bin/fastpt -E || true # 编译成功也会返回1，忽略错误 @hygon

#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
