Skip to content

Commit 6e84d63

Browse files
committed
helm: build and publish for multiple repositories
1 parent a7d955d commit 6e84d63

7 files changed

Lines changed: 99 additions & 3 deletions

File tree

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
# This script also requires `jq` https://stedolan.github.io/jq/
99

1010
.PHONY: build publish
11+
.PHONY: chart-package-oci chart-package-quay chart-package-all
12+
.PHONY: chart-publish-oci chart-publish-quay chart-publish-all
1113

1214
OPERATOR_NAME := airflow-operator
1315
VERSION := $(shell cargo metadata --format-version 1 | jq -r '.packages[] | select(.name=="stackable-${OPERATOR_NAME}") | .version')
1416

1517
OCI_REGISTRY_HOSTNAME := oci.stackable.tech
1618
OCI_REGISTRY_PROJECT_IMAGES := sdp
1719

20+
OCI_REGISTRY_PROJECT_CHARTS ?= sdp/charts
21+
QUAY_REGISTRY_PROJECT_CHARTS ?= stackable/charts
22+
23+
CHART_DIR := deploy/helm/${OPERATOR_NAME}
24+
CHART_PACKAGE_OUTPUT_DIR ?= /tmp
25+
1826
SHELL=/usr/bin/env bash -euo pipefail
1927

2028
render-readme:
@@ -53,6 +61,38 @@ crds:
5361
chart-lint: compile-chart
5462
docker run -it -v $(shell pwd):/build/helm-charts -w /build/helm-charts quay.io/helmpack/chart-testing:v3.5.0 ct lint --config deploy/helm/ct.yaml
5563

64+
chart-package-oci: compile-chart
65+
tmp_dir="$$(mktemp -d)"; \
66+
trap 'rm -rf "$$tmp_dir"' EXIT; \
67+
cp -r "${CHART_DIR}" "$$tmp_dir/"; \
68+
yq ea '. as $$item ireduce ({}; . * $$item )' \
69+
"$$tmp_dir/${OPERATOR_NAME}/values.yaml" \
70+
"$$tmp_dir/${OPERATOR_NAME}/values.registry-oci.yaml" \
71+
> "$$tmp_dir/${OPERATOR_NAME}/values.yaml.new"; \
72+
mv "$$tmp_dir/${OPERATOR_NAME}/values.yaml.new" "$$tmp_dir/${OPERATOR_NAME}/values.yaml"; \
73+
helm package "$$tmp_dir/${OPERATOR_NAME}" --destination "${CHART_PACKAGE_OUTPUT_DIR}"
74+
75+
chart-package-quay: compile-chart
76+
tmp_dir="$$(mktemp -d)"; \
77+
trap 'rm -rf "$$tmp_dir"' EXIT; \
78+
cp -r "${CHART_DIR}" "$$tmp_dir/"; \
79+
yq ea '. as $$item ireduce ({}; . * $$item )' \
80+
"$$tmp_dir/${OPERATOR_NAME}/values.yaml" \
81+
"$$tmp_dir/${OPERATOR_NAME}/values.registry-quay.yaml" \
82+
> "$$tmp_dir/${OPERATOR_NAME}/values.yaml.new"; \
83+
mv "$$tmp_dir/${OPERATOR_NAME}/values.yaml.new" "$$tmp_dir/${OPERATOR_NAME}/values.yaml"; \
84+
helm package "$$tmp_dir/${OPERATOR_NAME}" --destination "${CHART_PACKAGE_OUTPUT_DIR}"
85+
86+
chart-package-all: chart-package-oci chart-package-quay
87+
88+
chart-publish-oci: chart-package-oci
89+
helm push "${CHART_PACKAGE_OUTPUT_DIR}/${OPERATOR_NAME}-${VERSION}.tgz" "oci://${OCI_REGISTRY_HOSTNAME}/${OCI_REGISTRY_PROJECT_CHARTS}"
90+
91+
chart-publish-quay: chart-package-quay
92+
helm push "${CHART_PACKAGE_OUTPUT_DIR}/${OPERATOR_NAME}-${VERSION}.tgz" "oci://quay.io/${QUAY_REGISTRY_PROJECT_CHARTS}"
93+
94+
chart-publish-all: chart-publish-oci chart-publish-quay
95+
5696
clean: chart-clean
5797
cargo clean
5898
docker rmi --force '${OCI_REGISTRY_HOSTNAME}/${OCI_REGISTRY_PROJECT_IMAGES}/${OPERATOR_NAME}:${VERSION}'

deploy/helm/airflow-operator/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ make compile-chart
1717
helm install airflow-operator deploy/helm/airflow-operator
1818
```
1919

20+
## Publish The Chart To Multiple Registries
21+
22+
This chart is structured so the operator image can be sourced from different registries without
23+
duplicating templates.
24+
25+
- `values.yaml` contains the default image coordinates (`image.registry` and `image.repository`).
26+
- `values.registry-oci.yaml` sets defaults for chart artifacts published to `oci.stackable.tech`.
27+
- `values.registry-quay.yaml` sets defaults for chart artifacts published to `quay.io`.
28+
29+
Package each artifact with a registry-specific `values.yaml` so users of each chart registry
30+
automatically pull images from the same source registry.
31+
32+
`helm package` does not accept a values overlay directly, so create a temporary chart copy per
33+
target and merge values before packaging:
34+
35+
```bash
36+
# Package chart with oci.stackable.tech defaults
37+
tmp_oci="$(mktemp -d)"
38+
cp -r deploy/helm/airflow-operator "${tmp_oci}/"
39+
yq ea '. as $item ireduce ({}; . * $item )' \
40+
"${tmp_oci}/airflow-operator/values.yaml" \
41+
"${tmp_oci}/airflow-operator/values.registry-oci.yaml" \
42+
> "${tmp_oci}/airflow-operator/values.yaml.new"
43+
mv "${tmp_oci}/airflow-operator/values.yaml.new" "${tmp_oci}/airflow-operator/values.yaml"
44+
helm package "${tmp_oci}/airflow-operator" --destination /tmp/charts-oci
45+
46+
# Package chart with quay.io defaults
47+
tmp_quay="$(mktemp -d)"
48+
cp -r deploy/helm/airflow-operator "${tmp_quay}/"
49+
yq ea '. as $item ireduce ({}; . * $item )' \
50+
"${tmp_quay}/airflow-operator/values.yaml" \
51+
"${tmp_quay}/airflow-operator/values.registry-quay.yaml" \
52+
> "${tmp_quay}/airflow-operator/values.yaml.new"
53+
mv "${tmp_quay}/airflow-operator/values.yaml.new" "${tmp_quay}/airflow-operator/values.yaml"
54+
helm package "${tmp_quay}/airflow-operator" --destination /tmp/charts-quay
55+
```
56+
57+
Then push the packaged chart from `/tmp/charts-oci` to `oci.stackable.tech` and the packaged chart
58+
from `/tmp/charts-quay` to `quay.io`.
59+
2060
## Usage of the CRDs
2161

2262
The usage of this operator and its CRDs is described in the [documentation](https://docs.stackable.tech/airflow/index.html)

deploy/helm/airflow-operator/templates/_helpers.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ Labels for Kubernetes objects created by helm test
7777
{{- define "operator.testLabels" -}}
7878
helm.sh/test: {{ include "operator.chart" . }}
7979
{{- end }}
80+
81+
{{/*
82+
Build the full container image reference.
83+
*/}}
84+
{{- define "operator.image" -}}
85+
{{- printf "%s/%s:%s" .Values.image.registry .Values.image.repository (.Values.image.tag | default .Chart.AppVersion) -}}
86+
{{- end }}

deploy/helm/airflow-operator/templates/deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
template:
1616
metadata:
1717
annotations:
18-
internal.stackable.tech/image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
18+
internal.stackable.tech/image: "{{ include "operator.image" . }}"
1919
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
2020
{{- with .Values.podAnnotations }}
2121
{{- toYaml . | nindent 8 }}
@@ -37,7 +37,7 @@ spec:
3737
- name: {{ include "operator.appname" . }}
3838
securityContext:
3939
{{- toYaml .Values.securityContext | nindent 12 }}
40-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
40+
image: "{{ include "operator.image" . }}"
4141
imagePullPolicy: {{ .Values.image.pullPolicy }}
4242
resources:
4343
{{- toYaml .Values.resources | nindent 12 }}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# Values overlay for chart packages published to oci.stackable.tech.
3+
image:
4+
registry: oci.stackable.tech/sdp
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# Values overlay for chart packages published to quay.io.
3+
image:
4+
registry: quay.io/stackable

deploy/helm/airflow-operator/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Default values for airflow-operator.
22
---
33
image:
4-
repository: oci.stackable.tech/sdp/airflow-operator
4+
registry: oci.stackable.tech/sdp
5+
repository: airflow-operator
56
pullPolicy: IfNotPresent
67
pullSecrets: []
78

0 commit comments

Comments
 (0)