Skip to content

Commit 65c89c6

Browse files
fix(ppg-packer): review fixes for identity, CRB map, and CI template coverage
- Key the identity gate on /etc/os-release ID + VERSION_ID major in validate.sh and the smoke template; release-file names cannot tell EL distros apart once more are added - Collapse the per-distro CRB branches into one case mapping with a fail-closed default and a single anchored repolist grep - Validate + fmt-check the reimage and bootstrap templates in the workflow check job; the PR trigger already fires on those paths
1 parent abcccc2 commit 65c89c6

4 files changed

Lines changed: 36 additions & 25 deletions

File tree

.github/workflows/ppg-ami-factory.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
set -euo pipefail
7373
packer fmt -check -diff .
7474
packer fmt -check -diff smoke
75+
packer fmt -check -diff reimage
76+
packer fmt -check -diff bootstrap
7577
packer init .
7678
for os_name in oraclelinux rocky; do
7779
for major in 8 9 10; do
@@ -94,6 +96,9 @@ jobs:
9496
&& packer validate \
9597
-var candidate_ami=ami-00000000000000000 \
9698
-var os=rocky -var os_major=8 -var arch=x86_64 . )
99+
( cd reimage && packer init . && packer validate -var arch=x86_64 . )
100+
( cd bootstrap && packer init . && packer validate \
101+
-var raw_ami=ami-00000000000000000 -var arch=x86_64 . )
97102
# drift guard (mirrors `just check`): justfile root_gib must equal var.volume_size,
98103
# else a reimaged base would be the wrong root size for the refresh to launch.
99104
rg=$(awk -F'"' '/^root_gib[[:space:]]*:=/{print $2; exit}' justfile)

ppg/packer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ami_ol9_x86_64=$(aws ec2 describe-images --region eu-central-1 --owners self \
109109
`scripts/validate.sh` runs as the last provisioner; any failure aborts the build
110110
so a broken/mislabeled image is never registered:
111111

112-
1. `/etc/oracle-release` / `/etc/rocky-release` major matches the target (fidelity).
112+
1. `/etc/os-release` `ID` + `VERSION_ID` major match the target (fidelity; release-file names cannot tell EL distros apart).
113113
2. `uname -m` matches the target arch.
114114
3. The CRB repo is defined: `ol<major>_codeready_builder` (OL), `powertools`
115115
(Rocky 8) or `crb` (Rocky 9/10). PG -devel deps resolve from it.

ppg/packer/scripts/validate.sh

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,39 @@ fail() { echo "VALIDATE FAIL: $*" >&2; exit 1; }
1919
. /etc/os-release
2020
echo "VALIDATE: ${PRETTY_NAME:-?} $(uname -m) (want ${OS} ${OS_MAJOR} / ${UNAME_ARCH})"
2121

22-
# 1. Genuine OS of the expected major (fidelity gate).
22+
# 1. Genuine OS of the expected major (fidelity gate). Keyed on /etc/os-release
23+
# ID + VERSION_ID (sourced above): distro release-file names cannot tell EL
24+
# distros apart once more are added (every clone ships /etc/redhat-release).
2325
case "${OS}" in
24-
oraclelinux) release_file=/etc/oracle-release ;;
25-
rocky) release_file=/etc/rocky-release ;;
26+
oraclelinux) expected_id=ol ;;
27+
rocky) expected_id=rocky ;;
2628
*) fail "unknown OS '${OS}' (want oraclelinux|rocky)" ;;
2729
esac
28-
[[ -f "${release_file}" ]] || fail "no ${release_file} (not ${OS})"
29-
grep -Eq "release[[:space:]]+${OS_MAJOR}\." "${release_file}" \
30-
|| fail "release major != ${OS_MAJOR}: $(cat "${release_file}")"
30+
31+
[[ "${ID:-}" = "${expected_id}" ]] || fail "os-release ID '${ID:-}' != '${expected_id}'"
32+
os_major_found="${VERSION_ID:-}"
33+
os_major_found="${os_major_found%%.*}"
34+
[[ "${os_major_found}" = "${OS_MAJOR}" ]] \
35+
|| fail "os-release major '${os_major_found}' != '${OS_MAJOR}' (VERSION_ID='${VERSION_ID:-}')"
3136

3237
# 2. Architecture matches the target.
3338
[[ "$(uname -m)" = "${UNAME_ARCH}" ]] || fail "arch $(uname -m) != ${UNAME_ARCH}"
3439

3540
# 3. The CRB repo must be DEFINED on the image (it is disabled by default; PG
36-
# -devel deps need it). Oracle names it "ol<major>_codeready_builder", Rocky
37-
# names it "powertools" (8) / "crb" (9/10). The AUTHORITATIVE resolvability
38-
# check is the smoke test, which enables it and actually installs
39-
# percona-postgresql17-server; a builder-side repoquery proved fragile
40-
# (disabled-repo metadata not fetched), so this gate only asserts the repo
41-
# exists.
42-
if [[ "${OS}" = oraclelinux ]]; then
43-
crb="ol${OS_MAJOR}_codeready_builder"
44-
dnf repolist --all 2>/dev/null | grep -qiE "codeready" \
45-
|| fail "CRB repo (${crb}) not defined on image"
46-
else
47-
crb=crb
48-
[[ "${OS_MAJOR}" = 8 ]] && crb=powertools
49-
dnf repolist --all 2>/dev/null | grep -qiE "^${crb}([[:space:]]|$)" \
50-
|| fail "CRB repo (${crb}) not defined on image"
51-
fi
41+
# -devel deps need it). One mapping per distro/major, one anchored grep. The
42+
# AUTHORITATIVE resolvability check is the smoke test, which enables it and
43+
# actually installs percona-postgresql17-server; a builder-side repoquery
44+
# proved fragile (disabled-repo metadata not fetched), so this gate only
45+
# asserts the repo exists.
46+
case "${OS}/${OS_MAJOR}" in
47+
oraclelinux/*) crb="ol${OS_MAJOR}_codeready_builder" ;;
48+
rocky/8) crb="powertools" ;;
49+
rocky/*) crb="crb" ;;
50+
*) fail "no CRB mapping for ${OS}/${OS_MAJOR}" ;;
51+
esac
52+
53+
dnf repolist --all 2>/dev/null | grep -qiE "^${crb}([[:space:]]|$)" \
54+
|| fail "CRB repo (${crb}) not defined on image"
5255
echo " CRB ok: repo defined (${crb})"
5356

5457
# 4. cloud-init present (instance bootstrap).

ppg/packer/smoke/smoke.pkr.hcl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ variable "builder_security_group_name" {
5151
locals {
5252
instance_type = var.arch == "arm64" ? "t4g.large" : "t3.large"
5353
uname_arch = var.arch == "arm64" ? "aarch64" : "x86_64"
54-
release_file = var.os == "rocky" ? "/etc/rocky-release" : "/etc/oracle-release"
54+
# Identity via /etc/os-release ID (release-file names cannot tell EL distros
55+
# apart once more are added: every clone ships /etc/redhat-release).
56+
expected_id = var.os == "rocky" ? "rocky" : "ol"
5557
# Rocky images use "rocky" as the cloud-init default user; OL uses ec2-user.
5658
ssh_user = var.os == "rocky" ? "rocky" : "ec2-user"
5759
# CRB naming differs per distro: OL "ol<major>_codeready_builder", Rocky "powertools" (8) / "crb" (9/10).
@@ -94,7 +96,8 @@ build {
9496
provisioner "shell" {
9597
inline = [
9698
"set -euo pipefail",
97-
"grep -Eq 'release[[:space:]]+${var.os_major}\\.' ${local.release_file} || { echo \"wrong ${var.os} major: $(cat ${local.release_file})\"; exit 1; }",
99+
". /etc/os-release; [ \"$$ID\" = '${local.expected_id}' ] || { echo \"wrong distro ID $$ID (want ${local.expected_id})\"; exit 1; }",
100+
". /etc/os-release; [ \"$${VERSION_ID%%.*}\" = '${var.os_major}' ] || { echo \"wrong major $$VERSION_ID (want ${var.os_major})\"; exit 1; }",
98101
"[ \"$(uname -m)\" = '${local.uname_arch}' ] || { echo \"wrong arch $(uname -m)\"; exit 1; }",
99102
"sudo cloud-init status --wait 2>/dev/null | grep -qE 'done|disabled' || { echo 'cloud-init not done'; exit 1; }",
100103
"rpm -q amazon-ssm-agent >/dev/null || { echo 'ssm-agent not baked'; exit 1; }",

0 commit comments

Comments
 (0)