Skip to content

Commit

Permalink
Add build automation
Browse files Browse the repository at this point in the history
  • Loading branch information
hickeyma committed Apr 6, 2020
1 parent 90472aa commit a477a35
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 2 deletions.
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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: /.*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin/
tmp/
21 changes: 21 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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'
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -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"
42 changes: 42 additions & 0 deletions scripts/install_plugin.sh
Original file line number Diff line number Diff line change
@@ -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" .
10 changes: 10 additions & 0 deletions scripts/tag.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a477a35

Please sign in to comment.