Last active
May 30, 2024 09:26
-
-
Save lukeplausin/6d44fdce6f984af628d6929573bbf9bc to your computer and use it in GitHub Desktop.
Upload all historical helm chart versions from a chart git repository history. If you didn't use a chart repository before but you do now, well this chart can help you upload your back catalogue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# This script assumes that you store all your charts in a single repo | |
# under a single folder called charts-folder. It will go back through previous versions | |
# of the code and upload all of them into your chart registry. | |
# This script assumes that you have updated the chart version in `Chart.yaml` | |
# whenever a change has been made in the chart. If this is not the case, you can | |
# switch off version checking by disabling the check on line 54. | |
# If you want to upload without chart signing, then set SIGN_PARAMETERS=(). | |
# If you want to start at a specific commit, then set start_commit=<the start commit>. | |
# To run this script you need zsh and yq installed on your machine. | |
# Warning: This script will clear any uncommitted changes in your repo. | |
export REGISTRY_HOST=my.awesome.chart.registry | |
export REGISTRY_PATH=charts | |
# export SIGN_PARAMETERS=("--sign --key 'Luke Plausin <[email protected]>' --keyring ~/.gnupg/secring.gpg --passphrase-file /tmp/keyring_pass") | |
export SIGN_PARAMETERS=() | |
# SLEEP=1 | |
SLEEP=0 | |
cd ~/path/to/my/charts-repo/charts-folder | |
git checkout main | |
git pull | |
# start_commit=cafedad | |
start_commit=$(git log --pretty=oneline --reverse | head -1 | cut -d ' ' -f 1) | |
echo $SHELL | |
declare -A chartversions | |
for commit in $(git rev-list $start_commit..main --reverse); do | |
git clean -Xdf | |
echo "I am checking out $commit" | |
git checkout $commit | |
rm -rf *.tgz *.prov | |
all_charts=$(ls .) | |
for dirname in */ ; do | |
chartname=${dirname%/} | |
if [ -f "$chartname/Chart.yaml" ]; then | |
echo "processing chart '$chartname'" | |
version=$(cat $chartname/Chart.yaml | yq '.version') | |
# Check if we have already uploaded this version... | |
if [[ "${chartversions[$chartname]}" == $version ]] ; then | |
skip_chart=YES | |
echo "Chart $chartname version $version already processed" | |
else | |
pushd $chartname | |
helm dependency update | |
helm template "test-deployment" . > /dev/null | |
if [ $? -eq 0 ]; then | |
skip_chart=NO | |
# Remember this version of the chart... | |
chartversions[$chartname]=$version | |
else | |
skip_chart=YES | |
echo "Chart $chartname version $version failed template test" | |
fi | |
popd | |
sleep $SLEEP | |
fi | |
if [[ "$skip_chart" == "NO" ]]; then | |
helm package $chartname $SIGN_PARAMETERS | |
helm push $chartname-*.tgz oci://$REGISTRY_HOST/$REGISTRY_PATH | |
# helm push $chartname-*.tgz.prov oci://$REGISTRY_HOST/$REGISTRY_PATH | |
rm -rf $chartname-*.tgz $chartname-*.tgz.prov | |
else | |
echo "Skipping upload..." | |
fi | |
sleep $SLEEP | |
fi | |
done | |
done | |
echo "Done upload, cleaning up..." | |
git clean -Xdf | |
echo "Finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment