Skip to content

Commit

Permalink
Add support for Golang binary to the Dockerfiles
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ykulazhenkov committed Nov 14, 2024
1 parent 4a8c933 commit 2978a74
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
24 changes: 22 additions & 2 deletions RHEL_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSIO
# Final clean image of precompiled driver container
ARG D_FINAL_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:latest

##################################################################
# Stage: build go binary for entrypoint
FROM golang:1.23 AS go_builder

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

Expand Down Expand Up @@ -70,10 +85,13 @@ RUN set -x && \
cd ${D_OFED_SRC_DOWNLOAD_PATH} && (curl -sL ${D_OFED_URL_PATH} | tar -xzf -)

WORKDIR /

COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
ADD ./entrypoint.sh /root/entrypoint.sh
ADD ./dtk_nic_driver_build.sh /root/dtk_nic_driver_build.sh
ADD ./loader.sh /root/loader.sh

ENTRYPOINT ["/root/entrypoint.sh"]
ENTRYPOINT ["/root/loader.sh"]
CMD ["sources"]

#####################
Expand Down Expand Up @@ -135,8 +153,10 @@ RUN touch /lib/modules/${D_KERNEL_VER}/modules.order /lib/modules/${D_KERNEL_VER
depmod ${D_KERNEL_VER}

WORKDIR /
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
ADD ./entrypoint.sh /root/entrypoint.sh
ADD ./dtk_nic_driver_build.sh /root/dtk_nic_driver_build.sh
ADD ./loader.sh /root/loader.sh

ENTRYPOINT ["/root/entrypoint.sh"]
ENTRYPOINT ["/root/loader.sh"]
CMD ["precompiled"]
20 changes: 18 additions & 2 deletions Ubuntu_Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ ARG OFED_SRC_LOCAL_DIR=${D_OFED_SRC_DOWNLOAD_PATH}/MLNX_OFED_SRC-${D_OFED_VERSIO
# 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.23 AS go_builder

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
Expand All @@ -34,10 +49,11 @@ RUN set -x && \
# Container functional requirements
jq iproute2 udev ethtool

WORKDIR /
COPY --from=go_builder /workspace/build/entrypoint /root/entrypoint
ADD ./entrypoint.sh /root/entrypoint.sh
ADD ./loader.sh /root/loader.sh

ENTRYPOINT ["/root/entrypoint.sh"]
ENTRYPOINT ["/root/loader.sh"]

##############################################################################################
# Stage: Download NVIDIA driver sources and install src driver container packages requirements
Expand Down
27 changes: 27 additions & 0 deletions loader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Copyright 2024, NVIDIA CORPORATION & AFFILIATES

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# The script selects the entrypoint script(binary) based on the value of USE_NEW_ENTRYPOINT environment variable.
# By default, it uses the old bash-based implementation.

: "${USE_NEW_ENTRYPOINT:=false}"

if ${USE_NEW_ENTRYPOINT}; then
./entrypoint "$@"
else
./entrypoint.sh "$@"
fi

0 comments on commit 2978a74

Please sign in to comment.