Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehdi BEN ABDALLAH authored and mbenabda committed Feb 22, 2018
1 parent b322a1c commit b162f46
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
vendor/
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
PROJECT_BIN_NAME=local-chart-version
PROJECT_NAME=helm-$(PROJECT_BIN_NAME)
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

LDFLAGS := -X main.Version=$(VERSION)
# Clear the "unreleased" string in BuildMetadata
LDFLAGS += -X $(PKG)/vendor/k8s.io/helm/pkg/version.BuildMetadata=
LDFLAGS += -X $(PKG)/vendor/k8s.io/helm/pkg/version.Version=$(shell grep -A1 "package: k8s.io/helm" glide.yaml | sed -n -e 's/[ ]*version:.*\(v[.0-9]*\).*/\1/p')

.PHONY: clean
clean:
@rm -rf $(PROJECT_BIN_NAME) ./build ./dist

.PHONY: build-cross
build-cross: LDFLAGS += -extldflags "-static"
build-cross:
CGO_ENABLED=0 gox \
-verbose \
-parallel=3 \
-output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" \
-ldflags "$(LDFLAGS)" \
-osarch="$(TARGETS)" \
$(PKG)

.PHONY: dist
dist: export COPYFILE_DISABLE=1 #teach OSX tar to not put ._* files in tar archive
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 {} \; \
)

HAS_GLIDE := $(shell command -v glide;)
HAS_GOX := $(shell command -v gox;)
HAS_GIT := $(shell command -v git;)
HAS_GITHUB_RELEASE := $(shell command -v github-release;)

.PHONY: bootstrap
bootstrap:
ifndef HAS_GLIDE
go get -u github.com/Masterminds/glide
endif
ifndef HAS_GOX
go get -u github.com/mitchellh/gox
endif
ifndef HAS_GIT
$(error You must install Git)
endif
ifndef HAS_GITHUB_RELEASE
go get -u github.com/c4milo/github-release
endif
glide install --strip-vendor

.PHONY: build
build:
go build -i -v -o ${PROJECT_BIN_NAME} -ldflags="$(LDFLAGS)"

.PHONY: install
install: bootstrap build
mkdir -p $(HELM_HOME)/plugins/${PROJECT_NAME}
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
ifndef GITHUB_TOKEN
$(error GITHUB_TOKEN is undefined)
endif
git push
github-release ${PROJECT_GH} v$(VERSION) master "v$(VERSION)" "dist/*.*"
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
# helm-chart-version
Bump Helm Chart version on local filesystem (golang port of github.com/shaneramey/helm-local-bump)
# Helm Chart Version Plugin

This is a Helm plugin that helps you change your chart version.
It is meant to be used in integration pipelines.

## Usage

```
helm local-chart-version [subcommand] [PATH_TO_LOCAL_CHART] [flags]
```

know more:
```
helm local-chart-version help
```

## Install

### Using Helm plugin manager (> 2.3.x)

```shell
helm plugin install https://github.com/mbenabda/helm-local-chart-version
```

### Pre Helm 2.3.0 Installation
Pick a release tarball from the [releases](https://github.com/mbenabda/helm-local-chart-version/releases) page.

Unpack the tarball in your helm plugins directory (`$(helm home)/plugins`).

E.g.
```
curl -L $TARBALL_URL | tar -C $(helm home)/plugins -xzv
```

## Build

Clone the repository into your `$GOPATH` and then build it.

```
$ mkdir -p $GOPATH/src/github.com/mbenabda/
$ cd $GOPATH/src/github.com/mbenabda/
$ git clone https://github.com/mbenabda/helm-local-chart-version.git
$ cd helm-local-chart-version
$ make install
```

The above will install this plugin into your `$HELM_HOME/plugins` directory.

### Prerequisites

- You need to have [Go](http://golang.org) installed. Make sure to set `$GOPATH`
- If you don't have [Glide](http://glide.sh) installed, this will install it into
`$GOPATH/bin` for you.
- install [github.com/c4milo/github-release](https://github.com/c4milo/github-release)
47 changes: 47 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package: github.com/mbenabda/helm-local-chart-version
import:
- package: github.com/Masterminds/semver
version: ~1.3.1
- package: github.com/spf13/cobra
version: ~0.0.1
- package: k8s.io/helm
version: ~2.8.1
subpackages:
- pkg/chartutil
151 changes: 151 additions & 0 deletions install-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#!/bin/bash

# Shamelessly copied from https://github.com/technosophos/helm-template
#
# Helm Template Plugin
# Copyright (C) 2016, Matt Butcher
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

PROJECT_BIN_NAME="local-chart-version"
PROJECT_NAME="helm-${PROJECT_BIN_NAME}"
PROJECT_GH="mbenabda/${PROJECT_NAME}"

: ${HELM_PLUGIN_PATH:="$(helm home)/plugins/${PROJECT_NAME}"}

# Convert the HELM_PLUGIN_PATH to unix if cygpath is
# available. This is the case when using MSYS2 or Cygwin
# on Windows where helm returns a Windows path but we
# need a Unix path

if type cygpath > /dev/null 2>&1; then
HELM_PLUGIN_PATH=$(cygpath -u $HELM_PLUGIN_PATH)
fi

if [[ $SKIP_BIN_INSTALL == "1" ]]; then
echo "Skipping binary install"
exit
fi

# initArch discovers the architecture for this system.
initArch() {
ARCH=$(uname -m)
case $ARCH in
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}

# initOS discovers the operating system for this system.
initOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

case "$OS" in
# Msys support
msys*) OS='windows';;
# Minimalist GNU for Windows
mingw*) OS='windows';;
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

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 version=$(git describe --tags --exact-match 2>/dev/null)
if [ -n "$version" ]; then
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}')
elif type "wget" > /dev/null; then
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
fi
}

# downloadFile downloads the latest binary package and also the checksum
# for that binary.
downloadFile() {
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz"
echo "Downloading $DOWNLOAD_URL"
if type "curl" > /dev/null; then
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE"
elif type "wget" > /dev/null; then
wget -q -O "$PLUGIN_TMP_FILE" "$DOWNLOAD_URL"
fi
}

# installFile verifies the SHA256 for the file, then unpacks and
# installs it.
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"
}

# fail_trap is executed if an error occurs.
fail_trap() {
result=$?
if [ "$result" != "0" ]; then
echo "Failed to install $PROJECT_NAME"
echo "\tFor support, go to https://github.com/${PROJECT_GH}."
fi
exit $result
}

# testVersion tests the installed client to make sure it is working.
testVersion() {
set +e
echo "$PROJECT_NAME installed into $HELM_PLUGIN_PATH/$PROJECT_BIN_NAME"
$HELM_PLUGIN_PATH/$PROJECT_BIN_NAME -h
set -e
}

# Execution

#Stop execution on any error
trap "fail_trap" EXIT
set -e
initArch
initOS
verifySupported
getDownloadURL
downloadFile
installFile
testVersion
Loading

0 comments on commit b162f46

Please sign in to comment.