Sachin Bhosale
Sachin Bhosale's Blog

Sachin Bhosale's Blog

How to create public helm chart repository with GitHub Pages

Host helm chart repository on GitHub pages using GitHub Actions

Sachin Bhosale's photo
Sachin Bhosale
·Nov 30, 2021·

4 min read

How to create public helm chart repository with GitHub Pages

Subscribe to my newsletter and never miss my upcoming articles

Table of contents

  • Create 'gh_pages` branch to publish
  • Configure GitHub Repo to publish github_pages
  • Create a personal token
  • Create Repository Secret
  • Create GitHub Action workflow for PullRequest
  • Create Workflow for Helm Chart Release
  • Access Helm Repository

In this article, we host earlier created Helm Chart as helm repository on GitHub Pages. You can visit earlier article on how to create helm chart and add sub-chart dependency.

Let's follow the below steps:

Create 'gh_pages` branch to publish

To publish the helm repository to GitHub pages, create a gh_pages branch in your repo.

# Create new empty branch without parent
git checkout --orphan gh-pages
# remove local files 
git rm -rf . 
# Make empty commit to push
git commit --allow-empty  -m "Initial Commit"
# push branch to origin
git push

Configure GitHub Repo to publish github_pages

To publish the github_pages branch , you need to setup Settings > Pages in your repository and it should show you the URL of hosted pages.

Screen Shot 2021-11-30 at 10.07.18 PM.png

Create a personal token

We need to create personal token to pass to Helm Chart Release workflow. Visit Settings > Developer Settings > Personal Access Token. Generate Personal token with Scopes repo, workflow, write:packages

Keep the token safely and never share with anyone

Screen Shot 2021-11-30 at 10.12.56 PM.png

Create Repository Secret

To provide a token to workflow, you need to visit Settings > Secrets for your repository and add REPO_TOKEN with value of personal token created in previous step.

Screen Shot 2021-11-30 at 10.14.58 PM.png

Also verify that default GITHUB_TOKEN has read and write permission by visiting repository Settings > Actions

Screen Shot 2021-11-30 at 10.25.26 PM.png

Create GitHub Action workflow for PullRequest

helm-pr.yaml workflow will trigger on pull request (PR) and perform below steps:

  • Checkout the code on runner
  • Set up Helm on runner i.e. helm tools
  • Set up Helm Chart Testing tools ct
  • Add required helm chart dependencies
  • List changes for Chart testing - it checks changes compared to base branch in this case main
  • Chart Lint - it examines charts for possible issues and runs series of tests to verify that chart is well-formed
  • Create Kubernetes kind cluster to install the chart
  • Install chart to Kubernetes cluster created in previous step and run the tests in template/tests

If all the checks are successful then PR is good to merge and reviewer can merge the changes.

.github/workflows/helm-pr.yaml

name: Helm PR Workflow

on:
  pull_request:
  workflow_dispatch:

jobs:

  lint-test:
    runs-on: ubuntu-latest
    name: Helm Chart Lint
    env:
      CT_CHART_DIRS: charts
      CT_TARGET_BRANCH: $GITHUB_BASE_REF
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up Helm
        uses: azure/setup-helm@v1

      - uses: actions/setup-python@v2
        with:
          python-version: 3.7

      - name: Set up chart-testing
        uses: helm/chart-testing-action@v2.1.0

      - name: Add Helm Repo dependencies
        run: helm repo add bitnami https://charts.bitnami.com/bitnami

      - name: Run chart-testing (list-changed)
        id: list-changed
        run: |
          changed=$(ct list-changed --target-branch $GITHUB_BASE_REF)
          if [[ -n "$changed" ]]; then
            echo "::set-output name=changed::true"
          fi

      - name: Run chart-testing (lint)
        run: ct lint --target-branch $GITHUB_BASE_REF

      - name: Create kind Kubernetes cluster
        uses: helm/kind-action@v1.2.0
        if: steps.list-changed.outputs.changed == 'true'

      - name: Run chart-testing (install)
        run: ct install --target-branch $GITHUB_BASE_REF

You can check sample Helm PR workflow here

Screen Shot 2021-11-30 at 7.10.01 PM.png

Create Workflow for Helm Chart Release

helm-release.yaml workflow triggers on commit to main branch and performs below steps:

.github/workflows/helm-release.yaml

name: Helm Release Workflow

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  helm-release:
    runs-on: ubuntu-latest
    name: Release Helm Chart
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

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

      - name: Install Helm
        uses: azure/setup-helm@v1

      - name: Add Helm Repo dependencies
        run: helm repo add bitnami https://charts.bitnami.com/bitnami

      - name: Run User chart-releaser
        uses: helm/chart-releaser-action@v1.2.1
        env:
          CR_TOKEN: "${{ secrets.REPO_TOKEN }}"
          CR_SKIP_EXISTING: true
        with:
          charts_dir: charts

You can check sample helm release workflow run here

Screen Shot 2021-11-30 at 7.07.51 PM.png

Access Helm Repository

On successful workflow run, you would get helm repo available on https://sachinb4u.github.io/helm-chart-demos/index.yaml

You can try adding repository to your environment and installing myapp chart

# add helm repository
helm repo add sachin https://sachinb4u.github.io/helm-chart-demos

# search chart
helm search repo sachin

# install chart
helm install demo-app sachin/myapp

I hope you got an overview of Helm Repository using GitHub action to setup CI-CD pipeline.

Thanks for reading! I would appreciate your feedback on the articles, it will motivate me to keep writing.

 
Share this