Skip to content

Commit

Permalink
Add 'prepare-release.sh' script
Browse files Browse the repository at this point in the history
This script updates chart version and creates helm package.

Related: #131
  • Loading branch information
e0ne committed Mar 23, 2021
1 parent ff5c371 commit af163e5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
containers:
- name: network-operator
# Replace this with the built image name
image: mellanox/network-operator
mellanox/network-operator
command:
- network-operator
imagePullPolicy: IfNotPresent
Expand Down
2 changes: 1 addition & 1 deletion deployment/network-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: network-operator
version: 0.3.0
kubeVersion: '>= 1.17.0'
appVersion: v0.3.0
appVersion: v0.3.1
description: Nvidia Mellanox network operator
type: application
keywords:
Expand Down
127 changes: 127 additions & 0 deletions scripts/releases/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash -e
# Copyright 2020 NVIDIA
#
# 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.

set -o pipefail

this=`basename $0`

usage () {
cat << EOF
Usage: $this [-h] RELEASE_VERSION GPG_KEY
Options:
-h show this help and exit
Example:
$this v0.1.2 "Jane Doe <jane.doe@example.com>"
NOTE: The GPG key should be associated with the signer's Github account.
EOF
}

sign_helm_chart() {
local chart="$1"
echo "Signing Helm chart $chart"
local sha256=`openssl dgst -sha256 "$chart" | awk '{ print $2 }'`
local yaml=`tar xf $chart -O network-operator/Chart.yaml`
echo "$yaml
...
files:
$chart: sha256:$sha256" | gpg -u "$key" --clearsign -o "$chart.prov"
}

#
# Parse command line
#
while getopts "h" opt; do
case $opt in
h) usage
exit 0
;;
*) usage
exit 1
;;
esac
done
shift "$((OPTIND - 1))"

# Check that no extra args were provided
if [ $# -ne 2 ]; then
if [ $# -lt 2 ]; then
echo -e "ERROR: too few arguments\n"
else
echo -e "ERROR: unknown arguments: ${@:3}\n"
fi
usage
exit 1
fi

release=$1
key="$2"
shift 2

container_image=k8s.gcr.io/nfd/node-feature-discovery:$release

#
# Check/parse release number
#
if [ -z "$release" ]; then
echo -e "ERROR: missing RELEASE_VERSION\n"
usage
exit 1
fi

if [[ $release =~ ^(v[0-9]+\.[0-9]+)(\..+)?$ ]]; then
docs_version=${BASH_REMATCH[1]}
semver=${release:1}
else
echo -e "ERROR: invalid RELEASE_VERSION '$release'"
exit 1
fi

## Patch deployment files
sed -e s"/image:.*/image: mellanox\/network-operator:$release/" \
-i deploy/operator.yaml

# Patch Helm chart
chart=`echo $release | cut -c 2-`
sed -e s"/appVersion:.*/appVersion: $release/" \
-e s"/^version:.*/version: $chart/" \
-i deployment/network-operator/Chart.yaml
sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" \
-i deployment/network-operator/values.yaml

#
# Create release assets to be uploaded
#
helm package deployment/network-operator/ --version $semver

chart_name="network-operator-$semver.tgz"
sign_helm_chart $chart_name

cat << EOF
*******************************************************************************
*** Please manually upload the following generated files to the Github release
*** page:
***
*** $chart_name
*** $chart_name.prov
***
*******************************************************************************
EOF

0 comments on commit af163e5

Please sign in to comment.