From d921df347e3ba9494757144e5402c66ac4085260 Mon Sep 17 00:00:00 2001 From: Michel Thebeau Date: Thu, 4 Jan 2024 20:54:46 +0000 Subject: [PATCH] chart version auto-increment scheme Refer to the example for auto-increment presented by Bob Church: https://review.opendev.org/c/starlingx/platform-armada-app/+/904464 Implement these specifics for vault-helm: - Use StarlingX debian git revcount packaging mechanisms to derive the semver BUILD version for upstream helm charts which maintains the upstream chart version and adds a versioned BUILD extension. ::= "+" Chart version (MAJOR.MINOR.PATCH+STX.REV) is passed to 'helm package' command to force the version, where REV == 'git revcount' - Update the rules to automatically update the chart versions in the fluxCD helmrelease.yaml files. Test Plan: PASS file byte level comparison of package before/after PASS AIO-SX vault sanity PASS application-update Story: 2010929 Task: 49399 Change-Id: Id40547c1001ab8fa2d7c83abbcc5c9d44185ee2f Signed-off-by: Michel Thebeau --- stx-vault-helm/debian/deb_folder/rules | 26 +++++++++++++------ .../fluxcd-manifests/vault/helmrelease.yaml | 2 +- vault-helm/debian/deb_folder/control | 3 +-- vault-helm/debian/deb_folder/rules | 12 +++++---- vault-helm/vault-helm/files/Makefile | 4 +-- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/stx-vault-helm/debian/deb_folder/rules b/stx-vault-helm/debian/deb_folder/rules index b2ade1f..60e6ca1 100755 --- a/stx-vault-helm/debian/deb_folder/rules +++ b/stx-vault-helm/debian/deb_folder/rules @@ -10,7 +10,7 @@ export REVISION = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.') export APP_NAME = vault export APP_VERSION = $(RELEASE)-$(REVISION) -export APP_TARBALL_FLUXCD = $(APP_NAME)-$(APP_VERSION).tgz +export APP_TARBALL = $(APP_NAME)-$(APP_VERSION).tgz export HELM_REPO = stx-platform export STAGING = staging @@ -30,9 +30,22 @@ override_dh_auto_build: # Setup the staging directory. mkdir -p $(STAGING) cp files/metadata.yaml $(STAGING) + cp -Rv fluxcd-manifests $(STAGING)/ mkdir -p $(STAGING)/charts cp /usr/lib/helm/vault*.tgz $(STAGING)/charts + # Adjust the helmrelease yamls based on the chart versions + for c in $(STAGING)/charts/*; do \ + chart=$$(basename $$c .tgz); \ + chart_name=$${chart%-*}; \ + chart_version=$${chart##*-}; \ + echo "Found $$chart; name: $$chart_name, version: $$chart_version"; \ + chart_manifest=$$(find $(STAGING)/fluxcd-manifests -name helmrelease.yaml -exec grep -q $$chart_name {} \; -print); \ + echo "Updating manifest: $$chart_manifest"; \ + sed -i "s/REPLACE_HELM_CHART_VERSION/$$chart_version/g" $$chart_manifest; \ + grep version $$chart_manifest; \ + done + # Populate metadata. sed -i 's/APP_REPLACE_NAME/$(APP_NAME)/g' $(STAGING)/metadata.yaml sed -i 's/APP_REPLACE_VERSION/$(APP_VERSION)/g' $(STAGING)/metadata.yaml @@ -42,13 +55,10 @@ override_dh_auto_build: mkdir -p $(STAGING)/plugins cp /plugins/*.whl $(STAGING)/plugins - # Prepare staging for fluxcd package - cp -R fluxcd-manifests $(STAGING)/ - - # calculate checksum of all files in staging for the fluxcd app + # calculate checksum of all files in staging for the app cd $(STAGING) && find . -type f ! -name '*.md5' -print0 | xargs -0 md5sum > checksum.md5 - # package fluxcd app - tar -zcf $(APP_TARBALL_FLUXCD) -C $(STAGING)/ . + # package the app + tar -zcf $(APP_TARBALL) -C $(STAGING)/ . # Cleanup staging rm -rf $(STAGING) @@ -56,6 +66,6 @@ override_dh_auto_build: override_dh_auto_install: # Install the app tar file. install -d -m 755 $(APP_FOLDER) - install -p -D -m 755 $(APP_TARBALL_FLUXCD) $(APP_FOLDER) + install -p -D -m 755 $(APP_TARBALL) $(APP_FOLDER) override_dh_usrlocal: diff --git a/stx-vault-helm/stx-vault-helm/fluxcd-manifests/vault/helmrelease.yaml b/stx-vault-helm/stx-vault-helm/fluxcd-manifests/vault/helmrelease.yaml index 8ff549d..8784c97 100644 --- a/stx-vault-helm/stx-vault-helm/fluxcd-manifests/vault/helmrelease.yaml +++ b/stx-vault-helm/stx-vault-helm/fluxcd-manifests/vault/helmrelease.yaml @@ -15,7 +15,7 @@ spec: chart: spec: chart: vault - version: 0.25.0 + version: REPLACE_HELM_CHART_VERSION sourceRef: kind: HelmRepository name: stx-platform diff --git a/vault-helm/debian/deb_folder/control b/vault-helm/debian/deb_folder/control index dfb785f..1992699 100644 --- a/vault-helm/debian/deb_folder/control +++ b/vault-helm/debian/deb_folder/control @@ -3,9 +3,8 @@ Section: libs Priority: optional Maintainer: StarlingX Developers Build-Depends: debhelper-compat (= 13), - chartmuseum, helm, - procps + build-info, Standards-Version: 4.5.1 Homepage: https://www.starlingx.io diff --git a/vault-helm/debian/deb_folder/rules b/vault-helm/debian/deb_folder/rules index 2639a90..cc7788d 100755 --- a/vault-helm/debian/deb_folder/rules +++ b/vault-helm/debian/deb_folder/rules @@ -1,12 +1,14 @@ #!/usr/bin/make -f export DH_VERBOSE = 1 +export DEB_VERSION = $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ') +export PATCH_VERSION = $(shell echo $(DEB_VERSION) | cut -f 4 -d '.') +export CHART_BASE_VERSION = "0.25.0" +export CHART_VERSION = $(CHART_BASE_VERSION)+STX.$(PATCH_VERSION) + export ROOT = debian/tmp export APP_FOLDER = $(ROOT)/usr/lib/helm -export APP_TARBALL = vault-0.25.0.tgz -export STAGING = staging - %: dh $@ @@ -18,11 +20,11 @@ override_dh_auto_build: cat _helpers-CA.tpl >> templates/_helpers.tpl mv templates vault/templates # Create the TGZ file. - make vault + make CHART_VERSION=$(CHART_VERSION) vault override_dh_auto_install: # Install the app tar file. install -d -m 755 $(APP_FOLDER) - install -p -D -m 755 $(APP_TARBALL) $(APP_FOLDER) + install -p -D -m 755 vault*.tgz $(APP_FOLDER) override_dh_auto_test: diff --git a/vault-helm/vault-helm/files/Makefile b/vault-helm/vault-helm/files/Makefile index 03a3bb5..7486f01 100644 --- a/vault-helm/vault-helm/files/Makefile +++ b/vault-helm/vault-helm/files/Makefile @@ -25,18 +25,16 @@ $(CHARTS): init-%: if [ -f $*/Makefile ]; then make -C $*; fi - if [ -f $*/requirements.yaml ]; then helm dep up $*; fi lint-%: init-% if [ -d $* ]; then helm lint $*; fi build-%: - if [ -d $* ]; then helm package $*; fi + if [ -d $* ]; then helm package --version $(CHART_VERSION) $*; fi clean: @echo "Clean all build artifacts" rm -f */templates/_partials.tpl */templates/_globals.tpl - rm -f *tgz */charts/*tgz */requirements.lock rm -rf */charts */tmpcharts %: