Sub topic 10
Automating publishing in CI
This chapter assumes you can package a chart, run helm registry login, and push with helm push. It also assumes you know that the chart version becomes the OCI tag. Here you move those manual steps into a pipeline that publishes on every release tag.
What the pipeline must do
A publishing job repeats the same steps you ran by hand:
- Check out the source.
- Install Helm.
- Log in to the registry without a prompt.
- Package the chart.
- Push the archive to an
oci://path.
Logging in without a prompt
A CI job has no terminal, so it cannot type a password. Pass the password on standard input and add --password-stdin. This keeps the secret out of the process list and out of shell history.
echo "$REGISTRY_TOKEN" | helm registry login registry.example.com --username ci-bot --password-stdinUse a token with the narrowest scope that allows pushing. Store it in the CI system's secret store. Never write it into the repository.
A GitHub Actions workflow
This workflow runs when you push a tag that starts with v. It logs in to GitHub Container Registry (GHCR) with the built-in GITHUB_TOKEN, then packages and pushes the chart.
name: publish-chart
on:
push:
tags: ['v*']
permissions:
contents: read
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/setup-helm@v4
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io --username "${{ github.actor }}" --password-stdin
- name: Package and push
run: |
helm package charts/myapp --destination dist
helm push dist/*.tgz oci://ghcr.io/my-org/chartsPoints to notice:
permissionsgrants onlypackages: writeand read access to contents. The job gets nothing else.helm package ... --destination distwrites the archive to a known folder, so the globdist/*.tgzmatches exactly one file.helm pushappends the chart name to the path and uses the chart version as the tag. The result isghcr.io/my-org/charts/myapp:<version>.- GHCR requires a lowercase organization name in the path.
My-Orgfails,my-orgworks.
Keeping the Git tag and chart version in sync
The two values can drift apart. A common fix is to make the pipeline set the version from the Git tag. helm package accepts --version and --app-version flags that override the values in Chart.yaml for that archive.
VERSION="${GITHUB_REF_NAME#v}"
helm package charts/myapp --version "$VERSION" --app-version "$VERSION" --destination distHere GITHUB_REF_NAME holds the tag name, such as v1.2.0. The #v expansion strips the leading v, because chart versions are semantic versions and have no prefix. Note that the file in your repository is unchanged. Only the packaged archive carries the new version.
Common mistakes
| Symptom | Likely cause |
|---|---|
| `unauthorized` on push | The token lacks write scope, or `packages: write` is missing from `permissions`. |
| Login succeeds but push fails with a name error | Uppercase letters in the registry path. |
| Push overwrites an existing release | The chart version was not bumped. |
| `dist/*.tgz` matches several files | An old archive remains in `dist`. Use a clean workspace. |
Exercise
Your workflow runs on tag v2.0.1 but the chart in the registry has the tag 0.1.0. Why does this happen, and how can you fix it?
Show answer
The OCI tag comes from version in Chart.yaml, not from the Git tag. Either bump version before tagging, or run helm package with --version set from the Git tag (for example, --version "${GITHUB_REF_NAME#v}").