diff --git a/.build_targets b/.build_targets new file mode 100644 index 0000000..5d140b9 --- /dev/null +++ b/.build_targets @@ -0,0 +1 @@ +darwin/amd64 linux/amd64 linux/386 windows/amd64 \ No newline at end of file diff --git a/Makefile b/Makefile index 12da706..06e4948 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ PROJECT_GH=mbenabda/$(PROJECT_NAME) PKG:= github.com/$(PROJECT_GH) HELM_HOME ?= $(shell helm home) -VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml) -TARGETS ?= darwin/amd64 linux/amd64 linux/386 windows/amd64 +VERSION ?= $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml) +TARGETS ?= $(shell cat .build_targets) LDFLAGS := -X main.Version=$(VERSION) # Clear the "unreleased" string in BuildMetadata @@ -17,12 +17,11 @@ clean: @rm -rf $(PROJECT_BIN_NAME) ./build ./dist .PHONY: build-cross -build-cross: LDFLAGS += -extldflags "-static" +build-cross: LDFLAGS += -s -w -extldflags "-static" build-cross: CGO_ENABLED=0 gox \ -verbose \ - -parallel=3 \ - -output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" \ + -output="dist/$(PROJECT_NAME)-{{.OS}}-{{.Arch}}/$(PROJECT_BIN_NAME)" \ -ldflags "$(LDFLAGS)" \ -osarch="$(TARGETS)" \ $(PKG) @@ -32,9 +31,9 @@ dist: export COPYFILE_DISABLE=1 #teach OSX tar to not put ._* files in tar archi dist: ( \ cd dist && \ - find * -type d -exec cp ../README.md {} \; && \ - find * -type d -exec cp ../plugin.yaml {} \; && \ - find * -type d -exec tar -zcf ${PROJECT_BIN_NAME}-${VERSION}-{}.tgz {} \; \ + find * -maxdepth 1 -type d -exec cp ../README.md {} \; && \ + find * -maxdepth 1 -type d -exec cp ../plugin.yaml {} \; && \ + ls -d * | xargs -I {} -n1 bash -c "cd {} && tar -zcf ../{}.tgz * && cd .." \ ) HAS_GLIDE := $(shell command -v glide;) @@ -68,9 +67,8 @@ install: bootstrap build cp ${PROJECT_BIN_NAME} $(HELM_HOME)/plugins/${PROJECT_NAME}/ cp plugin.yaml $(HELM_HOME)/plugins/${PROJECT_NAME}/ -# usage: make clean bootstrap build-cross dist release .PHONY: release -release: dist +release: clean bootstrap build-cross dist ifndef GITHUB_TOKEN $(error GITHUB_TOKEN is undefined) endif diff --git a/install-binary.sh b/install-binary.sh index b388bf1..d482814 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -43,7 +43,7 @@ if [[ $SKIP_BIN_INSTALL == "1" ]]; then exit fi -# initArch discovers the architecture for this system. +# Discover the architecture for this system. initArch() { ARCH=$(uname -m) case $ARCH in @@ -54,7 +54,7 @@ initArch() { esac } -# initOS discovers the operating system for this system. +# Discover the operating system for this system. initOS() { OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') @@ -66,38 +66,33 @@ initOS() { esac } -# verifySupported checks that the os/arch combination is supported for -# binary builds. -verifySupported() { - local supported="darwin-amd64\nlinux-amd64\nlinux-386\nwindows-amd64" - if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then - echo "No prebuilt binary for ${OS}-${ARCH}." - exit 1 - fi - +# Figure out the download url for the latest available version. +getDownloadURL() { if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then echo "Either curl or wget is required" exit 1 fi -} -# getDownloadURL checks the latest available version. -getDownloadURL() { - local url="https://api.github.com/repos/$PROJECT_GH/releases/latest" + local url="https://api.github.com/repos/${PROJECT_GH}/releases/latest" local version=$(git describe --tags --exact-match 2>/dev/null) if [ -n "$version" ]; then - url="https://api.github.com/repos/$PROJECT_GH/releases/tags/$version" + url="https://api.github.com/repos/${PROJECT_GH}/releases/tags/${version}" fi + # Use the GitHub API to find the download url for this project. if type "curl" > /dev/null; then - DOWNLOAD_URL=$(curl -v -s $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + DOWNLOAD_URL=$(curl -v -s $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') elif type "wget" > /dev/null; then - DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + DOWNLOAD_URL=$(wget -q -O - $url | grep "${OS}-${ARCH}" | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + fi + + if ! echo "${DOWNLOAD_URL}" | grep -q "${OS}-${ARCH}"; then + echo "No prebuilt binary for ${OS}-${ARCH}." + exit 1 fi } -# downloadFile downloads the latest binary package and also the checksum -# for that binary. +# Download the plugin package. downloadFile() { PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz" echo "Downloading $DOWNLOAD_URL" @@ -108,18 +103,16 @@ downloadFile() { fi } -# installFile verifies the SHA256 for the file, then unpacks and -# installs it. +# Unpack and install the helm plugin installFile() { HELM_TMP="/tmp/$PROJECT_NAME" mkdir -p "$HELM_TMP" tar xf "$PLUGIN_TMP_FILE" -C "$HELM_TMP" - HELM_TMP_BIN="$HELM_TMP/${PROJECT_NAME}/${PROJECT_BIN_NAME}" echo "Preparing to install into ${HELM_PLUGIN_PATH}" - cp "$HELM_TMP_BIN" "$HELM_PLUGIN_PATH" + cp -r "$HELM_TMP" "$HELM_PLUGIN_PATH" } -# fail_trap is executed if an error occurs. +# Executed if an error occurs. fail_trap() { result=$? if [ "$result" != "0" ]; then @@ -129,7 +122,7 @@ fail_trap() { exit $result } -# testVersion tests the installed client to make sure it is working. +# Use the installed plugin's binary to make sure it is working. testVersion() { set +e echo "$PROJECT_NAME installed into $HELM_PLUGIN_PATH/$PROJECT_BIN_NAME" @@ -144,7 +137,6 @@ trap "fail_trap" EXIT set -e initArch initOS -verifySupported getDownloadURL downloadFile installFile diff --git a/plugin.yaml b/plugin.yaml index ae6ef1e..e11d3cd 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -2,7 +2,7 @@ name: "local-chart-version" version: "0.0.1" usage: "local-chart-version [subcommand] LOCAL_CHART_DIRECTORY [flags]" description: |- - Helm plugin for bumping/manually setting the version number of a local helm chart + Helm plugin for setting/bumping the version number of a local chart Usage: "local-chart-version [subcommand] LOCAL_CHART_DIRECTORY [flags]" command: "$HELM_PLUGIN_DIR/local-chart-version" hooks: