# --------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------
# Dockerfile to Test ONNX Runtime on UBI8 with CUDA 11.8 and TensorRT 8.6

# Build base image with required system packages
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubi8 AS base

ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/src/tensorrt/bin:${PATH}

RUN dnf install -y bash wget git&&\
    dnf clean dbcache

# Install python3
RUN dnf install -y \
    python3.8 \
    python38-pip \
    python38-wheel &&\
    cd /usr/local/bin &&\
    ln -s /usr/bin/python3 python3.8 &&\
    ln -s /usr/bin/pip3 pip3.8;

RUN pip3 install --upgrade pip
RUN pip3 install setuptools>=68.2.2
RUN pip3 install cmake==3.27.2

# Install TensorRT
RUN dnf install -y libnvinfer8 libnvonnxparsers8 libnvparsers8 libnvinfer-plugin8 libnvinfer-lean8 libnvinfer-vc-plugin8 libnvinfer-dispatch8
RUN v="8.6.1.6-1+cuda11.8" &&\
    dnf downgrade -y libnvinfer8-${v} libnvinfer8-${v} libnvonnxparsers8-${v} libnvparsers8-${v} libnvinfer-plugin8-${v} libnvinfer-lean8-${v} libnvinfer-vc-plugin8-${v} libnvinfer-dispatch8-${v} &&\
    dnf install -y dnf-plugin-versionlock &&\
    dnf versionlock libnvinfer8 libnvonnxparsers8 libnvparsers8 libnvinfer-plugin8 libnvinfer-lean8 libnvinfer-vc-plugin8 libnvinfer-dispatch8
RUN dnf clean dbcache
#RUN ln -s /usr/local/cuda-11.8/bin /usr/local/cuda/bin

# Build final image from base.
FROM base as final
ARG BUILD_USER=onnxruntimedev
ARG BUILD_UID=1000
RUN adduser --uid $BUILD_UID $BUILD_USER
WORKDIR /home/$BUILD_USER
USER $BUILD_USER
