How to publish HELM 3 charts to GitHub Container Registry
Tags: github, container, helm
Published: 2021-04-10 16:33:57

---
title: How to publish HELM 3 charts to GitHub Container Registry
published: true
date: 2021-04-09 23:00:00 UTC
tags: github, container, helm
canonical_url: https://www.visualstudiogeeks.com/github/publish-helm-3-charts-to-gcr
---

I have already written how to publish HELM chart to ACR using [Azure DevOps](/devops/helm/deploying-helm-chart-with-azdo) and [GitHub actions](/helm/devops/publish-helm-charts-to-acr-using-github-actions). But did you know you can also publish HELM3 charts (or any OCI compliant package) to [GitHub Container Registry(GCR)](https://github.blog/2020-09-01-introducing-github-container-registry/)? In this post we will see how to do that. 

## Enable improved container support

GitHub Container Registry is currently in public beta. So, the first step is to ensure that you have enabled the GitHub Container Registry for your account. If you have GitHub personal account, you can do that from `Feature Preview` window.

![](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2021/apr/publish-helm-3-charts-to-gcr/improved-container-support.jpg)

If you have a Enterprise account, you can do that going to `Settings` page.

![](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2021/apr/publish-helm-3-charts-to-gcr/improved-container-support-ent.jpg)

GitHub documentation has step-by-step guide of enabling **improved container support** [here](https://docs.github.com/en/packages/guides/enabling-improved-container-support)

## Publishing HELM 3 charts using GitHub Actions

It really takes only couple of steps to do it using GitHub Actions. Like any other action, you start by creating `.github\workflow` folder and create an `yml` file in your repository.

Excluding the `name` and trigger part, first step in the YAML is to define few necessary variables.

```
env:
  HELM_EXPERIMENTAL_OCI: 1 #enable OCI support
  HELM_VERSION_TO_INSTALL: 3.5.0 # version of HEL to install
  GCR_IMAGE: ghcr.io/$/vote-app

```

First variable [enables the OCI support](https://helm.sh/docs/topics/registries/#enabling-oci-support) for the HELM commands we are going to run later in the YAML.

Next variable `HELM_VERSION_TO_INSTALL` is used later in the workflow to install specific version of the HELM. For this workflow, we need `3.5.0`.

Last variable `GCR_IMAGE` is constructing the chart name for the publication.

> The GitHub Container Registry hosts containers at `ghcr.io/OWNER/IMAGE-NAME`. I get the `OWNER` of the repository using `github.repository_owner` from [`github` context](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context).

Next steps are defining the `job` with steps to download the code (where we have HELM chart) and install the specific HELM tool on the runner/agent.

```
jobs:
  build:
    name: publish gcr
    runs-on: ubuntu-latest
    environment: prod
    steps:
      - uses: actions/checkout@v2
        name: checkout repo
      
      - name: install helm
        uses: Azure/setup-helm@v1
        with:
          # Version of helm
          version: ${{ env.HELM_VERSION_TO_INSTALL }} # default is latest

```

The above steps setup the agent machine with the required HELM tool.

Next, we need to run few `helm` commands to login to GCR (GitHub Container Registry) and finally publish the chart.

1. 

We login to GCR using `${{ secrets.GITHUB_TOKEN }}`

> GitHub Container Registry only [recently](https://github.blog/changelog/2021-03-24-packages-container-registry-now-supports-github_token/) started supporting `GITHUB_TOKEN`. Previously you had to create a separate PAT token with specific permissions to GCR.

2. 

Next two steps in the workflow will be to save the chart and publish. We do that using `helm chart save` and `help chart push` commands as shown below.

```
- name: login to acr using helm
  run: |
    echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin

- name: save helm chart to local registry
  run: |
    helm chart save ${{ github.workspace }}/src/azure-vote-helm-chart/ ${{ env.GCR_IMAGE }}:${{ github.sha }}

- name: publish chart to acr
  run: |
    helm chart push ${{ env.GCR_IMAGE }}:${{ github.sha }}

```

That is it, if all worked successfully for you, you should see the chart in the GCR.

![](https://www.visualstudiogeeks.com/images/screenshots/utkarsh/2021/apr/publish-helm-3-charts-to-gcr/published-chart.jpg)