Skip to content

Commit

Permalink
Helm chart release automation
Browse files Browse the repository at this point in the history
push helm chart as oci image to ghcr on release (tag)

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Sep 1, 2024
1 parent a39ee65 commit 3bd4809
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/chart-push-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Push helm chart on release"

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}

on:
push:
tags:
- v*
jobs:
package-and-push-helm-chart:
runs-on: ubuntu-22.04
steps:
- name: install helm
uses: azure/[email protected]
with:
version: latest

- name: Check out the repo
uses: actions/checkout@v4

- name: update chart
env:
GITHUB_TAG: ${{ github.ref_name }}
GITHUB_REPO_OWNER: ${{ github.repository_owner }}
run: make chart-prepare-release

- name: push chart
env:
GITHUB_TAG: ${{ github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO_OWNER: ${{ github.repository_owner }}
run: make chart-push-release
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ catalog-build: opm ## Build a catalog image.
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

.PHONY: chart-prepare-release
chart-prepare-release: | $(YQ) ; ## prepare helm chart for release
@GITHUB_TAG=$(GITHUB_TAG) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-update.sh

.PHONY: chart-push-release
chart-push-release: | $(HELM) ## push release helm chart
@GITHUB_TAG=$(GITHUB_TAG) GITHUB_TOKEN=$(GITHUB_TOKEN) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-push.sh

##@ Binary Dependencies download

MOCKERY ?= $(LOCALBIN)/mockery
Expand Down Expand Up @@ -378,6 +386,13 @@ $(HELM): | $(LOCALBIN)
rm -f $(LOCALBIN)/get_helm.sh; \
}

YQ := $(abspath $(LOCALBIN)/yq)
YQ_VERSION=v4.44.1
.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary.
$(YQ): | $(LOCALBIN)
@curl -fsSL -o $(YQ) https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_linux_amd64 && chmod +x $(YQ)

##@ Dev

TEST_CLUSTER_NAME = mn-op
Expand Down
34 changes: 34 additions & 0 deletions hack/release/chart-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -ex

# github repo owner: e.g mellanox
GITHUB_REPO_OWNER=${GITHUB_REPO_OWNER:-}
# github api token with package:write permissions
GITHUB_TOKEN=${GITHUB_TOKEN:-}
# github tag e.g v1.2.3
GITHUB_TAG=${GITHUB_TAG:-}

BASE=${PWD}
HELM_CMD="${BASE}/bin/helm"
HELM_CHART=${BASE}/deployment/maintenance-operator-chart
HELM_CHART_VERSION=${GITHUB_TAG#"v"}
HELM_CHART_TARBALL="maintenance-operator-chart-${HELM_CHART_VERSION}.tgz"

if [ -z "$GITHUB_REPO_OWNER" ]; then
echo "ERROR: GITHUB_REPO_OWNER must be provided as env var"
exit 1
fi

if [ -z "$GITHUB_TOKEN" ]; then
echo "ERROR: GITHUB_TOKEN must be provided as env var"
exit 1
fi

if [ -z "$GITHUB_TAG" ]; then
echo "ERROR: GITHUB_TAG must be provided as env var"
exit 1
fi

$HELM_CMD package ${HELM_CHART}
$HELM_CMD registry login ghcr.io -u ${GITHUB_REPO_OWNER} -p ${GITHUB_TOKEN}
$HELM_CMD push ${HELM_CHART_TARBALL} oci://ghcr.io/${GITHUB_REPO_OWNER}
37 changes: 37 additions & 0 deletions hack/release/chart-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -ex

# github tag e.g v1.2.3
GITHUB_TAG=${GITHUB_TAG:-}
# github repo owner e.g mellanox
GITHUB_REPO_OWNER=${GITHUB_REPO_OWNER:-}

BASE=${PWD}
YQ_CMD="${BASE}/bin/yq"
HELM_VALUES=${BASE}/deployment/maintenance-opeator-chart/values.yaml
HELM_CHART=${BASE}/deployment/maintenance-opeator-chart/Chart.yaml


if [ -z "$GITHUB_TAG" ]; then
echo "ERROR: GITHUB_TAG must be provided as env var"
exit 1
fi

if [ -z "$GITHUB_REPO_OWNER" ]; then
echo "ERROR: GITHUB_REPO_OWNER must be provided as env var"
exit 1
fi

# tag provided via env var
OPERATOR_TAG=${GITHUB_TAG}

# patch values.yaml in-place

# maintenance-operator image:
OPERATOR_REPO=${GITHUB_REPO_OWNER} # this is used to allow to release maintenance-operator from forks
$YQ_CMD -i ".operator.image.repository = \"ghcr.io/${OPERATOR_REPO}/maintenance-operator\"" ${HELM_VALUES}
$YQ_CMD -i ".operator.image.tag = \"${OPERATOR_TAG}\"" ${HELM_VALUES}

# patch Chart.yaml in-place
$YQ_CMD -i ".version = \"${OPERATOR_TAG#"v"}\"" ${HELM_CHART}
$YQ_CMD -i ".appVersion = \"${OPERATOR_TAG}\"" ${HELM_CHART}

0 comments on commit 3bd4809

Please sign in to comment.