From 0782c1c7d14b616dfc2861acbfb6174782efcdd4 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Mon, 12 May 2025 06:53:53 +0200 Subject: [PATCH] add Helm chart image baking Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- modules/helm/helm.mk | 16 ++++++++++++++-- modules/tools/00_mod.mk | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/helm/helm.mk b/modules/helm/helm.mk index cc02cfa1..e7b5156c 100644 --- a/modules/helm/helm.mk +++ b/modules/helm/helm.mk @@ -46,6 +46,7 @@ helm_chart_image_registry := $(dir $(helm_chart_image_name)) helm_chart_image_tag := $(helm_chart_version) helm_chart_sources := $(shell find $(helm_chart_source_dir) -maxdepth 1 -type f) $(shell find $(helm_chart_source_dir)/templates -type f) helm_chart_archive := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).tgz +helm_chart_archive_baked := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).baked.tgz helm_digest_path := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).digests helm_digest = $(shell head -1 $(helm_digest_path) 2> /dev/null) @@ -74,12 +75,15 @@ $(helm_chart_archive): $(helm_chart_sources) | $(NEEDS_HELM) $(NEEDS_YQ) $(bin_d --version $(helm_chart_version) \ --destination $(dir $@) +$(helm_chart_archive_baked): $(helm_chart_archive) | $(NEEDS_HELM-TOOL) + $(HELM-TOOL) images bake $(helm_chart_archive) $(helm_chart_archive_baked) -p $(helm_chart_source_dir)/image_paths.json + .PHONY: helm-chart-oci-push ## Create and push Helm chart to OCI registry. ## Will also create a non-v-prefixed tag for the OCI image. ## @category [shared] Publish -helm-chart-oci-push: $(helm_chart_archive) | $(NEEDS_HELM) $(NEEDS_CRANE) - $(HELM) push "$(helm_chart_archive)" "oci://$(helm_chart_image_registry)" 2>&1 \ +helm-chart-oci-push: $(helm_chart_archive_baked) | $(NEEDS_HELM) $(NEEDS_CRANE) + $(HELM) push "$(helm_chart_archive_baked)" "oci://$(helm_chart_image_registry)" 2>&1 \ | tee >(grep -o "sha256:.\+" | tee $(helm_digest_path)) @# $(helm_chart_image_tag:v%=%) removes the v prefix from the value stored in helm_chart_image_tag. @@ -111,6 +115,14 @@ generate-helm-schema: | $(NEEDS_HELM-TOOL) $(NEEDS_GOJQ) shared_generate_targets += generate-helm-schema +.PHONY: generate-helm-image-paths +## Generate Helm chart image paths. +## @category [shared] Generate/ Verify +generate-helm-image-paths: | $(NEEDS_HELM-TOOL) $(NEEDS_GOJQ) + $(HELM-TOOL) images extract $(helm_chart_source_dir)/values.yaml | $(GOJQ) > $(helm_chart_source_dir)/image_paths.json + +shared_generate_targets += generate-helm-image-paths + .PHONY: verify-helm-values ## Verify Helm chart values using helm-tool. ## @category [shared] Generate/ Verify diff --git a/modules/tools/00_mod.mk b/modules/tools/00_mod.mk index b1da74ba..c9c9d160 100644 --- a/modules/tools/00_mod.mk +++ b/modules/tools/00_mod.mk @@ -126,7 +126,7 @@ tools += goreleaser=v1.26.2 # https://pkg.go.dev/github.com/anchore/syft/cmd/syft?tab=versions tools += syft=v1.22.0 # https://github.com/cert-manager/helm-tool/releases -tools += helm-tool=v0.5.3 +tools += helm-tool=1e5e33bbe040440558170bb41fc00eb02a15d1a1 # https://github.com/cert-manager/image-tool/releases tools += image-tool=v0.0.2 # https://github.com/cert-manager/cmctl/releases