Skip to content

Commit

Permalink
Initial implementation for Helm v3
Browse files Browse the repository at this point in the history
The implementation is based on the Helm v2 plugin from https://github.com/app-registry/appr-helm-plugin and contains changes so that the plugin works with Helm v3
  • Loading branch information
Grueneberg, Oliver (415) committed Mar 12, 2020
1 parent ca32cd7 commit 1f25954
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
.vscode
.python-version
.idea
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- Initial implementation for Helm v3
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
PLUGIN_FILES = plugin.yaml LICENSE README.md Changelog.md cnr.ps1 cnr.sh


dist/quay-helmv3-plugin.tar.gz:
mkdir -p dist/quay-helmv3-plugin
cp $(PLUGIN_FILES) dist/quay-helmv3-plugin
cd dist && tar czvf quay-helmv3-plugin.tar.gz quay-helmv3-plugin


all: dist/quay-helmv3-plugin.tar.gz


install: dist/quay-helmv3-plugin.tar.gz
cp dist/quay-helmv3-plugin.tar.gz ~/.local/share/helm/plugins
cd ~/.local/share/helm/plugins && tar xvf quay-helmv3-plugin.tar.gz

clean:
rm -rf dist

.PHONY: clean

dev:
mkdir ~/.local/share/helm/plugins/quay-helmv3-plugin
cp $(PLUGIN_FILES) ~/.local/share/helm/plugins/quay-helmv3-plugin
108 changes: 107 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,107 @@
# appr-helmV3-plugin
# Helm Quay plugin

## Overview

This Helm plugin was created from the [Helm plugin](https://github.com/app-registry/appr-helm-plugin) that was designed to work with `Helm v2`. Due to the fact that `Helm v3` comes with a `helm registry` subcommand the original plugin does not work with `Helm v3`.

## Install the Helm Quay Plugin

First, Install the latest [Helm v3 release](https://github.com/kubernetes/helm#install).

If you are an OSX user, quickstart with brew: `brew install kubernetes-helm`

Next download and install the Quay plugin for Helm.


### Option 1: Install using `helm plugin install`

```shell
# If you are asked for credentials, use your GitHub Enterprise Token as username and leave password blank.
$ helm plugin install https://github.com/app-registry/quay-helmv3-plugin

$ helm quay --help
Quay plugin assets do not exist, download them now !
downloading https://github.com/app-registry/appr/releases/download/v0.7.4/appr-osx-x64 ...
```

### Option 2: Install using `git clone`
```shell
# export $HELM_PLUGINS environment variable
$ eval `helm env`
$ git clone https://github.com/app-registry/quay-helmv3-plugin $HELM_PLUGINS/quay-helmv3-plugin

$ helm quay --help
Quay plugin assets do not exist, download them now !
downloading https://github.com/app-registry/appr/releases/download/v0.7.4/appr-osx-x64 ...
```

### Upgrade

##### Upgrade the appr binary

``` shell
$ helm quay list-plugin-versions
$ helm quay upgrade-plugin VERSION
downloading https://github.com/app-registry/appr/releases/download/v0.7.4/appr-osx-x64 ...
```

##### Upgrade the helm plugin

```
$ eval `helm env`
$ cd $HELM_PLUGINS/quay-helmv3-plugin
$ git pull origin master
$ helm quay upgrade-plugin
downloading https://github.com/app-registry/appr/releases/download/v0.7.4/appr-osx-x64 ...
```

## Example Usage

### Check Quay version

```
helm quay version quay.io
```

Output should be:
```
Api-version: {u'cnr-api': u'0.X.Y'}
Client-version: 0.X.Y
```

### Pull Helm chart from the Quay registry

```
helm quay list quay.io
helm quay pull quay.io/charts/jenkins
```

### Create and push your own chart

First, create an account on https://quay.io or another on-prem Quay environment and login to the CLI using the username and password

Set an environment for the username created at Quay to use through the rest of these instructions.

```
export USERNAME=philips
```

Login to Quay with the Helm quay plugin:

```
helm quay login -u $USERNAME quay.io
```

Create a new Helm chart, the default will create a sample application:

```
helm create my-first-chart
```

Push this new chart to Quay.

```
cd my-first-chart
helm quay push quay.io/$USERNAME
```
56 changes: 56 additions & 0 deletions cnr.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
$global_args=$args

if(!(Test-Path $Env:HELM_PLUGIN_DIR)){
$Env:HELM_PLUGIN_DIR="$Env:HELM_PLUGINS/quay-helmv3-plugin"
}


function List_Plugin_Versions() {
$Params = @{
uri = "https://api.github.com/repos/app-registry/appr/tags"
}
if ($Env:HTTPS_PROXY) {
$Params.add('Proxy', $Env:HTTPS_PROXY)
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
return Invoke-WebRequest @Params | ConvertFrom-Json

}

function Latest() {
$latest = List_Plugin_Versions
return $latest[0].name
}

function Download_Appr() {
$version = Latest
# 2 global_args means e.g.:
# helm quay upgrade-plugin v0.7.2
# then v0.7.2 is used as version, if not latest
if ($global_args.Count -eq 2) {
$version = $global_args[1]
}
$Params = @{}
$Params.add('outFile', "$Env:HELM_PLUGIN_DIR/appr.exe")
$Params.add('uri', "https://github.com/app-registry/appr/releases/download/$version/appr-win-x64.exe")
if ($Env:HTTPS_PROXY) {
$Params.add('Proxy', $Env:HTTPS_PROXY)
}
Invoke-WebRequest @Params

}

function Download_Or_Noop() {
if (!( Test-Path $Env:HELM_PLUGIN_DIR/appr.exe)) {
Write-Host "Quay plugin assets do not exist, download them now !"
Download_Appr
}
}

Download_Or_Noop

switch ($args[0]) {
"upgrade-plugin" { Download_Appr }
"list-plugin-versions" { List_Plugin_Versions }
default { Invoke-Expression "$Env:HELM_PLUGIN_DIR/appr.exe helm $args"}
}
63 changes: 63 additions & 0 deletions cnr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#set -e

function list_plugin_versions {
if [ -x "$(command -v curl)" ]; then
local GET="curl -s"
else
local GET="wget -q -O -"
fi
$GET https://api.github.com/repos/app-registry/appr/tags |grep name | cut -d'"' -f 4
};

function latest {
list_plugin_versions | head -n 1
}

function download_appr {
local version=$(latest)
if [ $# -eq 1 ]; then
version=$1
fi
local PLATFORM="linux"

if [ -e /etc/alpine-release ]; then
PLATFORM="alpine"
fi

if [ "$(uname)" = "Darwin" ]; then
PLATFORM="osx"
fi

local URL="https://github.com/app-registry/appr/releases/download/$version/appr-$PLATFORM-x64"
echo "downloading $URL ..."
if [ -x "$(command -v curl)" ]; then
curl -s -L $URL -o $HELM_PLUGIN_DIR/appr
else
wget -q -O $HELM_PLUGIN_DIR/appr $URL
fi
chmod +x "$HELM_PLUGIN_DIR/appr"
}

function download_or_noop {
if [ ! -e "$HELM_PLUGIN_DIR/appr" ]; then
echo "Quay plugin assets do not exist, download them now !"
download_appr $1
fi
}

[ -z "$HELM_PLUGIN_DIR" ] && HELM_PLUGIN_DIR="$HELM_PLUGINS/quay-helmv3-plugin"
LATEST=$(latest)
download_or_noop $LATEST

case "$1" in
upgrade-plugin)
download_appr "${@:2}"
;;
list-plugin-versions)
list_plugin_versions
;;
*)
$HELM_PLUGIN_DIR/appr helm $@
;;
esac
18 changes: 18 additions & 0 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "quay"
version: "0.1.0"
usage: "app-registry client to Helm"
description: |-
This plugin provides Quay client to Helm v3.
usage:
$ helm quay login -u <username> quay.io
$ helm quay pull quay.io/charts/jenkins
$ helm quay push quay.io/<namespace>
ignoreFlags: false
useTunnel: false
platformCommand:
- os: darwin
command: "$HELM_PLUGIN_DIR/cnr.sh"
- os: linux
command: "$HELM_PLUGIN_DIR/cnr.sh"
- os: windows
command: "powershell $HELM_PLUGIN_DIR/cnr.ps1"

0 comments on commit 1f25954

Please sign in to comment.