Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
✨ migrate to centralised helm repository
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-haley authored Nov 14, 2022
1 parent 25f9ade commit 19c9551
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 292 deletions.
7 changes: 7 additions & 0 deletions .github/chart-testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
remote: origin
target-branch: master
debug: true
check-version-increment: true
upgrade: true
validate-chart-schema: true
validate-yaml: true
28 changes: 0 additions & 28 deletions .github/helm-chart-tagger.sh

This file was deleted.

53 changes: 0 additions & 53 deletions .github/workflows/deploy.yaml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/pr.yaml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Release Charts

on:
push:
branches:
- master

jobs:
test:
uses: "traefik/hub-helm-chart/.github/workflows/test.yml@master"
release:
needs: test
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git config --global --add safe.directory /charts
- name: Get chart verison
id: chart_version
run: |
echo "CHART_VERSION=$(cat hub-agent/Chart.yaml | awk -F"[ ',]+" '/version:/{print $2}')" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: tag_exists
run: |
TAG_EXISTS=true
if ! [ $(git tag -l "${{ steps.chart_version.outputs.CHART_VERSION }}") ]; then
TAG_EXISTS=false
fi
echo TAG_EXISTS=$TAG_EXISTS >> $GITHUB_OUTPUT
- name: Tag release
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ steps.chart_version.outputs.CHART_VERSION }}
if: steps.tag_exists.outputs.TAG_EXISTS == 'false'

- name: Create release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
if: steps.tag_exists.outputs.TAG_EXISTS == 'false'

- name: Publish Helm chart
uses: stefanprodan/helm-gh-pages@master
with:
token: ${{ secrets.CHARTS_TOKEN }}
charts_dir: .
charts_url: https://traefik.github.io/charts
owner: traefik
repository: charts
branch: master
target_dir: hub-agent
index_dir: .
commit_username: traefiker
commit_email: 30906710+traefiker@users.noreply.github.com
if: steps.tag_exists.outputs.TAG_EXISTS == 'false'
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Test

on:
workflow_call:
workflow_dispatch:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Lint
run: make lint

- name: Test
run: make test
109 changes: 5 additions & 104 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,106 +1,7 @@
DIST_DIR ?= $(CURDIR)/dist
CHART_DIR ?= $(CURDIR)/hub-agent
TMPDIR ?= /tmp
HELM_REPO ?= $(CURDIR)/repo
LINT_USE_DOCKER ?= true
LINT_CMD ?= ct lint --config=lint/ct.yaml
PROJECT ?= traefik/hub-helm-chart
VERSION ?= $(shell cat hub-agent/Chart.yaml | grep 'version: ' | awk '{ print $$2 }')
.PHONY: lint test

################################## Functionnal targets
test:
docker run ${DOCKER_ARGS} --entrypoint /bin/sh --rm -v $(CURDIR):/charts -w /charts quintush/helm-unittest:3.10.0-0.2.9 /charts/hack/test.sh

all: clean test build

test: lint unit-test

# Execute Static Testing
lint: lint-requirements
@echo "== Linting Chart..."
@git remote add hub-agent https://github.com/traefik/hub-helm-chart >/dev/null 2>&1 || true
@git fetch hub-agent master >/dev/null 2>&1 || true
ifeq ($(LINT_USE_DOCKER),true)
@docker run --rm -t -v $(CURDIR):/charts -w /charts quay.io/helmpack/chart-testing:v3.3.1 $(LINT_CMD)
else
cd $(CHART_DIR)/tests && $(LINT_CMD)
endif
@echo "== Linting Finished"

# Execute Units Tests
unit-test: helm-unittest
@echo "== Unit Testing Chart..."
@helm unittest --helm3 --color --update-snapshot ./hub-agent
@echo "== Unit Tests Finished..."

build: global-requirements $(DIST_DIR)
@echo "== Building Chart..."
@helm package $(CHART_DIR) --destination=$(DIST_DIR)
@echo "== Building Finished"

# Prepare the Helm repository with the latest packaged charts
package: global-requirements $(DIST_DIR) $(HELM_REPO) build full-yaml
@echo "== Deploying Chart..."
@rm -rf $(CURDIR)/gh-pages.zip
@curl -sSL -o gh-pages.zip -H "Authorization: Bearer $(GITHUB_TOKEN)" https://api.github.com/repos/$(PROJECT)/zipball/gh-pages
@unzip -oj $(CURDIR)/gh-pages.zip -d $(HELM_REPO)/
@cp $(DIST_DIR)/*tgz $(HELM_REPO)/
@cp $(CURDIR)/README.md $(HELM_REPO)/index.md
@cp -r $(DIST_DIR)/yaml $(HELM_REPO)/
@helm repo index --merge $(HELM_REPO)/index.yaml --url https://helm.traefik.io/hub/ $(HELM_REPO)
@echo "== Deploying Finished"

# Cleanup leftovers and distribution dir
clean:
@echo "== Cleaning..."
@rm -rf $(DIST_DIR)
@rm -rf $(HELM_REPO)
@echo "== Cleaning Finished"

# Generate full yaml
full-yaml:
@echo "== Generating full yaml for $(VERSION)"
@helm template hub-agent hub-agent > $(DIST_DIR)/yaml/$(VERSION).yaml

install: global-requirements $(DIST_DIR)
@helm install hub-agent $(CHART_DIR)

uninstall: global-requirements $(DIST_DIR)
@helm uninstall hub-agent $(CHART_DIR)
clean

global-requirements:
@echo "== Checking global requirements..."
ifeq ($(LINT_USE_DOCKER),true)
@command -v docker >/dev/null || ( echo "ERROR: Docker binary not found. Exiting." && exit 1)
@docker info >/dev/null || ( echo "ERROR: command "docker info" is in error. Exiting." && exit 1)
else
@command -v helm >/dev/null || ( echo "ERROR: Helm binary not found. Exiting." && exit 1)
@command -v git >/dev/null || ( echo "ERROR: git binary not found. Exiting." && exit 1)
@echo "== Global requirements are met."
endif

lint-requirements: global-requirements
@echo "== Checking requirements for linting..."
ifeq ($(LINT_USE_DOCKER),true)
@command -v docker >/dev/null || ( echo "ERROR: Docker binary not found. Exiting." && exit 1)
@docker info >/dev/null || ( echo "ERROR: command "docker info" is in error. Exiting." && exit 1)
else
@command -v ct >/dev/null || ( echo "ERROR: ct binary not found. Exiting." && exit 1)
@command -v yamale >/dev/null || ( echo "ERROR: yamale binary not found. Exiting." && exit 1)
@command -v yamllint >/dev/null || ( echo "ERROR: yamllint binary not found. Exiting." && exit 1)
@command -v kubectl >/dev/null || ( echo "ERROR: kubectl binary not found. Exiting." && exit 1)
endif
@echo "== Requirements for linting are met."

################################## Technical targets
$(DIST_DIR):
@mkdir -p $(DIST_DIR)/yaml

$(HELM_REPO):
@mkdir -p $(HELM_REPO)

helm-unittest: global-requirements
@echo "== Checking that plugin helm-unittest is available..."
@helm plugin list 2>/dev/null | grep unittest >/dev/null || helm plugin install https://github.com/quintush/helm-unittest --version v0.2.7 --debug
@echo "== plugin helm-unittest is ready"

.PHONY: all global-requirements lint-requirements helm-unittest lint build package clean full-yaml
lint:
docker run ${DOCKER_ARGS} --env GIT_SAFE_DIR="true" --entrypoint /bin/sh --rm -v $(CURDIR):/charts -w /charts quay.io/helmpack/chart-testing:v3.7.1 /charts/hack/lint.sh
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ With the command `helm version`, make sure that you have:
Add Hub's chart repository to Helm:

```bash
helm repo add traefik-hub https://helm.traefik.io/hub
helm repo add traefik https://traefik.github.io/charts
```

You can update the chart repository by running:
Expand All @@ -27,7 +27,7 @@ helm repo update
### Deploying Hub

```bash
helm install hub-agent traefik-hub/hub-agent
helm install hub-agent traefik/hub-agent
```

### Deploying Hub with a full-yaml
Expand All @@ -49,17 +49,13 @@ kubectl create namespace hub
- Then launch the installation with the imperative argument --namespace:

```bash
helm install hub-agent traefik-hub/hub-agent --namespace hub
helm install hub-agent traefik/hub-agent --namespace hub
```

### Launch unit tests

You need the helm-plugin: https://github.com/rancher/helm-unittest

Then:

```bash
helm unittest hub-agent/
make test
```

### Uninstall
Expand Down
12 changes: 12 additions & 0 deletions hack/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

CT_ARGS=""
GIT_SAFE_DIR="false"

if [ "$GIT_SAFE_DIR" != "true" ]; then
git config --global --add safe.directory /charts
fi

CT_ARGS="--charts ${PWD}/charts"

ct lint --config=./.github/chart-testing.yaml
3 changes: 3 additions & 0 deletions hack/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/usr/bin/helm unittest --helm3 --color ./hub-agent;
Loading

0 comments on commit 19c9551

Please sign in to comment.