Skip to content

Commit cd40b4c

Browse files
authored
Merge pull request #11 from ykulazhenkov/go-entrypoint-tree
Add entrypoint Go binary
2 parents 13a49d3 + 6f65faa commit cd40b4c

File tree

32 files changed

+3631
-0
lines changed

32 files changed

+3631
-0
lines changed

Golang_Ubuntu_Dockerfile

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
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"]

entrypoint/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
bin/
3+
cover.out

entrypoint/.golangci.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
run:
2+
timeout: 10m
3+
# If set we pass it to "go list -mod={option}". From "go help modules":
4+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
5+
# automatic updating of go.mod described above. Instead, it fails when any changes
6+
# to go.mod are needed. This setting is most useful to check that go.mod does
7+
# not need updates, such as in a continuous integration and testing system.
8+
# If invoked with -mod=vendor, the go command assumes that the vendor
9+
# directory holds the correct copies of dependencies and ignores
10+
# the dependency descriptions in go.mod.
11+
#
12+
# Allowed values: readonly|vendor|mod
13+
# By default, it isn't set.
14+
modules-download-mode: readonly
15+
tests: false
16+
17+
linters:
18+
disable-all: true
19+
# Enable specific linter
20+
# https://golangci-lint.run/usage/linters/#enabled-by-default
21+
enable:
22+
- asasalint
23+
- asciicheck
24+
- bidichk
25+
- bodyclose
26+
- containedctx
27+
- contextcheck
28+
- decorder
29+
- dogsled
30+
- durationcheck
31+
- errcheck
32+
- errchkjson
33+
- errname
34+
- copyloopvar
35+
- fatcontext
36+
- funlen
37+
- ginkgolinter
38+
- goconst
39+
- gocritic
40+
- gocyclo
41+
- gofmt
42+
- gofumpt
43+
- goimports
44+
- gomodguard
45+
- goprintffuncname
46+
- gosec
47+
- gosimple
48+
- govet
49+
- grouper
50+
- importas
51+
- ineffassign
52+
- interfacebloat
53+
- intrange
54+
- lll
55+
- loggercheck
56+
- maintidx
57+
- makezero
58+
- misspell
59+
- nakedret
60+
- nilerr
61+
- nilnil
62+
- noctx
63+
- nolintlint
64+
- nosprintfhostport
65+
- prealloc
66+
- predeclared
67+
- promlinter
68+
- reassign
69+
- revive
70+
- rowserrcheck
71+
- sloglint
72+
- staticcheck
73+
- stylecheck
74+
- tagalign
75+
- thelper
76+
- tparallel
77+
- typecheck
78+
- unconvert
79+
- unparam
80+
- unused
81+
- usestdlibvars
82+
- wastedassign
83+
- whitespace
84+
85+
linters-settings:
86+
funlen:
87+
lines: 120
88+
statements: 55
89+
goconst:
90+
min-len: 2
91+
min-occurrences: 2
92+
gocyclo:
93+
min-complexity: 30
94+
goimports:
95+
local-prefixes: github.com/Mellanox/doca-driver-build
96+
lll:
97+
line-length: 140
98+
misspell:
99+
locale: US
100+
stylecheck:
101+
checks: ["all", "-ST1000"]
102+
dot-import-whitelist:
103+
- github.com/onsi/ginkgo/v2
104+
- github.com/onsi/ginkgo/v2/extensions/table
105+
- github.com/onsi/gomega
106+
- github.com/onsi/gomega/gstruct
107+
gocritic:
108+
disabled-checks:
109+
- appendAssign
110+
ireturn:
111+
allow:
112+
- anon
113+
- error
114+
- empty
115+
- stdlib
116+
revive:
117+
rules:
118+
- name: package-comments
119+
severity: warning
120+
disabled: true
121+
exclude: [""]
122+
- name: import-shadowing
123+
severity: warning
124+
disabled: false
125+
exclude: [""]
126+
- name: exported
127+
severity: warning
128+
disabled: false
129+
exclude: [""]
130+
arguments:
131+
- "checkPrivateReceivers"
132+
- "checkPublicInterface"

entrypoint/.mockery.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
with-expecter: True
2+
dir: "{{.InterfaceDir}}/mocks"
3+
mockname: "{{.InterfaceName}}"
4+
outpkg: "{{.PackageName}}"
5+
filename: "{{.InterfaceName}}.go"
6+
all: True
7+
packages:
8+
github.com/Mellanox/doca-driver-build/entrypoint/internal:
9+
config:
10+
recursive: True

0 commit comments

Comments
 (0)