-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathstamp-release-version.sh
More file actions
executable file
·143 lines (129 loc) · 5.58 KB
/
Copy pathstamp-release-version.sh
File metadata and controls
executable file
·143 lines (129 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# Stamp a release version across the v4 install charts and the copies
# embedded in the operator image and the CLI.
#
# hack/stamp-release-version.sh <version> <registry-host> <registry-namespace> [--charts-only]
#
# The committed tree carries a development version (and upstream-default
# registry annotations); real versions are stamped at publish time from
# the git tag by the release workflow — nothing is committed back. See
# decisions.md "Release versions are stamped in CI at publish time".
#
# What gets stamped:
# - educates-installer + educates-training-platform (umbrella) +
# the five runtime subcharts: Chart.yaml version, appVersion, and
# the educates.dev/image-registry-{host,namespace} annotations
# (only where a chart already carries them).
# - The umbrella's dependencies[].version pins.
# - The CLI's embedded operator chart (regenerated from the stamped
# educates-installer chart, same as `make embed-installer-chart`).
#
# Full mode (default) additionally rebuilds what the operator image
# embeds — requires `helm` on PATH:
# - Repackages the five runtime subcharts into
# installer/operator/vendored-charts/ at the stamped version.
# - Rewrites the //go:embed filenames and <X>ChartVersion constants
# in vendored-charts/embed.go (local subcharts only; upstream
# charts stay pinned).
# - Refreshes the local-subchart entries in SHA256SUMS.
#
# --charts-only skips the operator-image pieces; it needs only perl, so
# the macOS CLI build runners can use it.
set -euo pipefail
usage() {
echo "usage: $0 <version> <registry-host> <registry-namespace> [--charts-only]" >&2
exit 1
}
VERSION="${1:-}"
REGISTRY_HOST="${2:-}"
REGISTRY_NAMESPACE="${3:-}"
[ -n "$VERSION" ] && [ -n "$REGISTRY_HOST" ] && [ -n "$REGISTRY_NAMESPACE" ] || usage
CHARTS_ONLY=false
if [ "${4:-}" = "--charts-only" ]; then
CHARTS_ONLY=true
elif [ -n "${4:-}" ]; then
usage
fi
cd "$(dirname "$0")/.."
INSTALLER_CHART=installer/charts/educates-installer
UMBRELLA_CHART=installer/charts/educates-training-platform
VENDORED_CHARTS_DIR=installer/operator/vendored-charts
EMBED_GO=$VENDORED_CHARTS_DIR/embed.go
EMBEDDED_CLI_CHART=client-programs/pkg/deployer/chart/files
LOCAL_SUBCHARTS="secrets-manager lookup-service session-manager node-ca-injector remote-access"
# Maps a subchart name to its version constant in embed.go.
chart_version_const() {
case "$1" in
secrets-manager) echo SecretsManagerChartVersion ;;
lookup-service) echo LookupServiceChartVersion ;;
session-manager) echo SessionManagerChartVersion ;;
node-ca-injector) echo NodeCAInjectorChartVersion ;;
remote-access) echo RemoteAccessChartVersion ;;
*) echo "unknown subchart $1" >&2; exit 1 ;;
esac
}
# Stamps version, appVersion and (where present) the image-registry
# annotations of one Chart.yaml. Line-level perl keeps this portable
# (no yq on the macOS runners) and preserves comments.
stamp_chart_yaml() {
local file="$1"
perl -pi -e "s|^version: .*|version: ${VERSION}|" "$file"
perl -pi -e "s|^appVersion: .*|appVersion: \"${VERSION}\"|" "$file"
perl -pi -e "s|^(\s+)educates\.dev/image-registry-host: .*|\${1}educates.dev/image-registry-host: \"${REGISTRY_HOST}\"|" "$file"
perl -pi -e "s|^(\s+)educates\.dev/image-registry-namespace: .*|\${1}educates.dev/image-registry-namespace: \"${REGISTRY_NAMESPACE}\"|" "$file"
}
echo ">> stamping charts to version ${VERSION} (registry ${REGISTRY_HOST}/${REGISTRY_NAMESPACE})"
stamp_chart_yaml "$INSTALLER_CHART/Chart.yaml"
stamp_chart_yaml "$UMBRELLA_CHART/Chart.yaml"
# The umbrella's only indented `version:` lines are its dependency pins.
perl -pi -e "s|^(\s+)version: .*|\${1}version: ${VERSION}|" "$UMBRELLA_CHART/Chart.yaml"
for name in $LOCAL_SUBCHARTS; do
stamp_chart_yaml "$UMBRELLA_CHART/charts/$name/Chart.yaml"
done
echo ">> refreshing embedded CLI chart from $INSTALLER_CHART"
rm -rf "$EMBEDDED_CLI_CHART"
mkdir -p "$EMBEDDED_CLI_CHART"
cp -r "$INSTALLER_CHART/." "$EMBEDDED_CLI_CHART/"
if $CHARTS_ONLY; then
echo ">> --charts-only: skipping operator vendored-charts rebuild"
exit 0
fi
echo ">> repackaging runtime subcharts into $VENDORED_CHARTS_DIR"
for name in $LOCAL_SUBCHARTS; do
rm -f "$VENDORED_CHARTS_DIR/$name-"*.tgz
helm package "$UMBRELLA_CHART/charts/$name" --destination "$VENDORED_CHARTS_DIR" >/dev/null
[ -f "$VENDORED_CHARTS_DIR/$name-$VERSION.tgz" ] || {
echo "helm package did not produce $name-$VERSION.tgz" >&2
exit 1
}
done
echo ">> rewriting embed.go filenames and version constants"
for name in $LOCAL_SUBCHARTS; do
const=$(chart_version_const "$name")
perl -pi -e "s|^//go:embed ${name}-.*\.tgz$|//go:embed ${name}-${VERSION}.tgz|" "$EMBED_GO"
perl -pi -e "s|^const ${const} = \".*\"|const ${const} = \"${VERSION}\"|" "$EMBED_GO"
done
# Every //go:embed target must exist on disk or the operator image
# build fails later with a far less obvious error.
while read -r tarball; do
[ -f "$VENDORED_CHARTS_DIR/$tarball" ] || {
echo "embed.go references $tarball but it is missing from $VENDORED_CHARTS_DIR" >&2
exit 1
}
done < <(perl -ne 'print "$1\n" if m|^//go:embed (.*\.tgz)$|' "$EMBED_GO")
echo ">> refreshing local-subchart entries in SHA256SUMS"
sums="$VENDORED_CHARTS_DIR/SHA256SUMS"
tmp=$(mktemp)
cp "$sums" "$tmp"
for name in $LOCAL_SUBCHARTS; do
grep -v " ${name}-" "$tmp" > "$tmp.next" || true
mv "$tmp.next" "$tmp"
done
(
cd "$VENDORED_CHARTS_DIR"
for name in $LOCAL_SUBCHARTS; do
shasum -a 256 "$name-$VERSION.tgz" >> "$tmp"
done
)
mv "$tmp" "$sums"
echo ">> done"