Skip to content

Commit e78b041

Browse files
committed
Add push-artifasts.sh script; extend Makefile
1 parent b11f348 commit e78b041

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
**/dev
66
/bin
77
/hack/tools/bin
8+
/artifacts
9+
images.txt
810

911
cover.out
1012
*.coverprofile

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ EFFECTIVE_VERSION := $(VERSION)-$(shell git rev-parse HEAD)
1111
LD_FLAGS := "-w $(shell bash $(GARDENER_HACK_DIR)/get-build-ld-flags.sh k8s.io/component-base $(REPO_ROOT)/VERSION $(EXTENSION_PREFIX))"
1212
LEADER_ELECTION := false
1313
IGNORE_OPERATION_ANNOTATION := true
14+
export REPO ?= ghcr.io/ironcore-dev
15+
export TAG ?= $(EFFECTIVE_VERSION)
1416

1517
WEBHOOK_CONFIG_PORT := 8443
1618
WEBHOOK_CONFIG_MODE := url
@@ -33,6 +35,12 @@ endif
3335
TOOLS_DIR := $(HACK_DIR)/tools
3436
include $(GARDENER_HACK_DIR)/tools.mk
3537

38+
KO := $(TOOLS_BIN_DIR)/ko
39+
# renovate: datasource=github-releases depName=ko-build/ko
40+
KO_VERSION ?= v0.17.1
41+
$(KO): $(call tool_version_file,$(KO),$(KO_VERSION))
42+
GOBIN=$(abspath $(TOOLS_BIN_DIR)) go install github.com/google/ko@$(KO_VERSION)
43+
3644
#########################################
3745
# Rules for local development scenarios #
3846
#########################################
@@ -78,6 +86,28 @@ docker-images:
7886
@docker build --build-arg EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) -t $(IMAGE_PREFIX)/$(NAME):$(VERSION) -t $(IMAGE_PREFIX)/$(NAME):latest -f Dockerfile -m 6g --target $(EXTENSION_PREFIX)-$(NAME) .
7987
@docker build --build-arg EFFECTIVE_VERSION=$(EFFECTIVE_VERSION) -t $(IMAGE_PREFIX)/$(ADMISSION_NAME):$(VERSION) -t $(IMAGE_PREFIX)/$(ADMISSION_NAME):latest -f Dockerfile -m 6g --target $(EXTENSION_PREFIX)-$(ADMISSION_NAME) .
8088

89+
#################################################################
90+
# Rules related to binary build, Docker image build and release #
91+
#################################################################
92+
93+
export PUSH ?= false
94+
95+
.PHONY: images
96+
images: $(KO)
97+
KO_DOCKER_REPO=$(REPO) $(KO) build --push=$(PUSH) \
98+
--image-label org.opencontainers.image.source="https://github.com/ironcore-dev/gardener-extension-provider-ironcore" \
99+
--sbom none -t $(TAG) --base-import-paths \
100+
--platform linux/amd64,linux/arm64 \
101+
./cmd/gardener-extension-provider-ironcore ./cmd/gardener-extension-admission-ironcore \
102+
| tee images.txt
103+
104+
.PHONY: artifacts-only
105+
artifacts-only: $(HELM) $(YQ)
106+
hack/push-artifacts.sh
107+
108+
.PHONY: artifacts
109+
artifacts: images artifacts-only
110+
81111
#####################################################################
82112
# Rules for verification, formatting, linting, testing and cleaning #
83113
#####################################################################

hack/push-artifacts.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
charts=(
8+
gardener-extension-provider-ironcore
9+
gardener-extension-admission-ironcore/charts/application
10+
gardener-extension-admission-ironcore/charts/runtime
11+
)
12+
13+
helm_artifacts=artifacts/charts
14+
rm -rf "$helm_artifacts"
15+
mkdir -p "$helm_artifacts"
16+
cp -r charts/gardener-extension-* "$helm_artifacts"
17+
18+
function image() {
19+
grep "$1" images.txt
20+
}
21+
22+
function image_repo() {
23+
image "$1" | cut -d ':' -f 1
24+
}
25+
26+
function image_tag() {
27+
image "$1" | cut -d ':' -f 2-
28+
}
29+
30+
function update_chart_values() {
31+
for chart in charts/*; do
32+
name=$(basename "$chart")
33+
values_file="$helm_artifacts/$name/values.yaml"
34+
35+
if yq -e '. | has("image")' "$values_file" >/dev/null 2>&1; then
36+
# update charts that have a ".image" field
37+
yq -i "\
38+
( .image = \"$(image "$name")\" )\
39+
" "$values_file"
40+
elif yq -e '.global | has("image")' "$values_file" >/dev/null 2>&1; then
41+
# update charts that have a ".global.image" field
42+
yq -i "\
43+
( .global.image.repository = \"$(image_repo "$name")\" ) | \
44+
( .global.image.tag = \"$(image_tag "$name")\" )\
45+
" "$values_file"
46+
fi
47+
done
48+
}
49+
50+
# inject image references into chart values
51+
update_chart_values
52+
53+
set -x
54+
# push to registry
55+
if [ "$PUSH" != "true" ] ; then
56+
echo "Skip pushing artifacts because PUSH is not set to 'true'"
57+
exit 0
58+
fi
59+
60+
for chart in "${charts[@]}"; do
61+
chart_name=$(yq -e .name "$helm_artifacts/$chart/Chart.yaml")
62+
helm package "$helm_artifacts/$chart" --version "$TAG" -d "$helm_artifacts" >/dev/null 2>&1
63+
helm push "$helm_artifacts/$chart_name-"* "oci://$REPO/charts"
64+
done

0 commit comments

Comments
 (0)