mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-13 15:14:08 +00:00
shellcheck: Update nvidia_rootfs.sh
With the new rules we need more updates. Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
parent
af1d6c2407
commit
94579517d4
@ -5,7 +5,7 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
[ -n "$DEBUG" ] && set -x
|
[[ -n "${DEBUG}" ]] && set -x
|
||||||
|
|
||||||
readonly BUILD_DIR="/kata-containers/tools/packaging/kata-deploy/local-build/build/"
|
readonly BUILD_DIR="/kata-containers/tools/packaging/kata-deploy/local-build/build/"
|
||||||
# catch errors and then assign
|
# catch errors and then assign
|
||||||
@ -14,13 +14,17 @@ readonly SCRIPT_DIR="${script_dir}/nvidia"
|
|||||||
|
|
||||||
# This will control how much output the inird/image will produce
|
# This will control how much output the inird/image will produce
|
||||||
DEBUG=""
|
DEBUG=""
|
||||||
KBUILD_SIGN_PIN=${KBUILD_SIGN_PIN:-""}
|
KBUILD_SIGN_PIN=${KBUILD_SIGN_PIN:-}
|
||||||
|
|
||||||
machine_arch=${ARCH}
|
NVIDIA_GPU_STACK=${NVIDIA_GPU_STACK:?NVIDIA_GPU_STACK must be set}
|
||||||
|
VARIANT=${VARIANT:?VARIANT must be set}
|
||||||
|
ARCH=${ARCH:?ARCH must be set}
|
||||||
|
|
||||||
if [[ "$machine_arch" == "aarch64" ]]; then
|
machine_arch="${ARCH}"
|
||||||
|
|
||||||
|
if [[ "${machine_arch}" == "aarch64" ]]; then
|
||||||
distro_arch="arm64"
|
distro_arch="arm64"
|
||||||
elif [[ "$machine_arch" == "x86_64" ]]; then
|
elif [[ "${machine_arch}" == "x86_64" ]]; then
|
||||||
distro_arch="amd64"
|
distro_arch="amd64"
|
||||||
else
|
else
|
||||||
die "Unsupported architecture: ${machine_arch}"
|
die "Unsupported architecture: ${machine_arch}"
|
||||||
@ -40,7 +44,7 @@ setup_nvidia-nvrc() {
|
|||||||
pushd "${TARGET_BUILD_DIR}" > /dev/null || exit 1
|
pushd "${TARGET_BUILD_DIR}" > /dev/null || exit 1
|
||||||
|
|
||||||
rm -rf "${PROJECT}"
|
rm -rf "${PROJECT}"
|
||||||
git clone https://github.com/NVIDIA/${PROJECT}.git
|
git clone https://github.com/NVIDIA/"${PROJECT}".git
|
||||||
|
|
||||||
pushd "${PROJECT}" > /dev/null || exit 1
|
pushd "${PROJECT}" > /dev/null || exit 1
|
||||||
|
|
||||||
@ -68,8 +72,8 @@ setup_nvidia-gpu-admin-tools() {
|
|||||||
|
|
||||||
pushd "${TARGET_BUILD_DIR}" > /dev/null || exit 1
|
pushd "${TARGET_BUILD_DIR}" > /dev/null || exit 1
|
||||||
|
|
||||||
rm -rf "$(basename ${TARGET_GIT})"
|
rm -rf "$(basename "${TARGET_GIT}")"
|
||||||
git clone ${TARGET_GIT}
|
git clone "${TARGET_GIT}"
|
||||||
|
|
||||||
rm -rf dist
|
rm -rf dist
|
||||||
# Installed via pipx local python environment
|
# Installed via pipx local python environment
|
||||||
@ -99,14 +103,14 @@ setup_nvidia-dcgm-exporter() {
|
|||||||
local dex="dcgm-exporter"
|
local dex="dcgm-exporter"
|
||||||
|
|
||||||
rm -rf "${dex}"
|
rm -rf "${dex}"
|
||||||
git clone --branch "${TARGET_VERSION}" https://github.com/NVIDIA/${dex}
|
git clone --branch "${TARGET_VERSION}" https://github.com/NVIDIA/"${dex}"
|
||||||
make -C ${dex} binary
|
make -C "${dex}" binary
|
||||||
|
|
||||||
mkdir -p ../destdir/bin
|
mkdir -p ../destdir/bin
|
||||||
mkdir -p ../destdir/etc/${dex}
|
mkdir -p ../destdir/etc/"${dex}"
|
||||||
|
|
||||||
cp ${dex}/cmd/${dex}/${dex} ../destdir/bin/.
|
cp "${dex}"/cmd/"${dex}"/"${dex}" ../destdir/bin/.
|
||||||
cp ${dex}/etc/*.csv ../destdir/etc/${dex}/.
|
cp "${dex}"/etc/*.csv ../destdir/etc/"${dex}"/.
|
||||||
|
|
||||||
tar cvfa "${TARBALL}" -C ../destdir .
|
tar cvfa "${TARBALL}" -C ../destdir .
|
||||||
tar tvf "${TARBALL}"
|
tar tvf "${TARBALL}"
|
||||||
@ -115,7 +119,7 @@ setup_nvidia-dcgm-exporter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_nvidia_gpu_rootfs_stage_one() {
|
setup_nvidia_gpu_rootfs_stage_one() {
|
||||||
if [ -e "${BUILD_DIR}/kata-static-nvidia-gpu-rootfs-stage-one.tar.zst" ]; then
|
if [[ -e "${BUILD_DIR}/kata-static-nvidia-gpu-rootfs-stage-one.tar.zst" ]]; then
|
||||||
info "nvidia: GPU rootfs stage one already exists"
|
info "nvidia: GPU rootfs stage one already exists"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -124,11 +128,11 @@ setup_nvidia_gpu_rootfs_stage_one() {
|
|||||||
|
|
||||||
local rootfs_type=${1:-""}
|
local rootfs_type=${1:-""}
|
||||||
|
|
||||||
info "nvidia: Setup GPU rootfs type=$rootfs_type"
|
info "nvidia: Setup GPU rootfs type=${rootfs_type}"
|
||||||
|
|
||||||
for component in "nvidia-gpu-admin-tools" "nvidia-dcgm-exporter" "nvidia-nvrc"; do
|
for component in "nvidia-gpu-admin-tools" "nvidia-dcgm-exporter" "nvidia-nvrc"; do
|
||||||
if [ ! -e "${BUILD_DIR}/kata-static-${component}.tar.zst" ]; then
|
if [[ ! -e "${BUILD_DIR}/kata-static-${component}.tar.zst" ]]; then
|
||||||
setup_${component}
|
setup_"${component}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -137,28 +141,28 @@ setup_nvidia_gpu_rootfs_stage_one() {
|
|||||||
chmod +x ./nvidia_chroot.sh
|
chmod +x ./nvidia_chroot.sh
|
||||||
|
|
||||||
local appendix=""
|
local appendix=""
|
||||||
if [ "$rootfs_type" == "confidential" ]; then
|
if [[ "${rootfs_type}" == "confidential" ]]; then
|
||||||
appendix="-${rootfs_type}"
|
appendix="-${rootfs_type}"
|
||||||
fi
|
fi
|
||||||
if echo "$NVIDIA_GPU_STACK" | grep -q '\<dragonball\>'; then
|
if echo "${NVIDIA_GPU_STACK}" | grep -q '\<dragonball\>'; then
|
||||||
appendix="-dragonball-experimental"
|
appendix="-dragonball-experimental"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We need the kernel packages for building the drivers cleanly will be
|
# We need the kernel packages for building the drivers cleanly will be
|
||||||
# deinstalled and removed from the roofs once the build finishes.
|
# deinstalled and removed from the roofs once the build finishes.
|
||||||
tar -xvf ${BUILD_DIR}/kata-static-kernel-nvidia-gpu"${appendix}"-headers.tar.xz -C .
|
tar -xvf "${BUILD_DIR}"/kata-static-kernel-nvidia-gpu"${appendix}"-headers.tar.xz -C .
|
||||||
|
|
||||||
# If we find a local downloaded run file build the kernel modules
|
# If we find a local downloaded run file build the kernel modules
|
||||||
# with it, otherwise use the distribution packages. Run files may have
|
# with it, otherwise use the distribution packages. Run files may have
|
||||||
# more recent drivers available then the distribution packages.
|
# more recent drivers available then the distribution packages.
|
||||||
local run_file_name="nvidia-driver.run"
|
local run_file_name="nvidia-driver.run"
|
||||||
if [ -f ${BUILD_DIR}/${run_file_name} ]; then
|
if [[ -f ${BUILD_DIR}/${run_file_name} ]]; then
|
||||||
cp -L ${BUILD_DIR}/${run_file_name} ./${run_file_name}
|
cp -L "${BUILD_DIR}"/"${run_file_name}" ./"${run_file_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local run_fm_file_name="nvidia-fabricmanager.run"
|
local run_fm_file_name="nvidia-fabricmanager.run"
|
||||||
if [ -f ${BUILD_DIR}/${run_fm_file_name} ]; then
|
if [[ -f ${BUILD_DIR}/${run_fm_file_name} ]]; then
|
||||||
cp -L ${BUILD_DIR}/${run_fm_file_name} ./${run_fm_file_name}
|
cp -L "${BUILD_DIR}"/"${run_fm_file_name}" ./"${run_fm_file_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mount --rbind /dev ./dev
|
mount --rbind /dev ./dev
|
||||||
@ -310,7 +314,7 @@ compress_rootfs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggle_debug() {
|
toggle_debug() {
|
||||||
if echo "$NVIDIA_GPU_STACK" | grep -q '\<debug\>'; then
|
if echo "${NVIDIA_GPU_STACK}" | grep -q '\<debug\>'; then
|
||||||
export DEBUG="true"
|
export DEBUG="true"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -320,13 +324,13 @@ setup_nvidia_gpu_rootfs_stage_two() {
|
|||||||
readonly stage_two="${ROOTFS_DIR:?}"
|
readonly stage_two="${ROOTFS_DIR:?}"
|
||||||
readonly stack="${NVIDIA_GPU_STACK:?}"
|
readonly stack="${NVIDIA_GPU_STACK:?}"
|
||||||
|
|
||||||
echo "nvidia: chisseling the following stack components: $stack"
|
echo "nvidia: chisseling the following stack components: ${stack}"
|
||||||
|
|
||||||
|
|
||||||
[ -e "${stage_one}" ] && rm -rf "${stage_one}"
|
[[ -e "${stage_one}" ]] && rm -rf "${stage_one}"
|
||||||
[ ! -e "${stage_one}" ] && mkdir -p "${stage_one}"
|
[[ ! -e "${stage_one}" ]] && mkdir -p "${stage_one}"
|
||||||
|
|
||||||
tar -C "${stage_one}" -xf ${BUILD_DIR}/kata-static-rootfs-nvidia-gpu-stage-one.tar.zst
|
tar -C "${stage_one}" -xf "${BUILD_DIR}"/kata-static-rootfs-nvidia-gpu-stage-one.tar.zst
|
||||||
|
|
||||||
|
|
||||||
pushd "${stage_two}" >> /dev/null
|
pushd "${stage_two}" >> /dev/null
|
||||||
@ -335,19 +339,19 @@ setup_nvidia_gpu_rootfs_stage_two() {
|
|||||||
chisseled_init
|
chisseled_init
|
||||||
chisseled_iptables
|
chisseled_iptables
|
||||||
|
|
||||||
IFS=',' read -r -a stack_components <<< "$NVIDIA_GPU_STACK"
|
IFS=',' read -r -a stack_components <<< "${NVIDIA_GPU_STACK}"
|
||||||
|
|
||||||
for component in "${stack_components[@]}"; do
|
for component in "${stack_components[@]}"; do
|
||||||
if [ "$component" = "compute" ]; then
|
if [[ "${component}" = "compute" ]]; then
|
||||||
echo "nvidia: processing \"compute\" component"
|
echo "nvidia: processing \"compute\" component"
|
||||||
chisseled_compute
|
chisseled_compute
|
||||||
elif [ "$component" = "dcgm" ]; then
|
elif [[ "${component}" = "dcgm" ]]; then
|
||||||
echo "nvidia: processing DCGM component"
|
echo "nvidia: processing DCGM component"
|
||||||
chisseled_dcgm
|
chisseled_dcgm
|
||||||
elif [ "$component" = "nvswitch" ]; then
|
elif [[ "${component}" = "nvswitch" ]]; then
|
||||||
echo "nvidia: processing NVSwitch component"
|
echo "nvidia: processing NVSwitch component"
|
||||||
chisseled_nvswitch
|
chisseled_nvswitch
|
||||||
elif [ "$component" = "gpudirect" ]; then
|
elif [[ "${component}" = "gpudirect" ]]; then
|
||||||
echo "nvidia: processing GPUDirect component"
|
echo "nvidia: processing GPUDirect component"
|
||||||
chisseled_gpudirect
|
chisseled_gpudirect
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user