Skip to content

Commit 1003c13

Browse files
vdice0xE282B0
authored andcommitted
ci(*): update helm chart releasing
- Update the helm-chart-release.yml workflow to publish to the ghcr.io registry - Add related helm packaging targets to the Makefile - Add the deploy/update-chart-versions.sh helper script - Misc. Chart.yaml and README.md updates Signed-off-by: Vaughn Dice <[email protected]>
1 parent fd08113 commit 1003c13

File tree

6 files changed

+139
-29
lines changed

6 files changed

+139
-29
lines changed
+55-27
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,75 @@
11
# This action releases the runtime-class-manager helm chart
2-
# The action must run on each commit done against main, however
3-
# a new release will be performed **only** when a change occurs inside
4-
# of the `charts` directory.
2+
#
3+
# A chart is published to the configured OCI registry on every push to main
4+
# as well as on semver tag releases (via workflow_call from release.yml).
55
name: Release helm chart
66

7-
permissions:
8-
contents: read
9-
107
on:
118
push:
129
branches:
1310
- main
11+
workflow_call:
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
CHART_NAME: runtime-class-manager
1420

1521
jobs:
1622
release:
17-
runs-on: ubuntu-latest
18-
19-
permissions:
20-
id-token: write
21-
packages: write
22-
contents: write
23+
name: Release chart
24+
runs-on: ubuntu-22.04
2325

2426
steps:
25-
- name: Checkout
26-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
27+
- uses: actions/checkout@v4
28+
29+
- name: Install helm
30+
uses: Azure/setup-helm@v4
2731
with:
28-
fetch-depth: 0
32+
version: v3.16.3
2933

30-
- name: Configure Git
34+
- name: Determine chart version
3135
run: |
32-
git config user.name "$GITHUB_ACTOR"
33-
git config user.email "[email protected]"
36+
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]]; then
37+
# NOTE: We remove the leading 'v' to comply with helm's versioning requirements
38+
echo "CHART_VERSION=$(echo -n ${{ github.ref_name }} | sed -rn 's/(v)?(.*)/\2/p')" >> $GITHUB_ENV
39+
echo "APP_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
40+
else
41+
# NOTE: We can replace 0.0.0 with e.g. $(git describe --tags $(git rev-list --tags --max-count=1)) once we have a first tag
42+
# However, we'll also need to update the checkout step with 'fetch-depth: 0' if we list tags
43+
echo "CHART_VERSION=0.0.0-$(date +%Y%m%d-%H%M%S)-g$(git rev-parse --short HEAD)" >> $GITHUB_ENV
44+
# Setting to 'latest' to match tag used in container-image.yml
45+
echo "APP_VERSION=latest" >> $GITHUB_ENV
46+
fi
3447
35-
- name: Install Helm
36-
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
48+
- name: Log into registry ${{ env.REGISTRY }}
49+
uses: docker/login-action@v3
3750
with:
38-
version: v3.14.0
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Package chart
56+
run: make helm-package
57+
58+
- name: Lint packaged chart
59+
run: make helm-lint
3960

40-
- name: Run chart-releaser
41-
if: github.ref == 'refs/heads/main'
42-
uses: helm/chart-releaser-action@a917fd15b20e8b64b94d9158ad54cd6345335584 # v1.6.0
61+
- name: Upload chart as GitHub artifact
62+
uses: actions/upload-artifact@v4
4363
with:
44-
charts_dir: deploy/helm
64+
name: ${{ env.CHART_NAME }}
65+
path: _dist/${{ env.CHART_NAME }}-${{ env.CHART_VERSION }}.tgz
66+
67+
- name: Publish chart
4568
env:
46-
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
47-
CR_RELEASE_NAME_TEMPLATE: "{{ .Name }}-chart-{{ .Version }}"
69+
CHART_REGISTRY: ${{ env.REGISTRY }}/${{ github.repository_owner }}/charts
70+
run: |
71+
make helm-publish
72+
73+
echo '### Helm chart published:' >> $GITHUB_STEP_SUMMARY
74+
echo '- `Reference: ${{ env.CHART_REGISTRY }}/${{ env.CHART_NAME }}`' >> $GITHUB_STEP_SUMMARY
75+
echo '- `Version: ${{ env.CHART_VERSION }}`' >> $GITHUB_STEP_SUMMARY

.github/workflows/release.yml

+22
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@ jobs:
3131
packages: write
3232
contents: read
3333

34+
publish-chart:
35+
name: Publish the helm chart to the configured OCI registry
36+
uses: ./.github/workflows/helm-chart-release.yml
37+
permissions:
38+
packages: write
39+
contents: read
40+
needs:
41+
- ci
42+
- build-manager
43+
- build-installer
44+
3445
release:
3546
name: Create release
3647

3748
needs:
3849
- ci
3950
- build-manager
4051
- build-installer
52+
- publish-chart
4153

4254
permissions:
4355
contents: write
@@ -90,6 +102,12 @@ jobs:
90102
path: ./
91103
merge-multiple: true
92104

105+
- name: Download helm chart artifact
106+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
107+
with:
108+
name: runtime-class-manager
109+
path: ./
110+
93111
- name: Display structure of downloaded files
94112
run: ls -R
95113

@@ -101,6 +119,9 @@ jobs:
101119
let fs = require('fs');
102120
let path = require('path');
103121
122+
// The chart version omits the leading 'v' to adhere to Helm's versioning requirements
123+
let chartVersion = "${{ env.TAG_NAME }}".replace("v", "");
124+
104125
let files = [
105126
'runtime-class-manager-sbom-amd64.spdx',
106127
'runtime-class-manager-sbom-amd64.spdx.cert',
@@ -114,6 +135,7 @@ jobs:
114135
'node-installer-sbom-arm64.spdx',
115136
'node-installer-sbom-arm64.spdx.cert',
116137
'node-installer-sbom-arm64.spdx.sig',
138+
`runtime-class-manager-${chartVersion}.tgz`,
117139
]
118140
const {RELEASE_ID} = process.env
119141

Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,39 @@ kind-delete:
206206

207207
.PHONY: kind
208208
kind: create-kind-cluster install
209+
210+
##@ Helm chart distribution
211+
212+
HELM ?= helm
213+
CHART_NAME := runtime-class-manager
214+
CHART_REGISTRY ?= ghcr.io/spinkube/charts
215+
# We can update 0.0.0 to the most recent tag once we have a first git tag.
216+
# Note that the leading 'v' must be dropped per Helm's versioning requirements
217+
# e.g. $(shell git describe --tags --abbrev=0 | sed -rn 's/(v)?(.*)/\2/p')
218+
CHART_VERSION ?= 0.0.0-$(VERSION)
219+
APP_VERSION ?= $(VERSION)
220+
STAGING_DIR ?= _dist
221+
222+
.PHONY: helm-package
223+
helm-package: $(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz
224+
225+
$(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION):
226+
mkdir -p $(STAGING_DIR)
227+
cp -r deploy/helm $(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION)
228+
229+
$(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz: $(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION)
230+
CHART_NAME=$(CHART_NAME) CHART_VERSION=$(CHART_VERSION) APP_VERSION=$(APP_VERSION) STAGING_DIR=$(STAGING_DIR) ./deploy/update-chart-versions.sh
231+
$(HELM) package \
232+
--version $(CHART_VERSION) \
233+
--destination $(STAGING_DIR) \
234+
$(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION)
235+
236+
.PHONY: helm-publish
237+
helm-publish: helm-package
238+
$(HELM) push \
239+
$(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz \
240+
oci://$(CHART_REGISTRY)
241+
242+
.PHONY: helm-lint
243+
helm-lint: helm-package
244+
$(HELM) lint $(STAGING_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz

deploy/helm/Chart.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
# NOTE: this version is kept static in version control but is bumped when packaging and releasing
1819
version: 0.1.0
1920

2021
# This is the version number of the application being deployed. This version number should be
2122
# incremented each time you make changes to the application. Versions are not expected to
2223
# follow Semantic Versioning. They should reflect the version the application is using.
2324
# It is recommended to use it with quotes.
24-
appVersion: "1.16.0"
25+
# NOTE: this version is kept static in version control but is bumped when packaging and releasing
26+
appVersion: "0.1.0"

deploy/helm/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ With runtime-class-manager running, you're ready to create one or more Wasm Shim
2828
For example, here we install the Spin shim:
2929

3030
```shell
31-
kubectl apply -f ../../config/samples/test_shim_spin.yaml
31+
kubectl apply -f https://raw.githubusercontent.com/spinkube/runtime-class-manager/refs/heads/main/config/samples/test_shim_spin.yaml
3232
```
3333

3434
Now when you annotate one or more nodes with a label corresponding to the `nodeSelector` declared in the Shim, runtime-class-manager will install the shim as well as create the corresponding Runtimeclass:

deploy/update-chart-versions.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -eou pipefail
3+
4+
# Note: using '-i.bak' to support different versions of sed when using in-place editing.
5+
6+
# Swap tag in for main for URLs if the version is vx.x.x*
7+
if [[ "${APP_VERSION}" =~ ^v[0-9]+.[0-9]+.[0-9]+(.*)? ]]; then
8+
sed -i.bak -e "s%spinkube/runtime-class-manager/main%spinkube/runtime-class-manager/${APP_VERSION}%g" "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/README.md"
9+
sed -i.bak -e "s%spinkube/runtime-class-manager/main%spinkube/runtime-class-manager/${APP_VERSION}%g" "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/templates/NOTES.txt"
10+
fi
11+
12+
## Update Chart.yaml with CHART_VERSION and APP_VERSION
13+
yq -i '.version = env(CHART_VERSION)' "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/Chart.yaml"
14+
yq -i '.appVersion = env(APP_VERSION)' "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/Chart.yaml"
15+
16+
## Update values.yaml tags
17+
yq -i '.image.tag = env(APP_VERSION)' "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/values.yaml"
18+
yq -i '.rcm.shimDownloaderImage.tag = env(APP_VERSION)' "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/values.yaml"
19+
yq -i '.rcm.nodeInstallerImage.tag = env(APP_VERSION)' "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}/values.yaml"
20+
21+
# Cleanup
22+
find "${STAGING_DIR}/${CHART_NAME}-${CHART_VERSION}" -type f -name '*.bak' -print0 | xargs -0 rm -- || true

0 commit comments

Comments
 (0)