diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..40c206f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,40 @@ +version: 2 +jobs: + lint: + docker: + - image: koalaman/shellcheck-alpine + steps: + - checkout + - run: + name: lint + command: | + shellcheck -x scripts/tag.sh + shellcheck -x scripts/install_plugin.sh + untagged-build: + docker: + - image: circleci/golang:1.13 + working_directory: /go/src/github.com/hickeyma/helm-mapkubeapis + steps: + - checkout + - run: make build + tagged-build: + docker: + - image: circleci/golang:1.13 + working_directory: /go/src/github.com/hickeyma/helm-mapkubeapis + steps: + - checkout + - run: curl -sL https://raw.githubusercontent.com/goreleaser/get/master/get | VERSION=v0.117.2 bash +workflows: + version: 2 + untagged-build: + jobs: + - lint + - untagged-build + tagged-build: + jobs: + - tagged-build: + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ diff --git a/.gitignore b/.gitignore index e660fd9..ec905b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +tmp/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..eae26ae --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,21 @@ +builds: + - main: ./cmd/helm-mapkubeapis/map_kube_apis.go + binary: mapkubeapis + env: + - CGO_ENABLED=0 + goos: + - darwin + - linux + - windows + goarch: + - amd64 + - arm64 +archive: + format: tar.gz + files: + - README.md + - LICENSE + - plugin.yaml + - scripts/install_plugin.sh +checksum: + name_template: 'checksums.txt' diff --git a/README.md b/README.md index b1e6ad9..9677486 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,25 @@ The `mapkubeapis` plugin fixes the issue by mapping releases which contain depre > Note: It currently support Helm v3 only. +## Install + +Based on the version in `plugin.yaml`, release binary will be downloaded from GitHub: + +```console +$ helm plugin install https://github.com/hickeyma/helm-mapkubeapis.git +Downloading and installing helm-mapkubeapis v0.0.1 ... +https://github.com/hickeyma/helm-mapkubeapis/releases/download/v0.0.1/helm-mapkubeapis_0.0.1_darwin_amd64.tar.gz +Installed plugin: mapkubeapis +``` + +### For Windows (using WSL) +Helm's plugin install hook system relies on `/bin/sh`, regardless of the operating system present. Windows users can work around this by using Helm under [WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10). +``` +$ wget https://get.helm.sh/helm-v3.0.0-linux-amd64.tar.gz +$ tar xzf helm-v3.0.0-linux-amd64.tar.gz +$ ./linux-amd64/helm plugin install https://github.com/hickeyma/helm-mapkubeapis +``` + ## Usage ### Map Helm v3 deprecated Kubernetes APIs diff --git a/plugin.yaml b/plugin.yaml index 4d8538c..f820782 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,8 @@ name: "mapkubeapis" version: "0.0.1" -usage: "map release deprecated Kubernetes APIs in-place" -description: "map release deprecated Kubernetes APIs in-place" +usage: "Map release deprecated Kubernetes APIs in-place" +description: "Map release deprecated Kubernetes APIs in-place" command: "$HELM_PLUGIN_DIR/bin/mapkubeapis" +hooks: + install: "cd $HELM_PLUGIN_DIR; scripts/install_plugin.sh" + update: "cd $HELM_PLUGIN_DIR; scripts/install_plugin.sh" diff --git a/scripts/install_plugin.sh b/scripts/install_plugin.sh new file mode 100755 index 0000000..6881e93 --- /dev/null +++ b/scripts/install_plugin.sh @@ -0,0 +1,42 @@ +#!/bin/sh -e + +if [ -n "${HELM_LINTER_PLUGIN_NO_INSTALL_HOOK}" ]; then + echo "Development mode: not downloading versioned release." + exit 0 +fi + +# shellcheck disable=SC2002 +version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" +echo "Downloading and installing helm-mapkubeapis v${version} ..." + +url="" +if [ "$(uname)" = "Darwin" ]; then + url="https://github.com/hickeyma/helm-mapkubeapis/releases/download/v${version}/helm-mapkubeapis_${version}_darwin_amd64.tar.gz" +elif [ "$(uname)" = "Linux" ] ; then + if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then + url="https://github.com/hickeyma/helm-mapkubeapis/releases/download/v${version}/helm-mapkubeapis_${version}_linux_arm64.tar.gz" + else + url="https://github.com/hickeyma/helm-mapkubeapis/releases/download/v${version}/helm-mapkubeapis_${version}_linux_amd64.tar.gz" + fi +else + url="https://github.com/hickeyma/helm-mapkubeapis/releases/download/v${version}/helm-mapkubeapis_${version}_windows_amd64.tar.gz" +fi + +echo "$url" + +mkdir -p "bin" +mkdir -p "releases/v${version}" + +# Download with curl if possible. +# shellcheck disable=SC2230 +if [ -x "$(which curl 2>/dev/null)" ]; then + curl -sSL "${url}" -o "releases/v${version}.tar.gz" +else + wget -q "${url}" -O "releases/v${version}.tar.gz" +fi +tar xzf "releases/v${version}.tar.gz" -C "releases/v${version}" +mv "releases/v${version}/mapkubeapis" "bin/mapkubeapis" || \ + mv "releases/v${version}/mapkubeapis.exe" "bin/mapkubeapis" +mv "releases/v${version}/plugin.yaml" . +mv "releases/v${version}/README.md" . +mv "releases/v${version}/LICENSE" . diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 0000000..e3ab68a --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,10 @@ +#!/bin/sh -e + +# shellcheck disable=SC2002 +tag="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)" +echo "Tagging helm-mapkubeapis with v${tag} ..." + +git checkout master +git pull +git tag -a -m "Release v$tag" "v$tag" +git push origin refs/tags/v"$tag"