Skip to content

Instantly share code, notes, and snippets.

@scottrigby
Last active June 10, 2017 20:24
Show Gist options
  • Save scottrigby/30c004699f151e6ac64cb10acba8f412 to your computer and use it in GitHub Desktop.
Save scottrigby/30c004699f151e6ac64cb10acba8f412 to your computer and use it in GitHub Desktop.
#! /bin/bash
## Useful for checking local chart dependencies before pushing the dependent
## chart local changes.
##
## Usage:
## ./package_dep.sh [MAIN_CHART_PATH] [DEP_CHART_PATH] <[DEP_PACKAGE_VERSION | 0.1.0]>
package_dep() {
INSTALLED_GO=false
which go &> /dev/null
if [ $? == 1 ]; then
# We need Go's yaml parser. You might want go in general LOL.
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
export PATH=$PATH:/usr/local/go/bin
INSTALLED_GO=true
fi
INSTALLED_YAML=false
which yaml &> /dev/null
if [ $? == 1 ]; then
# You must have go installed and the go bin in your path.
GO_YAML_PACKAGE=github.com/mikefarah/yaml
go get $GO_YAML_PACKAGE
INSTALLED_YAML=true
fi
# Define vars.
MAIN_CHART_PATH="$1"
MAIN_CHART_NAME=$(helm inspect $MAIN_CHART_PATH | yaml read - name)
DEP_CHART_PATH="$2"
DEP_CHART_NAME=$(helm inspect $DEP_CHART_PATH | yaml read - name)
DEP_PACKAGE_VERSION=${3:-'0.1.0'}
DEP_TARBALL_PATH="$MAIN_CHART_PATH/charts"
DEP_TARBALL_NAME="$DEP_CHART_NAME-$DEP_PACKAGE_VERSION.tgz"
# Cleanup go package if it wasn't already installed.
if [ $INSTALLED_YAML = 'true' ];then
go clean -i $GO_YAML_PACKAGE
fi
# Cleanup go if it wasn't already installed. Note that we don't need to clean
# up path as it won't export outside the function.
if [ $INSTALLED_GO = 'true' ];then
rm -rf /usr/local/go
fi
# Instantiate the chart dep dir if it doesn't aleady exist.
# Note helm package --destination flag does not handle this for us.
ls $DEP_TARBALL_PATH &> /dev/null
if [ $? == 1 ]; then
mkdir -p $DEP_TARBALL_PATH
fi
echo "Repackaging $DEP_CHART_PATH into $DEP_TARBALL_PATH"
helm package --version "$DEP_PACKAGE_VERSION" --destination "$DEP_TARBALL_PATH" "$DEP_CHART_PATH"
ls "$DEP_TARBALL_PATH/$DEP_TARBALL_NAME" &> /dev/null
if [ $? == 0 ]; then
echo 'Finished.'
else
echo 'Something went wrong. Try to package manually.'
exit 1
fi
}
package_dep "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment