|
| 1 | +# Common (multistage) args |
| 2 | +ARG D_OS="ubuntu22.04" |
| 3 | +ARG D_ARCH="x86_64" |
| 4 | +ARG D_CONTAINER_VER="0" |
| 5 | +ARG D_DOCA_VERSION="2.9.1" |
| 6 | +ARG D_OFED_VERSION="24.10-1.1.4.0" |
| 7 | +ARG D_KERNEL_VER="5.15.0-25-generic" |
| 8 | +ARG D_OFED_SRC_DOWNLOAD_PATH="/run/mellanox/src" |
| 9 | +ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSION} |
| 10 | + |
| 11 | +# Go args |
| 12 | +ARG GOPROXY= |
| 13 | +ENV GOPROXY=$GOPROXY |
| 14 | + |
| 15 | +# Common for build and final clean image of precompiled driver container |
| 16 | +ARG D_BASE_IMAGE="ubuntu:22.04" |
| 17 | + |
| 18 | +################################################################## |
| 19 | +# Stage: build go binary for entrypoint |
| 20 | +FROM golang:1.24 AS go_builder |
| 21 | + |
| 22 | +WORKDIR /workspace |
| 23 | + |
| 24 | +COPY entrypoint/go.mod go.mod |
| 25 | +COPY entrypoint/go.sum go.sum |
| 26 | + |
| 27 | +RUN go mod download |
| 28 | + |
| 29 | +COPY entrypoint/ . |
| 30 | + |
| 31 | +RUN TARGETARCH=${D_ARCH} TARGETOS=linux make build |
| 32 | + |
| 33 | +################################################################## |
| 34 | +# Stage: Minimal base image update and install common requirements |
| 35 | +FROM $D_BASE_IMAGE AS base |
| 36 | + |
| 37 | +ARG D_APT_REMOVE="" |
| 38 | +ARG D_OFED_VERSION |
| 39 | +ARG D_CONTAINER_VER |
| 40 | +ARG D_OFED_SRC_DOWNLOAD_PATH |
| 41 | + |
| 42 | +ENV NVIDIA_NIC_DRIVER_VER=${D_OFED_VERSION} |
| 43 | +ENV NVIDIA_NIC_CONTAINER_VER=${D_CONTAINER_VER} |
| 44 | + |
| 45 | +WORKDIR /root |
| 46 | +RUN set -x && \ |
| 47 | + for source in ${D_APT_REMOVE}; do rm -f /etc/apt/sources.list.d/${source}.list; done && \ |
| 48 | +# Perform distro update and install prerequirements |
| 49 | + apt-get -yq update && \ |
| 50 | + DEBIAN_FRONTEND=noninteractive apt-get -yq upgrade && \ |
| 51 | + DEBIAN_FRONTEND=noninteractive apt-get -yq install apt-utils \ |
| 52 | +# Driver build / install script requirements |
| 53 | + perl pciutils kmod lsof python3 dh-python \ |
| 54 | +# Container functional requirements |
| 55 | + jq iproute2 udev ethtool ca-certificates |
| 56 | + |
| 57 | +COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint |
| 58 | +ADD ./entrypoint.sh /root/entrypoint.sh |
| 59 | +ADD ./loader.sh /root/loader.sh |
| 60 | + |
| 61 | +ENTRYPOINT ["/root/loader.sh"] |
| 62 | + |
| 63 | +############################################################################################## |
| 64 | +# Stage: Download NVIDIA driver sources and install src driver container packages requirements |
| 65 | + |
| 66 | +FROM base AS driver-src |
| 67 | + |
| 68 | +# Inherited global args |
| 69 | +ARG D_OS |
| 70 | +ARG D_DOCA_VERSION |
| 71 | +ARG D_OFED_VERSION |
| 72 | +ARG D_OFED_SRC_DOWNLOAD_PATH |
| 73 | + |
| 74 | +# Stage args |
| 75 | +ARG D_OFED_BASE_URL="https://linux.mellanox.com/public/repo/doca/${D_DOCA_VERSION}/SOURCES/MLNX_OFED" |
| 76 | +ARG D_OFED_SRC_TYPE="debian-" |
| 77 | + |
| 78 | +ARG D_OFED_SRC_ARCHIVE="MLNX_OFED_SRC-${D_OFED_SRC_TYPE}${D_OFED_VERSION}.tgz" |
| 79 | +ARG D_OFED_URL_PATH="${D_OFED_BASE_URL}/${D_OFED_SRC_ARCHIVE}" # although argument name says URL, local `*.tgz` compressed files may also be used (intended for internal use) |
| 80 | +ENV NVIDIA_NIC_DRIVER_PATH="${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSION}" |
| 81 | + |
| 82 | +WORKDIR /root |
| 83 | +RUN set -x && \ |
| 84 | + echo $D_OS | grep "ubuntu20.04" || GCC_VER="-12" && \ |
| 85 | +# Install prerequirements \ |
| 86 | + DEBIAN_FRONTEND=noninteractive apt-get -yq install curl \ |
| 87 | + dkms make autoconf autotools-dev chrpath automake hostname debhelper gcc$GCC_VER quilt libc6-dev build-essential pkg-config && \ |
| 88 | +# Cleanup \ |
| 89 | + apt-get clean autoclean && \ |
| 90 | + rm -rf /var/lib/apt/lists/* |
| 91 | + |
| 92 | +RUN echo $D_OS | grep "ubuntu20.04" || ln -fs gcc-12 /usr/bin/gcc # 'build-essential' installs `gcc`, however (if above ubuntu 20.04) we need `gcc-12`, so we overwrite it with this link |
| 93 | + |
| 94 | +# Download NVIDIA NIC driver |
| 95 | +RUN mkdir -p ${D_OFED_SRC_DOWNLOAD_PATH} |
| 96 | +WORKDIR ${D_OFED_SRC_DOWNLOAD_PATH} |
| 97 | +ADD ${D_OFED_URL_PATH} ${D_OFED_SRC_ARCHIVE} |
| 98 | +RUN if file ${D_OFED_SRC_ARCHIVE} | grep compressed; then \ |
| 99 | + tar -xzf ${D_OFED_SRC_ARCHIVE}; \ |
| 100 | + else \ |
| 101 | + mv ${D_OFED_SRC_ARCHIVE}/MLNX_OFED_SRC-${D_OFED_VERSION} . ; \ |
| 102 | + fi |
| 103 | + |
| 104 | +WORKDIR /root |
| 105 | + |
| 106 | +CMD ["sources"] |
| 107 | + |
| 108 | +LABEL doca-version=${D_DOCA_VERSION} |
| 109 | +LABEL ofed-version=${D_OFED_VERSION} |
| 110 | + |
| 111 | +##################### |
| 112 | +# Stage: Build driver |
| 113 | + |
| 114 | +FROM driver-src AS driver-builder |
| 115 | + |
| 116 | +# Inherited global args |
| 117 | +ARG D_OS |
| 118 | +ARG D_KERNEL_VER |
| 119 | +ARG OFED_SRC_LOCAL_DIR |
| 120 | +# Additional local arg (for precompiled CI) |
| 121 | +ARG D_BUILD_EXTRA_ARGS |
| 122 | + |
| 123 | +# Driver build manadatory packages |
| 124 | +RUN set -x && \ |
| 125 | + apt-get update && \ |
| 126 | + DEBIAN_FRONTEND=noninteractive apt-get -yq install linux-image-${D_KERNEL_VER} linux-headers-${D_KERNEL_VER} |
| 127 | + |
| 128 | +# Build driver |
| 129 | +RUN set -x && \ |
| 130 | + ${OFED_SRC_LOCAL_DIR}/install.pl --without-depcheck --distro ${D_OS} --without-dkms --kernel ${D_KERNEL_VER} --kernel-only --build-only --copy-ifnames-udev --with-mlnx-tools --without-knem-modules --without-srp-modules --without-kernel-mft-modules --without-iser-modules --without-isert-modules ${D_BUILD_EXTRA_ARGS} |
| 131 | + |
| 132 | +################################### |
| 133 | +# Stage: Install precompiled driver |
| 134 | + |
| 135 | +FROM base AS precompiled |
| 136 | + |
| 137 | +# Inherited global args |
| 138 | +ARG D_OS |
| 139 | +ARG D_ARCH |
| 140 | +ARG D_KERNEL_VER |
| 141 | +ARG OFED_SRC_LOCAL_DIR |
| 142 | + |
| 143 | +ENV NVIDIA_NIC_DRIVER_PATH="" |
| 144 | + |
| 145 | +RUN set -x && \ |
| 146 | + apt-get install -y lsb-release && \ |
| 147 | + test -n "${D_KERNEL_VER}" && apt-get install -y linux-modules-extra-${D_KERNEL_VER} || true # only install this package when kernel variable defined |
| 148 | +# Cleanup |
| 149 | +RUN set -x && \ |
| 150 | + apt-get clean autoclean && \ |
| 151 | + rm -rf /var/lib/apt/lists/* |
| 152 | + |
| 153 | +# Install driver |
| 154 | +COPY --from=driver-builder ${OFED_SRC_LOCAL_DIR}/DEBS/${D_OS}/*/*.deb /root/ |
| 155 | + |
| 156 | +RUN apt-get install -y /root/*.deb |
| 157 | + |
| 158 | +# Prevent modprobe from giving a WARNING about missing files |
| 159 | +RUN touch /lib/modules/${D_KERNEL_VER}/modules.order /lib/modules/${D_KERNEL_VER}/modules.builtin && \ |
| 160 | +# Introduce installed kernel modules |
| 161 | + depmod ${D_KERNEL_VER} |
| 162 | + |
| 163 | +CMD ["precompiled"] |
0 commit comments