Skip to content

Commit 24b68ff

Browse files
committed
refactor: streamline kustomization build process for alpha overlays
- Replaced inline kustomization build script in the GitHub Actions workflow with a dedicated bash script for better maintainability. - Updated documentation to clarify the use of a publish placeholder in kustomization files and the substitution of commit SHA during builds. - Introduced a new script to handle the rendering of alpha overlays, improving the overall workflow and ensuring accurate builds with the correct references.
1 parent 3f58d09 commit 24b68ff

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

.github/workflows/metaboost-infra-alpha-contracts.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ jobs:
2424
kustomize version
2525
2626
- name: Render infra/k8s/alpha overlays
27-
run: |
28-
set -euo pipefail
29-
for overlay in infra/k8s/alpha/*; do
30-
if [ -d "$overlay" ] && [ -f "$overlay/kustomization.yaml" ]; then
31-
echo "=== kustomize build $overlay ==="
32-
kustomize build --load-restrictor LoadRestrictionsNone "$overlay" >/dev/null
33-
fi
34-
done
27+
env:
28+
KUSTOMIZE_REF: ${{ github.event.pull_request.head.sha || github.sha }}
29+
run: bash scripts/k8s/kustomize-build-metaboost-alpha-overlays.sh

infra/k8s/alpha/INFRA-K8S-ALPHA.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ This directory is the in-repo alpha app-of-apps source.
88

99
`ops/kustomization.yaml` references remote `infra/k8s/base/ops?ref=...` (base ops ConfigMaps stay `metaboost-ops-*`).
1010

11+
Committed overlay `kustomization.yaml` files use publish placeholder **`X.Y.Z-staging.N`** on remote `?ref=` URLs (and matching image tags where applicable). Replace that value with the immutable staging tag after **Publish (staging)**. PR CI (`.github/workflows/metaboost-infra-alpha-contracts.yml`) and [`scripts/k8s/kustomize-build-metaboost-alpha-overlays.sh`](../../scripts/k8s/kustomize-build-metaboost-alpha-overlays.sh) substitute the commit SHA when rendering so overlays validate before a publish tag exists.
12+
1113
External GitOps repositories can still consume this model by syncing this repository revision and
1214
tracking the in-repo alpha root and child app manifests.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# Renders every infra/k8s/alpha/<component> overlay (no cluster apply).
3+
# Committed kustomizations pin remote bases with publish placeholder X.Y.Z-staging.N;
4+
# this script substitutes KUSTOMIZE_REF (commit SHA or staging tag) before kustomize build.
5+
set -euo pipefail
6+
7+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
8+
cd "$ROOT"
9+
10+
PUBLISH_REF_PLACEHOLDER='X.Y.Z-staging.N'
11+
KUSTOMIZE_REF="${KUSTOMIZE_REF:-${1:-${GITHUB_SHA:-}}}"
12+
if [ -z "$KUSTOMIZE_REF" ]; then
13+
KUSTOMIZE_REF="$(git rev-parse HEAD)"
14+
fi
15+
16+
run_kustomize_build() {
17+
local dir="$1"
18+
if command -v kustomize >/dev/null 2>&1; then
19+
kustomize build --load-restrictor LoadRestrictionsNone "$dir"
20+
else
21+
kubectl kustomize "$dir" --load-restrictor LoadRestrictionsNone
22+
fi
23+
}
24+
25+
FAIL=0
26+
for overlay in infra/k8s/alpha/*/; do
27+
if [ ! -f "${overlay}kustomization.yaml" ]; then
28+
continue
29+
fi
30+
overlay_name="${overlay%/}"
31+
tmp="$(mktemp -d)"
32+
cp -R "${overlay}"* "$tmp/"
33+
sed "s/${PUBLISH_REF_PLACEHOLDER}/${KUSTOMIZE_REF}/g" "$tmp/kustomization.yaml" >"$tmp/kustomization.yaml.sub"
34+
mv "$tmp/kustomization.yaml.sub" "$tmp/kustomization.yaml"
35+
echo "=== kustomize build $overlay_name (ref=$KUSTOMIZE_REF) ==="
36+
if run_kustomize_build "$tmp" >/dev/null; then
37+
echo "ok $overlay_name"
38+
else
39+
echo "FAIL $overlay_name" >&2
40+
FAIL=1
41+
fi
42+
rm -rf "$tmp"
43+
done
44+
exit "$FAIL"

0 commit comments

Comments
 (0)