Skip to content

Commit

Permalink
ci: publish helm chart to GitHub pages via GH action
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jun 26, 2024
1 parent ecd8427 commit 8910d1b
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 14 deletions.
33 changes: 27 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ jobs:
run: |
make test
# Builds all container images. For pushes to PRs/branches, we simply verify that the image build still works, the
# resulting image will not be pushed to any target registry. For pushes to the main branch, the images are tagged with
# "main", but not with a version x.y.z. Finally, for pushes to a tag (or when a tag is created), the images are tagged
# with the version indicated by the tag respectively, and also with latest. That is: Creating a GitHub release (or
# creating a git tag via other means) will trigger building images tagged with x.y.z meant for production use.
build-images:
# Builds and potentially pushes all container images. For pushes to PRs/branches, we simply verify that the image
# build still works, the resulting image will not be pushed to any target registry. For pushes to the main branch, the
# images are tagged with "main-dev", but not with a version x.y.z. Finally, for pushes to a tag (or when a tag is
# created), the images are tagged with the version indicated by the tag respectively, and also with latest. That is:
# Creating a GitHub release (or creating a git tag via other means) will trigger building images tagged with x.y.z
# meant for production use.
build-and-push-images:
name: Build Images
runs-on: ubuntu-latest
needs:
Expand Down Expand Up @@ -134,3 +135,23 @@ jobs:
imageTitle: Dash0 Kubernetes Operator Controller
imageDescription: the controller for the Dash0 Kubernetes operator
context: .

publish-helm-chart:
name: Publish Helm Chart
runs-on: ubuntu-latest
if: ${{ contains(github.ref, 'refs/tags/') }}
needs:
- build-and-push-images
concurrency:
group: ci-concurrency-group-${{ github.ref }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v4

- name: publish helm chart
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "publishing helm chart version ${{ github.ref_name }}"
helm-chart/bin/publish.sh ${{ github.ref_name }}
48 changes: 48 additions & 0 deletions helm-chart/bin/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: Copyright 2024 Dash0 Inc.
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

cd "$(dirname ${BASH_SOURCE})"/..

# Abort when there are local changes in the repository. This is mostly relevant for testing the script locally.
if ! git diff --quiet --exit-code; then
echo "error: The repository has local changes, aborting."
git --no-pager diff
exit 1
fi

version=${1:-}

if [[ -z $version ]]; then
echo "Mandatory parameter version is missing."
echo "Usage: $0 <version>"
exit 1
fi

echo "packaging Helm chart as version $version"
helm package \
dash0-operator \
--version $version \
--app-version $version \
--dependency-update \
--destination ..
echo "packaging Helm version $version has been packaged"

cd ..
echo "switching to gh-pages branch"
git fetch origin gh-pages:gh-pages
git switch gh-pages

# clean up potential left-overs from the --dependency-update flag
rm -rf helm-chart

echo "creating Helm chart index"
helm repo index .

echo "git add, commit & push"
git add "dash0-operator-$version.tgz" index.yaml
git commit -m"feat(chart): publish version $version"
git push --no-verify --set-upstream origin gh-pages
6 changes: 5 additions & 1 deletion helm-chart/dash0-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ helm.sh/chart: {{ include "dash0-operator.chartNameWithVersion" . }}

{{/* the init container image */}}
{{- define "dash0-operator.initContainerImage" -}}
{{- printf "%s:%s" .Values.operator.initContainerImage.repository .Values.operator.initContainerImage.tag }}
{{- printf "%s:%s" .Values.operator.initContainerImage.repository (include "dash0-operator.initContainerImageTag" .) }}
{{- end }}

{{- define "dash0-operator.initContainerImageTag" -}}
{{- default .Chart.AppVersion .Values.operator.initContainerImage.tag }}
{{- end }}

{{- define "dash0-operator.restrictiveContainerSecurityContext" -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ deployment should match snapshot (default values):
- name: DASH0_OTEL_COLLECTOR_BASE_URL
value: http://RELEASE-NAME-opentelemetry-collector.NAMESPACE.svc.cluster.local:4318
- name: DASH0_OPERATOR_IMAGE
value: dash0-operator-controller:1.0.0
value: ghcr.io/dash0hq/operator-controller:1.0.0
- name: DASH0_INIT_CONTAINER_IMAGE
value: ghcr.io/dash0hq/instrumentation:1.0.0
image: dash0-operator-controller:1.0.0
image: ghcr.io/dash0hq/operator-controller:1.0.0
livenessProbe:
httpGet:
path: /healthz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pre-delete hook job should match snapshot:
- command:
- /manager
- --uninstrument-all
image: dash0-operator-controller:1.0.0
image: ghcr.io/dash0hq/operator-controller:1.0.0
imagePullPolicy: null
name: pre-delete-job
resources:
Expand Down
21 changes: 21 additions & 0 deletions helm-chart/dash0-operator/tests/operator/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ tests:
asserts:
- matchSnapshot: {}

- it: image tags should default to appVersion
chart:
version: 4.5.6
appVersion: 99.100.101
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/dash0hq/operator-controller:99.100.101
- equal:
path: spec.template.spec.containers[0].env[1].name
value: DASH0_OPERATOR_IMAGE
- equal:
path: spec.template.spec.containers[0].env[1].value
value: ghcr.io/dash0hq/operator-controller:99.100.101
- equal:
path: spec.template.spec.containers[0].env[2].name
value: DASH0_INIT_CONTAINER_IMAGE
- equal:
path: spec.template.spec.containers[0].env[2].value
value: ghcr.io/dash0hq/instrumentation:99.100.101

- it: should render deployment with custom settings
set:
operator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ templates:
tests:
- it: pre-delete hook job should match snapshot
asserts:
- matchSnapshot: {}
- matchSnapshot: {}

- it: image tag should default to appVersion
chart:
version: 4.5.6
appVersion: 99.100.101
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/dash0hq/operator-controller:99.100.101
6 changes: 3 additions & 3 deletions helm-chart/dash0-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ operator:
image:
# Use a different image entirely. Note that Dash0 does not offer support for Dash0 operator setups that do not use
# Dash0's official image.
repository: "dash0-operator-controller"
repository: "ghcr.io/dash0hq/operator-controller"
# overrides the image tag, which defaults to the chart appVersion.
tag:
# override the default image pull policy
Expand All @@ -86,8 +86,8 @@ operator:
# Use a different image for the init container entirely. Note that Dash0 does not offer support for Dash0 operator
# setups that do not use Dash0's official init container image.
repository: "ghcr.io/dash0hq/instrumentation"
# overrides the image tag for the init container image
tag: "1.0.0"
# overrides the image tag, which defaults to the chart appVersion.
tag:
# override the default image pull policy
pullPolicy:

Expand Down

0 comments on commit 8910d1b

Please sign in to comment.