From 1c1ce2c6f78a51f8de1046f7fb35b687267500b8 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 8 May 2023 15:40:42 +0200 Subject: [PATCH] Use version from manifest to extract packages Signed-off-by: Evan Lezar --- scripts/release-kitmaker-artifactory.sh | 9 ---- scripts/release-packages.sh | 25 ++++++----- scripts/utils.sh | 59 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/scripts/release-kitmaker-artifactory.sh b/scripts/release-kitmaker-artifactory.sh index d7bee6dc..1d5c9c76 100755 --- a/scripts/release-kitmaker-artifactory.sh +++ b/scripts/release-kitmaker-artifactory.sh @@ -67,13 +67,6 @@ fi KITMAKER_SCRATCH="${KITMAKER_DIR}/.scratch" -# extract_info extracts the value of the specified variable from the manifest.txt file. -function extract_info() { - local variable=$1 - local value=$(cat "${ARTIFACTS_DIR}/manifest.txt" | grep "#${variable}=" | sed -e "s/#${variable}=//" | tr -d '\r') - echo $value -} - IMAGE_EPOCH=$(extract_info "IMAGE_EPOCH") # Note we use the main branch for the kitmaker archive. GIT_BRANCH=main @@ -129,8 +122,6 @@ function create_archive() { rmdir "${scratch_dir}" } -function join_by { local IFS="$1"; shift; echo "$*"; } - function optionally_add_property() { local property=$1 local value=$2 diff --git a/scripts/release-packages.sh b/scripts/release-packages.sh index ea0ebb23..ccc73026 100755 --- a/scripts/release-packages.sh +++ b/scripts/release-packages.sh @@ -31,6 +31,8 @@ if [[ $# -lt 1 || $# -gt 2 ]]; then assert_usage $* fi +source "${SCRIPTS_DIR}"/utils.sh + PACKAGE_REPO_ROOT=$1 if [[ ! -d ${PACKAGE_REPO_ROOT} ]]; then echo "The specified PACKAGE_REPO_ROOT '${PACKAGE_REPO_ROOT}' must exist" @@ -42,21 +44,20 @@ if [[ $# -ge 2 ]]; then REFERENCE=$2 fi -eval $(${SCRIPTS_DIR}/get-component-versions.sh) - -TAG=v"${NVIDIA_CONTAINER_TOOLKIT_PACKAGE_VERSION}" SHA=$(git rev-parse --short=8 ${REFERENCE}) +IMAGE_NAME="registry.gitlab.com/nvidia/container-toolkit/container-toolkit/staging/container-toolkit" +IMAGE_TAG=${SHA}-packaging + +VERSION="$(get_version_from_image ${IMAGE_NAME}:${IMAGE_TAG} ${SHA})" REPO="experimental" -if [[ ${TAG/rc./} == ${TAG} ]]; then +if [[ ${VERSION/rc./} == ${VERSION} ]]; then REPO="stable" fi -PACKAGE_CACHE=release-${TAG}-${REPO} +PACKAGE_CACHE=release-${VERSION}-${REPO} -echo "Fetching packages with SHA '${SHA}' as tag '${TAG}' to ${PACKAGE_CACHE}" -IMAGE_NAME="registry.gitlab.com/nvidia/container-toolkit/container-toolkit/staging/container-toolkit" -IMAGE_TAG=${SHA}-packaging +echo "Fetching packages with SHA '${SHA}' as tag '${VERSION}' to ${PACKAGE_CACHE}" ${SCRIPTS_DIR}/pull-packages.sh \ ${IMAGE_NAME}:${IMAGE_TAG} \ ${PACKAGE_CACHE} @@ -197,7 +198,7 @@ git -C ${PACKAGE_REPO_ROOT} add ${REPO} if [[ ${REPO} == "stable" ]]; then # Stable release git -C ${PACKAGE_REPO_ROOT} commit -s -F- < /dev/null; then + regctl image get-file "${image}" "${path_in_image}" "${path_on_host}" + else + # Note this will only work for destinations where the `path_on_host` is in `pwd` + docker run --rm \ + -v "$(pwd):$(pwd)" \ + -w "$(pwd)" \ + -u "$(id -u):$(id -g)" \ + --entrypoint="bash" \ + "${image}" \ + -c "cp ${path_in_image} ${path_on_host}" + fi +} + +# extract_info extracts the value of the specified variable from the manifest.txt file. +function extract_from_manifest() { + local variable=$1 + local manifest=$2 + local value=$(cat ${manifest} | grep "#${variable}=" | sed -e "s/#${variable}=//" | tr -d '\r') + echo $value +} + +# extract_info extracts the value of the specified variable from the manifest.txt file. +function extract_info() { + extract_from_manifest $1 "${ARTIFACTS_DIR}/manifest.txt" +} + +function get_version_from_image() { + local image=$1 + local manifest="manifest-${2}.txt" + copy_file ${image} "/artifacts/manifest.txt" ${manifest} + version=$(extract_from_manifest "PACKAGE_VERSION" ${manifest}) + echo "v${version/\~/-}" + rm -f ${manifest} +} + +function join_by { local IFS="$1"; shift; echo "$*"; } \ No newline at end of file