onnxruntime/dockerfiles/Dockerfile.openvino-rhel8
Edward Chen ea40dc3ad6
Update build.py to disallow running as root user by default. (#15164)
Try to address intermittent permissions issues that show up in non-transient CI environments.
2023-03-27 14:46:04 -07:00

87 lines
4.4 KiB
Text

# Build stage
FROM registry.access.redhat.com/ubi8/ubi:8.4
WORKDIR /code
ARG MY_ROOT=/code
ARG DEVICE=CPU_FP32
ARG ONNXRUNTIME_REPO=https://github.com/microsoft/onnxruntime
ARG ONNXRUNTIME_BRANCH=main
ENV INTEL_OPENVINO_DIR=/opt/intel/openvino_2022.3.0
ENV InferenceEngine_DIR=${INTEL_OPENVINO_DIR}/runtime/cmake
ENV IE_PLUGINS_PATH=${INTEL_OPENVINO_DIR}/runtime/lib/intel64/
ENV ngraph_DIR=${INTEL_OPENVINO_DIR}/runtime/cmake
ENV LD_LIBRARY_PATH=${INTEL_OPENVINO_DIR}/runtime/3rdparty/tbb/lib/:${IE_PLUGINS_PATH}:${LD_LIBRARY_PATH}
ENV OpenCV_DIR=${INTEL_OPENVINO_DIR}/extras/opencv/cmake
ENV LD_LIBRARY_PATH=${INTEL_OPENVINO_DIR}/extras/opencv/lib:${LD_LIBRARY_PATH}
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/local/lib64:/usr/lib64:/lib64:${LD_LIBRARY_PATH}
ENV PATH=${MY_ROOT}/cmake-dir/bin:$PATH
# Install packages
RUN yum install -y yum-utils autoconf automake libtool unzip udev wget zlib-devel libffi-devel openssl-devel git make gcc && \
yum clean packages && yum clean all && rm -rf /var/cache/yum && \
# Install python 3.8
cd $MY_ROOT && \
wget https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tgz && tar xvf Python-3.8.9.tgz && rm -rf Python-3.8.9.tgz && \
cd Python-3.8*/ && ./configure && make && make install && \
cd ../ && mkdir -p /usr/bin/Python38 && ln -s Python-3.8.9/ /usr/bin/Python38 && ln -s /usr/bin/pip3 /usr/bin/pip && \
# libusb1.0.22
cd /opt/ && wget https://github.com/libusb/libusb/archive/v1.0.22.zip && \
unzip v1.0.22.zip && rm -rf v1.0.22.zip && cd /opt/libusb-1.0.22 && \
# bootstrap steps
./bootstrap.sh && \
./configure --disable-udev --enable-shared && \
make -j4 && \
# configure libusb1.0.22
cd /opt/libusb-1.0.22/libusb && \
/bin/mkdir -p '/usr/local/lib' && \
/bin/bash ../libtool --mode=install /usr/bin/install -c libusb-1.0.la '/usr/local/lib' && \
/bin/mkdir -p '/usr/local/include/libusb-1.0' && \
/usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0' && \
/bin/mkdir -p '/usr/local/lib/pkgconfig' && \
# Install openvino
cd /opt/ && mkdir intel/ && cd intel && \
wget https://storage.openvinotoolkit.org/repositories/openvino/packages/2022.3/linux/l_openvino_toolkit_rhel8_2022.3.0.9052.9752fafe8eb_x86_64.tgz && \
tar xvf l_openvino_toolkit_rhel8_2022.3.0.9052.9752fafe8eb_x86_64.tgz && \
rm -rf l_openvino_toolkit_rhel8_2022.3.0.9052.9752fafe8eb_x86_64.tgz && \
mv l_openvino_toolkit_rhel8_2022.3.0.9052.9752fafe8eb_x86_64 openvino_2022.3.0 && \
cd ${INTEL_OPENVINO_DIR}/install_dependencies/ && ./install_openvino_dependencies.sh -y && ./install_NEO_OCL_driver.sh -y && \
printf "\nexport LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:/usr/local/lib\n" >> /opt/intel/openvino_2022.3.0/setupvars.sh && \
cd /opt/libusb-1.0.22 && \
/usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig' && \
# MYRIAD plugins are not available for openvino 2022.3.0 release
#cp /opt/intel/openvino_2022.3.0/install_dependencies/97-myriad-usbboot.rules /etc/udev/rules.d/ && \
ldconfig && \
#Install protobuf
cd $MY_ROOT && \
git clone https://github.com/protocolbuffers/protobuf.git && \
cd protobuf && \
git checkout v3.16.0 && \
git submodule update --init --recursive && \
mkdir build_source && cd build_source && \
cmake ../cmake -DCMAKE_INSTALL_LIBDIR=lib64 -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && \
make -j$(nproc) && \
make install && \
# Build onnxruntime
cd $MY_ROOT && \
pip3 install numpy wheel setuptools cython onnx && \
git clone --recursive -b ${ONNXRUNTIME_BRANCH} ${ONNXRUNTIME_REPO} && \
bash onnxruntime/dockerfiles/scripts/install_common_deps.sh && \
ln -s cmake-* cmake-dir && \
source /opt/intel/openvino_2022.3.0/setupvars.sh && \
cd /code/onnxruntime && ./build.sh --allow_running_as_root --config Release --update --build --parallel --use_openvino ${DEVICE} --build_shared_lib --build_wheel && \
pip3 install /code/onnxruntime/build/Linux/Release/dist/*-linux_x86_64.whl && \
# Clean up
cd ${MY_ROOT} && rm -rf onnxruntime && rm -rf Python-3.8.9 && rm -rf protobuf
# Deploy stage
ARG BUILD_UID=1001
ARG BUILD_USER=onnxruntimedev
RUN adduser --uid $BUILD_UID $BUILD_USER
RUN usermod -a -G video,users,render ${BUILD_USER}
ENV WORKDIR_PATH /home/${BUILD_USER}
WORKDIR ${WORKDIR_PATH}
USER ${BUILD_USER}