diff --git a/scripts-common/packman/bootstrap/configure.bat b/scripts-common/packman/bootstrap/configure.bat index 7397fcc83..abf85ed63 100644 --- a/scripts-common/packman/bootstrap/configure.bat +++ b/scripts-common/packman/bootstrap/configure.bat @@ -12,7 +12,7 @@ :: See the License for the specific language governing permissions and :: limitations under the License. -set PM_PACKMAN_VERSION=7.20 +set PM_PACKMAN_VERSION=7.24.2 :: Specify where packman command is rooted set PM_INSTALL_PATH=%~dp0.. diff --git a/scripts-common/packman/bootstrap/install_package.py b/scripts-common/packman/bootstrap/install_package.py index 7f1ab7266..f223ca935 100644 --- a/scripts-common/packman/bootstrap/install_package.py +++ b/scripts-common/packman/bootstrap/install_package.py @@ -142,11 +142,13 @@ def generate_sha256_for_file(file_path: Union[str, os.PathLike]) -> str: def install_common_module(package_path, install_path): - COMMON_SHA256 = "0023d893d3fa3600496cdf7fad9c8e6e0d5d7ab80a35741b4e8520736cc0c375" + COMMON_SHA256 = "7397be5807841f6d6084e1fa77a4f7c8a9a29b4285b4440cf8c2865d1d9fd152" package_sha256 = generate_sha256_for_file(package_path) if package_sha256 != COMMON_SHA256: - raise RuntimeError(f"Package at '{package_path}' must have a sha256 of '{COMMON_SHA256}' " - f"but was found to have '{package_sha256}'") + raise RuntimeError( + f"Package at '{package_path}' must have a sha256 of '{COMMON_SHA256}' " + f"but was found to have '{package_sha256}'" + ) staging_path, version = os.path.split(install_path) with StagingDirectory(staging_path) as staging_dir: output_folder = staging_dir.get_temp_folder_path() diff --git a/scripts-common/packman/packman b/scripts-common/packman/packman index 25e59ccf1..9e6b81050 100644 --- a/scripts-common/packman/packman +++ b/scripts-common/packman/packman @@ -24,7 +24,7 @@ else PM_CURL_SILENT="-s -S" PM_WGET_QUIET="--quiet" fi -export PM_PACKMAN_VERSION=7.20 +export PM_PACKMAN_VERSION=7.24.2 # This is necessary for newer macOS if [ `uname` == 'Darwin' ]; then @@ -60,17 +60,49 @@ if [ ! -d "$PM_PACKAGES_ROOT" ]; then mkdir -p -m a+rwx "$PM_PACKAGES_ROOT" fi +execute_with_retry() +{ + # Don't exit on error, we need to handle them + set +e + + local CMD="$1" + local MAX_TRIES=4 + local DELAY=2 + local TRIES=0 + local exit_code + + while [ $TRIES -lt $MAX_TRIES ] + do + ((TRIES++)) + eval $CMD + exit_code=$? + if [ $exit_code -eq 0 ]; then + return 0 + fi + + if [ $TRIES -lt $MAX_TRIES ]; then + echo "Attempt $TRIES failed. Retrying in $DELAY seconds ..." + sleep $DELAY + DELAY=$((DELAY * DELAY)) + echo "Retrying ..." + fi + done + + echo "Command failed after $MAX_TRIES attempts: $CMD" + return $exit_code +} + fetch_file_from_s3() { - SOURCE=$1 - SOURCE_URL=http://bootstrap.packman.nvidia.com/$SOURCE - TARGET=$2 + local SOURCE=$1 + local SOURCE_URL=http://bootstrap.packman.nvidia.com/$SOURCE + local TARGET=$2 echo "Fetching $SOURCE from bootstrap.packman.nvidia.com ..." + local CMD="curl -o $TARGET $SOURCE_URL $PM_CURL_SILENT" if command -v wget >/dev/null 2>&1; then - wget $PM_WGET_QUIET -O$TARGET $SOURCE_URL - else - curl -o $TARGET $SOURCE_URL $PM_CURL_SILENT + CMD="wget $PM_WGET_QUIET -O$TARGET $SOURCE_URL" fi + execute_with_retry "$CMD" } generate_temp_file_name() diff --git a/scripts-common/packman/packmanconf.py b/scripts-common/packman/packmanconf.py index 6afae51c2..f2dca9e3b 100644 --- a/scripts-common/packman/packmanconf.py +++ b/scripts-common/packman/packmanconf.py @@ -1,4 +1,18 @@ -# Use this file to bootstrap packman into your Python environment (3.7.x). Simply +# Copyright 2021-2024 NVIDIA CORPORATION + +# 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. + +# Use this file to bootstrap packman into your Python environment. Simply # add the path by doing sys.insert to where packmanconf.py is located and then execute: # # >>> import packmanconf @@ -84,7 +98,13 @@ def get_module_dir(conf_dir, packages_root: str, version: str) -> str: tf = tempfile.NamedTemporaryFile(delete=False) target_name = tf.name tf.close() - url = f"http://bootstrap.packman.nvidia.com/packman-common@{version}.zip" + # Using http here and not https is by design. Unfortunately SSL keeps getting revised + # which breaks old clients when servers are forced to upgrade to newer version of TLS + # and refuse to downgrade when asked. Instead of relying on SSL for transport security + # packman does SHA256 verification of the downloaded package in the `install_package` + # method. We therefore inform SonarQube to stop complaining about the line below. + # See issue #367 for more detail. + url = f"http://bootstrap.packman.nvidia.com/packman-common@{version}.zip" # NOSONAR print(f"Downloading '{url}' ...") import urllib.request