From 19c95511a4c6a11f67f547b90bd09c53db42f306 Mon Sep 17 00:00:00 2001 From: Charlie Haley Date: Mon, 14 Nov 2022 13:28:09 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20migrate=20to=20centralised=20helm?= =?UTF-8?q?=20repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/chart-testing.yaml | 7 +++ .github/helm-chart-tagger.sh | 28 --------- .github/workflows/deploy.yaml | 53 ----------------- .github/workflows/pr.yaml | 31 ---------- .github/workflows/release.yml | 67 +++++++++++++++++++++ .github/workflows/test.yml | 26 ++++++++ Makefile | 109 ++-------------------------------- README.md | 12 ++-- hack/lint.sh | 12 ++++ hack/test.sh | 3 + lint/chart_schema.yaml | 20 ------- lint/ct.yaml | 6 -- lint/lintconf.yaml | 42 ------------- 13 files changed, 124 insertions(+), 292 deletions(-) create mode 100644 .github/chart-testing.yaml delete mode 100755 .github/helm-chart-tagger.sh delete mode 100644 .github/workflows/deploy.yaml delete mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 hack/lint.sh create mode 100644 hack/test.sh delete mode 100644 lint/chart_schema.yaml delete mode 100644 lint/ct.yaml delete mode 100644 lint/lintconf.yaml diff --git a/.github/chart-testing.yaml b/.github/chart-testing.yaml new file mode 100644 index 0000000..e2ae364 --- /dev/null +++ b/.github/chart-testing.yaml @@ -0,0 +1,7 @@ +remote: origin +target-branch: master +debug: true +check-version-increment: true +upgrade: true +validate-chart-schema: true +validate-yaml: true diff --git a/.github/helm-chart-tagger.sh b/.github/helm-chart-tagger.sh deleted file mode 100755 index a5a162d..0000000 --- a/.github/helm-chart-tagger.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -e - -HASH=$(git rev-parse HEAD) - -if [ -f "./hub/Chart.yaml" ]; then - VERSION=$(cat ./hub/Chart.yaml | grep "version:" | awk -F " " '{ print "v"$2 }') -else - VERSION=$(cat ./Chart.yaml | grep "version:" | awk -F " " '{ print "v"$2 }') -fi - -if git rev-parse --quiet --verify ${VERSION}; then - echo 'tag exist' - exit 0 -else - echo 'tag not exist' -fi - -echo "${VERSION} ${HASH}" - -# https://docs.github.com/en/rest/reference/git#create-a-reference -curl \ - -X POST \ - -H "authorization: Bearer ${GITHUB_TOKEN}" \ - -H 'content-type: application/json' \ - -H 'Accept: application/vnd.github.v3+json' \ - https://api.github.com/repos/traefik/hub-helm-chart/git/refs \ - -d "{\"ref\":\"refs/tags/${VERSION}\",\"sha\":\"${HASH}\"}" diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index 50a583c..0000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build - -on: - push: - branches: - - master - -jobs: - - build: - name: Build - runs-on: ubuntu-latest - if: github.repository == 'traefik/hub-helm-chart' - - steps: - - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install - run: | - curl -L https://git.io/get_helm.sh | bash -s -- -v v3.5.3 - curl -sSL -o /tmp/ct.tgz https://github.com/helm/chart-testing/releases/download/v3.3.1/chart-testing_3.3.1_linux_amd64.tar.gz - tar xzf /tmp/ct.tgz -C /tmp && sudo cp /tmp/ct /usr/local/bin/ct && command -v ct - make - env: - TMPDIR: /tmp - ARCH: amd64 - - - name: Lint, build and test - run: | - make - - - name: Package - run: | - make package - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@4.1.0 - with: - branch: gh-pages - folder: repo/ - clean: false - - - name: Tag - run: | - ./.github/helm-chart-tagger.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml deleted file mode 100644 index 3a61751..0000000 --- a/.github/workflows/pr.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Build - -on: - pull_request: {} - -jobs: - - build: - name: Build on PR - runs-on: ubuntu-latest - - steps: - - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install - run: | - curl -L https://git.io/get_helm.sh | bash -s -- -v v3.5.3 - curl -sSL -o /tmp/ct.tgz https://github.com/helm/chart-testing/releases/download/v3.3.1/chart-testing_3.3.1_linux_amd64.tar.gz - tar xzf /tmp/ct.tgz -C /tmp && sudo cp /tmp/ct /usr/local/bin/ct && command -v ct - make - env: - TMPDIR: /tmp - ARCH: amd64 - - - name: Lint, build and test - run: | - make diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..76832d5 --- /dev/null +++ b/.github/workflows/release.yml @@ -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' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..10394dc --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/Makefile b/Makefile index 3ccb994..83c51b4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index d753b53..fb15844 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 @@ -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 diff --git a/hack/lint.sh b/hack/lint.sh new file mode 100644 index 0000000..96b4da7 --- /dev/null +++ b/hack/lint.sh @@ -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 diff --git a/hack/test.sh b/hack/test.sh new file mode 100644 index 0000000..d5780ae --- /dev/null +++ b/hack/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +/usr/bin/helm unittest --helm3 --color ./hub-agent; diff --git a/lint/chart_schema.yaml b/lint/chart_schema.yaml deleted file mode 100644 index e750223..0000000 --- a/lint/chart_schema.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: str() -home: str() -version: str() -appVersion: any(str(), num()) -description: str() -keywords: list(str(), required=False) -sources: list(str(), required=False) -maintainers: list(include('maintainer'), required=False) -icon: str(required=False) -engine: str(required=False) -condition: str(required=False) -tags: str(required=False) -deprecated: bool(required=False) -kubeVersion: str(required=False) -annotations: map(str(), str(), required=False) ---- -maintainer: - name: str() - email: str(required=False) - url: str(required=False) diff --git a/lint/ct.yaml b/lint/ct.yaml deleted file mode 100644 index 4431c8b..0000000 --- a/lint/ct.yaml +++ /dev/null @@ -1,6 +0,0 @@ -chart-dirs: - - ./ -remote: hub-agent -target-branch: master -debug: true -check-version-increment: true diff --git a/lint/lintconf.yaml b/lint/lintconf.yaml deleted file mode 100644 index ccbef81..0000000 --- a/lint/lintconf.yaml +++ /dev/null @@ -1,42 +0,0 @@ ---- -rules: - braces: - min-spaces-inside: 0 - max-spaces-inside: 0 - min-spaces-inside-empty: -1 - max-spaces-inside-empty: -1 - brackets: - min-spaces-inside: 0 - max-spaces-inside: 0 - min-spaces-inside-empty: -1 - max-spaces-inside-empty: -1 - colons: - max-spaces-before: 0 - max-spaces-after: 1 - commas: - max-spaces-before: 0 - min-spaces-after: 1 - max-spaces-after: 1 - comments: - require-starting-space: true - min-spaces-from-content: 2 - document-end: disable - document-start: disable - empty-lines: - max: 2 - max-start: 0 - max-end: 0 - hyphens: - max-spaces-after: 1 - indentation: - spaces: consistent - indent-sequences: whatever # - list indentation will handle both indentation and without - check-multi-line-strings: false - key-duplicates: enable - line-length: disable # Lines can be any length - new-line-at-end-of-file: enable - new-lines: - type: unix - trailing-spaces: enable - truthy: - level: warning