GitHub: automated publish of Helm chart using GitHub Actions

Github Actions provide the ability to define a build workflow, including the packaging and publishing of a Helm chart.

This allows tools like Helm to refer to the URL of the public source project, add it as a remote Helm repository, and then use the packaged chart to deploy a workload to a Kubernetes cluster.

Helm Chart published via GitHub Pages

As explained in the Helm documentation, publishing a Helm chart only requires an “index.yaml” file be publicly exposed, which details the versions and archived charts (tgz) available within the Helm repository.

Exposing an “index.yaml” at a public URL is most easily done using GitHub Pages, where any files put on the “gh-pages” git branch are reachable at a public URL with the following syntax:

https://${USER|ORG}.github.io/${PROJECT}

To support GitHub Pages, we first need to create a empty branch named “gh-pages” in our source repository.

# create new empty 'gh-pages' branch with no history
git switch --orphan gh-pages
# directory should be completely empty now
ls -latr

# add minimal content to new branch
echo "placeholder for github pages branch" > README.md
git add README.md 
git commit -am "empty 'gh-pages' branch"
git push -u origin gh-pages

# go back to original branch
git checkout main

GitHub Action for publishing Helm chart

I will build on a previous article where I have a GitHub action building and publishing a Docker (OCI) image, and now add a job that publishes a Helm chart.

Add the job definition below to the .github/workflows/github-actions-buildOCI.yml action definition:

  helm-package-and-publish-to-github:
    runs-on: ubuntu-22.04

    permissions:
      contents: write
      packages: write

    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

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

      # creates helm tgz archive as GitHub Release, and index.yaml on 'gh-pages' branch
      - name: Run chart-releaser
        uses: helm/chart-releaser-action@v1.7.0
        with:
          charts_dir: charts
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

The chart-releaser-action action takes care of:

  • Packaging the Helm chart into a tgz
  • Uploading the tgz to GitHub Releases, where it is available at a public URL
  • Generating an index.yaml on the ‘gh-pages’ branch, where it is available via GitLab Pages

Validate Helm chart published artifacts

There are two artifacts created after this Action is run:

  • The Helm chart index file (index.yaml) is pushed to the ‘gh-pages’ branch of the repo
  • The Helm chart archive (tgz) is pushed as a GitHub Release

Helm Chart repository index

On the GitHub project’s “gh-pages” branch,  you will now find an “index.yaml” file.  This is the Helm Chart repository index file.


As mentioned earlier, the GitHub Pages URL syntax is:

https://${USER|ORG}.github.io/${PROJECT}

Which means our index.yaml for this project is: https://fabianlee.github.io/google-hello-app-logging-multiarch/index.yaml

The ‘entries[].$CHART.version” above was pulled from “charts/$CHART/Chart.yaml” when packaging.

Helm Chart archive as GitHub Release

In the GitHub project’s Release section, there will now be a release created with the packaged Helm chart tgz.


GitHub Releases are available via public URL, and the URL to this tgz is embedded in index.yaml at ‘entries[].$CHART.urls’, so that specific charts can be pulled by the Helm client.

Validate public Helm chart access

Using this public Helm repository URL, we can now use a Helm client to add the chart repository locally.

# add helm repo from public gitlab URL, reads index.yaml
helm repo add github-hello https://fabianlee.github.io/google-hello-app-logging-multiarch

$ helm repo list
NAME                              	URL                                                             
github-hello                      	https://fabianlee.github.io/google-hello-app-logging-multiarch

# show charts available in repo
$ helm search repo -l github-hello
NAME                                              	CHART VERSION	APP VERSION	DESCRIPTION                
github-hello/google-hello-app-logging-multiarch	0.0.3        	1.0.34     	A Helm chart for Kubernetes
github-hello/google-hello-app-logging-multiarch	0.0.1        	0.1.0      	A Helm chart for Kubernetes

# test helm chart (no kubernetes connection required)
$ helm template my-github-test github-hello/google-hello-app-logging-multiarch

 

REFERENCES

helm docs, using github chart-releaser

github, chart-releaser-action

github discussion, curl for github image list

stackoverflow, querying github API for packages using curl

github plugin, chart-releaser

Helm docs, chart structure with index.yaml explanation

Helm docs, GitHub Pages example repository explained

github, example project source for this article, source

github, example project for this article, packages

github, example project for this article, releases

GitHub Pages docs