|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -o pipefail |
| 18 | + |
| 19 | +this=`basename $0` |
| 20 | + |
| 21 | +usage () { |
| 22 | +cat << EOF |
| 23 | +Usage: $this [-h] |
| 24 | +
|
| 25 | +Options: |
| 26 | + --helm-repo-path specify the path to the Helm repo (defaults to HELM_REPO_PATH) |
| 27 | + --help/-h show help for this command and exit |
| 28 | +
|
| 29 | +Example: |
| 30 | + - from a local path: |
| 31 | + $this /path/to/nvidia-device-plugin-{{ VERSION }}.tgz |
| 32 | + - from a URL: |
| 33 | + $this https://github.com/NVIDIA/k8s-device-plugin/archive/refs/tags/nvidia-device-plugin-{{ VERSION }}.tgz |
| 34 | +
|
| 35 | +EOF |
| 36 | +} |
| 37 | + |
| 38 | +# |
| 39 | +# Parse command line |
| 40 | +# |
| 41 | +while [[ $# -gt 0 ]]; do |
| 42 | + key="$1" |
| 43 | + case $key in |
| 44 | + --helm-repo-path) |
| 45 | + HELM_REPO_PATH="$2" |
| 46 | + shift 2 |
| 47 | + break |
| 48 | + ;; |
| 49 | + --help/h) usage |
| 50 | + exit 0 |
| 51 | + ;; |
| 52 | + esac |
| 53 | +done |
| 54 | + |
| 55 | +if [ -z "${HELM_REPO_PATH}" ]; then |
| 56 | + echo "helm repo path not specified" |
| 57 | + usage |
| 58 | + exit 1 |
| 59 | +fi |
| 60 | + |
| 61 | +# now we take the input from the user and check if is a path or url http/https |
| 62 | +asset_path="$@" |
| 63 | + |
| 64 | +if [ -z "$asset_path" ]; then |
| 65 | + echo "No assets provided" |
| 66 | + usage |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +if [[ $asset_path =~ ^https?:// ]]; then |
| 71 | + asset_urls=$asset_path |
| 72 | +else |
| 73 | + asset_local=$asset_path |
| 74 | +fi |
| 75 | + |
| 76 | +GH_REPO_PULL_URL="https://github.com/NVIDIA/k8s-device-plugin.git" |
| 77 | +git clone --depth=1 --branch=gh-pages ${GH_REPO_PULL_URL} ${HELM_REPO_PATH} |
| 78 | +mkdir -p ${HELM_REPO_PATH}/stable |
| 79 | + |
| 80 | +# Charts are local, no need to download |
| 81 | +if [ -n "$asset_local" ]; then |
| 82 | + echo "Copying $asset_local..." |
| 83 | + cp -f $asset_local $HELM_REPO_PATH/stable |
| 84 | +else |
| 85 | + # Download charts from release assets |
| 86 | + for asset_url in $asset_urls; do |
| 87 | + if ! echo "$asset_url" | grep -q '.*tgz$'; then |
| 88 | + echo "Skipping $asset_url, does not look like a Helm chart archive" |
| 89 | + continue |
| 90 | + fi |
| 91 | + echo "Downloading $asset_url..." |
| 92 | + curl -sSfLO -o $HELM_REPO_PATH/stable/$(basename $asset_url) $asset_url |
| 93 | + # We rely on all release assets having the same baseurl |
| 94 | + download_baseurl=`dirname $HELM_REPO_PATH/stable/$(basename $asset_url)` |
| 95 | + done |
| 96 | + if [ -z "$download_baseurl" ]; then |
| 97 | + echo "No Helm chart release assets found" |
| 98 | + exit 0 |
| 99 | + fi |
| 100 | +fi |
| 101 | + |
| 102 | +echo "Updating helm index" |
| 103 | +helm repo index $HELM_REPO_PATH/stable --merge $HELM_REPO_PATH/stable/index.yaml --url https://nvidia.github.io/k8s-device-plugin/stable |
| 104 | +cp -f $HELM_REPO_PATH/stable/index.yaml $HELM_REPO_PATH/index.yaml |
| 105 | + |
| 106 | +changes=$( git -C $HELM_REPO_PATH status --short ) |
| 107 | + |
| 108 | +# Check if there were any changes in the repo |
| 109 | +if [ -z "${changes}" ]; then |
| 110 | + echo "No changes in Helm repo index, gh-pages branch already up-to-date" |
| 111 | + exit 0 |
| 112 | +fi |
| 113 | + |
| 114 | +VERSION=$( echo "${changes}" | grep -v index | grep -oE "\-[0-9\.]+(\-[\-\.rc0-9]+)?.tgz" | sort -u ) |
| 115 | +VERSION=${VERSION#-} |
| 116 | +VERSION=${VERSION%.tgz} |
| 117 | + |
| 118 | +if [ -z "${VERSION}" ]; then |
| 119 | + echo "Could not extract version information" |
| 120 | + exit 1 |
| 121 | +fi |
| 122 | + |
| 123 | +VERSION="v$VERSION" |
| 124 | + |
| 125 | +# Create a new commit |
| 126 | +echo "Committing changes..." |
| 127 | +git -C $HELM_REPO_PATH add index.yaml stable |
| 128 | + |
| 129 | +cat <<EOF | git -C $HELM_REPO_PATH commit --signoff -F - |
| 130 | +Add packages for ${VERSION} release |
| 131 | +
|
| 132 | +This adds the following packages to the NVIDIA GPU Device Plugin Helm repo: |
| 133 | +$( git -C $HELM_REPO_PATH diff HEAD --name-only | grep -v index | sed 's#stable/#* #g' | sort -r ) |
| 134 | +
|
| 135 | +Note: This is an automated commit. |
| 136 | +
|
| 137 | +EOF |
| 138 | + |
| 139 | +echo "gh-pages branch successfully updated" |
0 commit comments