| 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 |
set -euo pipefail |
| 43 |
|
| 44 |
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 45 |
. "$REPO_ROOT/build/privilege.sh" |
| 46 |
|
| 47 |
HOST="${1:-}" |
| 48 |
[ -n "$HOST" ] || { |
| 49 |
printf 'usage: build/preflight.sh <host>\n' >&2 |
| 50 |
printf 'known hosts: %s\n' "$(cd "$REPO_ROOT/build/hosts" && ls -1 ./*.env | sed 's|^\./||; s|\.env$||' | tr '\n' ' ')" >&2 |
| 51 |
exit 2 |
| 52 |
} |
| 53 |
[ -f "$REPO_ROOT/build/hosts/$HOST.env" ] || { |
| 54 |
printf 'preflight: no recipe for host %s\n' "$HOST" >&2 |
| 55 |
exit 2 |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
BASE="$(grep -m1 -oE 'registry\.fedoraproject\.org/fedora-bootc:[0-9]+@sha256:[0-9a-f]+' "$REPO_ROOT/Containerfile")" |
| 62 |
[ -n "$BASE" ] || { echo "preflight: could not read the base image from the Containerfile" >&2; exit 1; } |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
out="$(mktemp)"; probe="" |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
cleanup() { rm -f "$out"; [ -n "$probe" ] && rm -rf "$probe"; :; } |
| 76 |
trap cleanup EXIT |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
set +e |
| 82 |
privc podman run --rm \ |
| 83 |
-v "$REPO_ROOT:/repo:ro" \ |
| 84 |
--entrypoint python3 \ |
| 85 |
"$BASE" /repo/build/preflight.py "$HOST" | tee "$out" |
| 86 |
rc="${PIPESTATUS[0]}" |
| 87 |
set -e |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
if [ "$rc" -ne 0 ]; then |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
echo |
| 117 |
echo "== probe: skipped; the dials above are already a refusal" |
| 118 |
elif [ "${2:-}" = "--fast" ]; then |
| 119 |
echo |
| 120 |
echo "== probe: skipped (--fast); dials and guards only" |
| 121 |
else |
| 122 |
pkgset="$(sed -n 's/^PKGSET: //p' "$out")" |
| 123 |
drop="$(sed -n 's/^TMPFILES-DROP: //p' "$out")" |
| 124 |
if [ -z "$pkgset" ]; then |
| 125 |
echo; echo "== probe: SKIP no package set came back from the resolver" |
| 126 |
else |
| 127 |
probe="$(mktemp -d)" |
| 128 |
mkdir -p "$probe/tmpfiles" |
| 129 |
cp "$REPO_ROOT"/usr/lib/tmpfiles.d/*.conf "$probe/tmpfiles/" |
| 130 |
for f in $drop; do rm -f "$probe/tmpfiles/$f"; done |
| 131 |
if [ -f "$REPO_ROOT/build/hosts/$HOST.requires" ]; then |
| 132 |
cp "$REPO_ROOT/build/hosts/$HOST.requires" "$probe/requires" |
| 133 |
else |
| 134 |
: > "$probe/requires" |
| 135 |
fi |
| 136 |
|
| 137 |
|
| 138 |
cat > "$probe/check-requires.sh" <<'CHECK' |
| 139 |
#!/bin/sh |
| 140 |
# Each requirement, asked of the image rather than of the repos. |
| 141 |
bad=0; any=0 |
| 142 |
while IFS= read -r line; do |
| 143 |
line="${line%%#*}" |
| 144 |
line="$(printf '%s' "$line" | tr -d '[:space:]')" |
| 145 |
[ -n "$line" ] || continue |
| 146 |
any=1 |
| 147 |
kind="${line%%:*}"; value="${line#*:}" |
| 148 |
case "$kind" in |
| 149 |
bin) command -v "$value" >/dev/null 2>&1 ;; |
| 150 |
pkgconfig) pkg-config --exists "$value" 2>/dev/null ;; |
| 151 |
file) find / -path "$value" -print -quit 2>/dev/null | grep -q . ;; |
| 152 |
*) printf ' SKIP %-34s unknown requirement kind |
| 153 |
' "$line"; continue ;; |
| 154 |
esac |
| 155 |
if [ $? -eq 0 ]; then |
| 156 |
printf ' ok %s |
| 157 |
' "$line" |
| 158 |
else |
| 159 |
printf ' FAIL %s |
| 160 |
' "$line" |
| 161 |
# Only now is repoquery worth the wait, and only for what is missing. |
| 162 |
case "$kind" in |
| 163 |
bin) q="/usr/bin/$value" ;; |
| 164 |
pkgconfig) q="pkgconfig($value)" ;; |
| 165 |
file) q="$value" ;; |
| 166 |
esac |
| 167 |
c="$(dnf -q repoquery --qf '%{name} |
| 168 |
' --whatprovides "$q" 2>/dev/null | sort -u | head -4 | tr ' |
| 169 |
' ' ')" |
| 170 |
[ -n "$c" ] && printf ' add one of: %s |
| 171 |
' "$c" |
| 172 |
bad=1 |
| 173 |
fi |
| 174 |
done < /requires |
| 175 |
[ "$any" = 1 ] || echo " SKIP this host declares no role contract" |
| 176 |
exit "$bad" |
| 177 |
CHECK |
| 178 |
chmod +x "$probe/check-requires.sh" |
| 179 |
|
| 180 |
cat > "$probe/Containerfile" <<PROBE |
| 181 |
FROM $BASE |
| 182 |
RUN set -eux; dnf install -y --skip-unavailable --setopt=install_weak_deps=False $pkgset; \\ |
| 183 |
dnf clean all; \\ |
| 184 |
rm -f /var/log/dnf5.log*; \\ |
| 185 |
rm -rf /var/lib/dnf /var/cache/libdnf5; \\ |
| 186 |
rm -f /var/cache/ldconfig/aux-cache; \\ |
| 187 |
rm -f /var/cache/swcatalog/cache/*.xb; \\ |
| 188 |
rm -f /var/lib/authselect/checksum |
| 189 |
COPY tmpfiles/ /usr/lib/tmpfiles.d/ |
| 190 |
COPY requires /requires |
| 191 |
COPY check-requires.sh /check-requires.sh |
| 192 |
PROBE |
| 193 |
|
| 194 |
echo |
| 195 |
echo "== probe: building the smallest image that can answer (one dnf transaction)" |
| 196 |
if ! privc podman build -q -t localhost/alloy-preflight-probe:"$HOST" "$probe" >/dev/null 2>"$probe/build.err"; then |
| 197 |
echo " SKIP the probe would not build:" |
| 198 |
sed 's/^/ /' "$probe/build.err" | tail -6 |
| 199 |
rc=1 |
| 200 |
else |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
missing="$(privc podman run --rm --entrypoint sh localhost/alloy-preflight-probe:"$HOST" -c \ |
| 208 |
'for p in '"$pkgset"'; do rpm -q --whatprovides "$p" >/dev/null 2>&1 || echo "$p"; done' 2>/dev/null | tr '\n' ' ')" |
| 209 |
notprobed="$(sed -n 's/^NOT-PROBED: //p' "$out")" |
| 210 |
[ -n "$notprobed" ] && missing="$missing$notprobed" |
| 211 |
if [ -n "$missing" ]; then |
| 212 |
echo |
| 213 |
echo "== probe coverage: not installed here, so not checked" |
| 214 |
printf ' %s\n' "$missing" | fold -s -w 76 | sed 's/^/ /' |
| 215 |
echo " (the real build enables Terra and COPRs first; the probe does not)" |
| 216 |
fi |
| 217 |
|
| 218 |
echo |
| 219 |
echo "== requires: what this host's role needs, asked of the image" |
| 220 |
set +e |
| 221 |
privc podman run --rm --entrypoint sh localhost/alloy-preflight-probe:"$HOST" /check-requires.sh |
| 222 |
[ $? -eq 0 ] || rc=1 |
| 223 |
set -e |
| 224 |
|
| 225 |
echo |
| 226 |
echo "== var-payload: bootc's own lint, on that probe" |
| 227 |
lint="$(privc podman run --rm --entrypoint bootc localhost/alloy-preflight-probe:"$HOST" \ |
| 228 |
container lint --no-truncate 2>&1 || true)" |
| 229 |
if printf '%s' "$lint" | grep -q 'var-tmpfiles'; then |
| 230 |
printf '%s\n' "$lint" | sed -n '/var-tmpfiles/,/^$/p' | sed 's/^/ /' |
| 231 |
echo " FAIL bootc would refuse this mint's /var; declare the paths above" |
| 232 |
rc=1 |
| 233 |
else |
| 234 |
echo " ok: bootc finds nothing undeclared in /var for this package set" |
| 235 |
fi |
| 236 |
fi |
| 237 |
fi |
| 238 |
fi |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
echo |
| 250 |
echo "== guards: known workarounds, asserted to still be there" |
| 251 |
tree_root="$(cd "$REPO_ROOT/.." && pwd)" |
| 252 |
guards_bad=0 |
| 253 |
for rel in Apps/goingson/dist/recipes/linux.rhai Apps/balanced_breakfast/dist/recipes/linux.rhai; do |
| 254 |
f="$tree_root/$rel" |
| 255 |
if [ ! -f "$f" ]; then |
| 256 |
printf ' SKIP %-52s not on this machine\n' "$rel" |
| 257 |
elif grep -q 'NO_STRIP' "$f"; then |
| 258 |
printf ' ok %-52s carries NO_STRIP\n' "$rel" |
| 259 |
else |
| 260 |
printf ' FAIL %-52s lost NO_STRIP; every AppImage built on Alloy would fail at bundling\n' "$rel" |
| 261 |
guards_bad=1 |
| 262 |
fi |
| 263 |
done |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
if [ "$rc" -eq 0 ] && [ "$guards_bad" -eq 0 ]; then |
| 278 |
echo; echo "preflight: clean" |
| 279 |
exit 0 |
| 280 |
fi |
| 281 |
if [ "$rc" -eq 0 ]; then |
| 282 |
echo; echo "preflight: this host has findings; the medium itself is clean" |
| 283 |
exit 4 |
| 284 |
fi |
| 285 |
echo; echo "preflight: findings above; fix them before building" |
| 286 |
exit 1 |
| 287 |
|