Skip to content

Instantly share code, notes, and snippets.

@weibeld
Created January 1, 2022 17:39
Show Gist options
  • Save weibeld/3eef3987001849f9532e1162857e5ed1 to your computer and use it in GitHub Desktop.
Save weibeld/3eef3987001849f9532e1162857e5ed1 to your computer and use it in GitHub Desktop.
Package a Helm chart
# Locally package a Helm chart by using a custom values file.
usage() {
echo -e "USAGE\n $(basename $0) chart-dir [values-file] [templates-dir]"
}
[[ ! ( "$#" -eq 1 || "$#" -eq 2 || "$#" -eq 3 ) ]] && { usage; exit 1; }
chart=${1%/}
values=$2
templates=$3
if [[ ! -d "$chart" ]]; then
echo -e "Directory '$chart' does not exist.\n\nIf it's in a submodule, you might need to run the following first:\n\n git submodule update --init"
exit 1
elif [[ -n "$values" && ! -f "$values" ]]; then
echo "File '$values' does not exist."
exit 1
elif [[ -n "$templates" && ! -d "$templates" ]]; then
echo "Directory '$templates' does not exist."
exit 1
fi
tmp=$(mktemp -d)
cp -r "$chart/" "$tmp"
[[ -n "$values" ]] && cp "$values" "$tmp"/values.yaml
[[ -n "$templates" ]] && cp -r "$templates" "$tmp"/templates
file=$(helm package "$tmp" --dependency-update | awk '{print $NF}')
tar xzf "$file" && rm "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment