One option would be to package your helm chart in the pipeline and then deploy the correctly versioned helm package in another job. This will allow you to also manage the versions that you release in a registry or repository.
First, package the helm chart with the correct --version
and --app-version
. You can declare a $nextReleaseVersion
as a variable in the pipeline or use a tool like semantic-release to automate versioning.
I am not sure what stack you are using but below are examples for Github and Gitlab.
Gitlab
In the gitlab pipeline example, helm cm-push is used to package the chart with the correct versions and push it to the Gitlab Package Registry "helm-chart-library":
package_helm:
image:
name: alpine/helm:3.5.3
entrypoint: [""]
before_script:
- apk add git && helm plugin install https://github.com/chartmuseum/helm-push
script:
- helm repo add --username deploy_token --password $DEPLOY_TOKEN helm-chart-library https://gitlab.example.com/api/v4/projects/${CI_PROJECT_ID}/packages/helm/stable
- helm cm-push charts/ --version="$nextReleaseVersion" --app-version="$nextReleaseVersion" helm-chart-library
Next, you will need to pull the helm package with the correct version from the registry and install it in the cluster. Note that when we install the package, we apply --untar
which will unzip the package and create a temporary directory with the Chart's name/release. You will need to apply the correct path of newly versioned helm chart to the helm upgrade
command and can also optionally set the image tag --set image.tag=$nextReleaseVersion
.
deploy_helm:
script:
- helm repo add --username deploy_token --password $DEPLOY_TOKEN helm-chart-library https://gitlab.example.com/api/v4/projects/${CI_PROJECT_ID}/packages/helm/stable
- helm repo update
- helm pull helm-chart-library/${HELM_RELEASE_NAME} --untar --version $nextReleaseVersion
- helm upgrade --install --namespace ${KUBERNETES_NAMESPACE} --values ${HELM_RELEASE_NAME}/${HELM_VALUES_FILE} ${HELM_RELEASE_NAME} ./${HELM_RELEASE_NAME}/
Github
Alternatively, in Github, you can push the chart into a Github Helm Chart Repository. Helm documentation offers an example here - https://helm.sh/docs/topics/chart_repository/#github-pages-example. I have Github Pages disabled and so also experimented pushing the helm packages to a separate branch e.g. "helm-chart-repo"
helm_package:
name: Package and Push Helm Charts to Chart Repository
runs-on: ubuntu-latest
steps:
- name: Checkout Current Branch
uses: actions/checkout@v2
# Check out the branch where you will store the helm packages
- name: Checkout helm-chart-repo Branch
uses: actions/checkout@v3
with:
repository: yourOrg/repositoryName
ref: 'branchName'
token: '${{ secrets.API_TOKEN }}'
# Package your chart with the correct versions, move the package
# into a directory called 'helm-chart-repository' and push to Github
- name: Helm Package and Push to Github Repository
env:
VERSION: ${{ env.nextReleaseVersion}}
run: |
helm package charts/ --version $VERSION --app-version $VERSION
git config --global user.email "your-email@your-org.com"
git config --global user.name "your-username"
mv package-name-$VERSION.tgz helm-chart-repository/package-name-$VERSION.tgz
CHART_PACKAGE_NAME="package-name-$VERSION.tgz"
cd charts/
helm repo index .
cd ../
git add .
git commit -m "$CHART_PACKAGE_NAME [skip ci]"
git push
This may not be the perfect solution but I hope it helps!