-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathUbuntu_Dockerfile
More file actions
177 lines (137 loc) · 6.3 KB
/
Ubuntu_Dockerfile
File metadata and controls
177 lines (137 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Common (multistage) args
ARG D_OS="ubuntu22.04"
ARG D_ARCH="x86_64"
ARG D_CONTAINER_VER="0"
ARG D_DOCA_VERSION="2.9.1"
ARG D_OFED_VERSION="24.10-1.1.4.0"
ARG D_KERNEL_VER="5.15.0-25-generic"
ARG D_OFED_SRC_DOWNLOAD_PATH="/run/mellanox/src"
ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSION}
ARG STIG_COMPLIANT=false
# Common for build and final clean image of precompiled driver container
ARG D_BASE_IMAGE="ubuntu:22.04"
##################################################################
# Stage: build go binary for entrypoint
FROM golang:1.24 AS go_builder
# Set GOPROXY if provided
ARG GOPROXY
ENV GOPROXY=$GOPROXY
WORKDIR /workspace
COPY entrypoint/go.mod go.mod
COPY entrypoint/go.sum go.sum
RUN go mod download
COPY entrypoint/ .
RUN TARGETARCH=${D_ARCH} TARGETOS=linux make build
##################################################################
# Stage: Minimal base image update and install common requirements
FROM $D_BASE_IMAGE AS base
ARG D_APT_REMOVE=""
ARG D_OFED_VERSION
ARG D_CONTAINER_VER
ARG D_OFED_SRC_DOWNLOAD_PATH
ARG STIG_COMPLIANT
ENV NVIDIA_NIC_DRIVER_VER=${D_OFED_VERSION}
ENV NVIDIA_NIC_CONTAINER_VER=${D_CONTAINER_VER}
WORKDIR /root
RUN set -x && \
for source in ${D_APT_REMOVE}; do rm -f /etc/apt/sources.list.d/${source}.list; done && \
# Perform distro update and install prerequirements
apt-get -yq update && \
DEBIAN_FRONTEND=noninteractive apt-get -yq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get -yq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install apt-utils \
# Driver build / install script requirements
perl pciutils kmod lsof python3 dh-python \
# Container functional requirements
jq iproute2 udev ethtool ca-certificates
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
ADD ./entrypoint.sh /root/entrypoint.sh
ADD ./loader.sh /root/loader.sh
# dockerfile COPY instruction limitation requires adding a file - even if it's an empty/dummy file
COPY stig-fixer.sh /tmp/stig-fixer.sh
# run STIG fixer script for STIG complaint image builds
RUN set -x && \
if [ "$STIG_COMPLIANT" = "true" ]; then \
chmod +x /tmp/stig-fixer.sh && \
/tmp/stig-fixer.sh ; \
fi && \
rm -f /tmp/stig-fixer.sh
ENTRYPOINT ["/root/loader.sh"]
##############################################################################################
# Stage: Download NVIDIA driver sources and install src driver container packages requirements
FROM base AS driver-src
# Inherited global args
ARG D_OS
ARG D_DOCA_VERSION
ARG D_OFED_VERSION
ARG D_OFED_SRC_DOWNLOAD_PATH
# Stage args
ARG D_OFED_BASE_URL="https://linux.mellanox.com/public/repo/doca/${D_DOCA_VERSION}/SOURCES/mlnx_ofed"
ARG D_OFED_SRC_TYPE="debian-"
ARG D_OFED_SRC_ARCHIVE="MLNX_OFED_SRC-${D_OFED_SRC_TYPE}${D_OFED_VERSION}.tgz"
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)
ENV NVIDIA_NIC_DRIVER_PATH="${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSION}"
WORKDIR /root
RUN set -x && \
apt-get update
RUN set -x && \
echo $D_OS | grep "ubuntu20.04" || GCC_VER="-12" && \
# Install prerequirements \
DEBIAN_FRONTEND=noninteractive apt-get -yq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install curl \
dkms make autoconf autotools-dev chrpath automake hostname debhelper gcc$GCC_VER quilt libc6-dev build-essential pkg-config ubuntu-advantage-tools && \
# Cleanup \
apt-get clean autoclean && apt install --reinstall -y ca-certificates && \
rm -rf /var/lib/apt/lists/* && update-ca-certificates
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
# Download NVIDIA NIC driver
RUN mkdir -p ${D_OFED_SRC_DOWNLOAD_PATH}
WORKDIR ${D_OFED_SRC_DOWNLOAD_PATH}
ADD ${D_OFED_URL_PATH} ${D_OFED_SRC_ARCHIVE}
RUN if file ${D_OFED_SRC_ARCHIVE} | grep compressed; then \
tar -xzf ${D_OFED_SRC_ARCHIVE}; \
else \
mv ${D_OFED_SRC_ARCHIVE}/MLNX_OFED_SRC-${D_OFED_VERSION} . ; \
fi
WORKDIR /root
CMD ["sources"]
LABEL doca-version=${D_DOCA_VERSION}
LABEL ofed-version=${D_OFED_VERSION}
#####################
# Stage: Build driver
FROM driver-src AS driver-builder
# Inherited global args
ARG D_OS
ARG D_KERNEL_VER
ARG OFED_SRC_LOCAL_DIR
# Additional local arg (for precompiled CI)
ARG D_BUILD_EXTRA_ARGS
# Driver build manadatory packages
RUN set -x && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -yq -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install linux-image-${D_KERNEL_VER} linux-headers-${D_KERNEL_VER}
# Build driver
RUN set -x && \
${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}
###################################
# Stage: Install precompiled driver
FROM base AS precompiled
# Inherited global args
ARG D_OS
ARG D_ARCH
ARG D_KERNEL_VER
ARG OFED_SRC_LOCAL_DIR
ENV NVIDIA_NIC_DRIVER_PATH=""
RUN set -x && \
DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" lsb-release && \
test -n "${D_KERNEL_VER}" && DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" linux-modules-extra-${D_KERNEL_VER} || true # only install this package when kernel variable defined
# Cleanup
RUN set -x && \
apt-get clean autoclean && \
rm -rf /var/lib/apt/lists/*
# Install driver
COPY --from=driver-builder ${OFED_SRC_LOCAL_DIR}/DEBS/${D_OS}/*/*.deb /root/
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" /root/*.deb
# Prevent modprobe from giving a WARNING about missing files
RUN touch /lib/modules/${D_KERNEL_VER}/modules.order /lib/modules/${D_KERNEL_VER}/modules.builtin && \
# Introduce installed kernel modules
depmod ${D_KERNEL_VER}
CMD ["precompiled"]