Skip to content

Commit 4231821

Browse files
ykulazhenkovrollandf
authored andcommitted
Add support for Golang binary to the Dockerfiles
This update ensures that the binary is always compiled during the build stage and incorporated into the image. By default, the existing bash-based entrypoint is used. To activate the new Go-based entrypoint, set `USE_NEW_ENTRYPOINT=true`. Signed-off-by: Yury Kulazhenkov <[email protected]>
1 parent 1130c07 commit 4231821

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

RHEL_Dockerfile

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSIO
1111
# Final clean image of precompiled driver container
1212
ARG D_FINAL_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest
1313

14+
##################################################################
15+
# Stage: build go binary for entrypoint
16+
FROM golang:1.23 AS go_builder
17+
18+
WORKDIR /workspace
19+
20+
COPY entrypoint/go.mod go.mod
21+
COPY entrypoint/go.sum go.sum
22+
23+
RUN go mod download
24+
25+
COPY entrypoint/ .
26+
27+
RUN TARGETARCH=${D_ARCH} TARGETOS=linux make build
28+
1429
##################################################################
1530
# Stage: Minimal base image update and install common requirements
1631

@@ -77,10 +92,13 @@ RUN if file ${D_OFED_SRC_ARCHIVE} | grep compressed; then \
7792
fi
7893

7994
WORKDIR /
95+
96+
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
8097
ADD ./entrypoint.sh /root/entrypoint.sh
8198
ADD ./dtk_nic_driver_build.sh /root/dtk_nic_driver_build.sh
99+
ADD ./loader.sh /root/loader.sh
82100

83-
ENTRYPOINT ["/root/entrypoint.sh"]
101+
ENTRYPOINT ["/root/loader.sh"]
84102
CMD ["sources"]
85103

86104
LABEL doca-version=${D_DOCA_VERSION}
@@ -138,8 +156,10 @@ RUN touch /lib/modules/${D_KERNEL_VER}/modules.order /lib/modules/${D_KERNEL_VER
138156
depmod ${D_KERNEL_VER}
139157

140158
WORKDIR /
159+
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
141160
ADD ./entrypoint.sh /root/entrypoint.sh
142161
ADD ./dtk_nic_driver_build.sh /root/dtk_nic_driver_build.sh
162+
ADD ./loader.sh /root/loader.sh
143163

144-
ENTRYPOINT ["/root/entrypoint.sh"]
164+
ENTRYPOINT ["/root/loader.sh"]
145165
CMD ["precompiled"]

Ubuntu_Dockerfile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSIO
1111
# Common for build and final clean image of precompiled driver container
1212
ARG D_BASE_IMAGE="ubuntu:22.04"
1313

14+
##################################################################
15+
# Stage: build go binary for entrypoint
16+
FROM golang:1.23 AS go_builder
17+
18+
WORKDIR /workspace
19+
20+
COPY entrypoint/go.mod go.mod
21+
COPY entrypoint/go.sum go.sum
22+
23+
RUN go mod download
24+
25+
COPY entrypoint/ .
26+
27+
RUN TARGETARCH=${D_ARCH} TARGETOS=linux make build
28+
1429
##################################################################
1530
# Stage: Minimal base image update and install common requirements
1631
FROM $D_BASE_IMAGE AS base
@@ -35,10 +50,11 @@ RUN set -x && \
3550
# Container functional requirements
3651
jq iproute2 udev ethtool ca-certificates
3752

38-
WORKDIR /
53+
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
3954
ADD ./entrypoint.sh /root/entrypoint.sh
55+
ADD ./loader.sh /root/loader.sh
4056

41-
ENTRYPOINT ["/root/entrypoint.sh"]
57+
ENTRYPOINT ["/root/loader.sh"]
4258

4359
##############################################################################################
4460
# Stage: Download NVIDIA driver sources and install src driver container packages requirements

loader.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# The script selects the entrypoint script(binary) based on the value of USE_NEW_ENTRYPOINT environment variable.
19+
# By default, it uses the old bash-based implementation.
20+
21+
: "${USE_NEW_ENTRYPOINT:=false}"
22+
23+
if ${USE_NEW_ENTRYPOINT}; then
24+
./entrypoint "$@"
25+
else
26+
./entrypoint.sh "$@"
27+
fi

0 commit comments

Comments
 (0)