Skip to content

Commit 23594c2

Browse files
Kabuki94claude
andcommitted
feat(build): honor [packages.<X>].enable + [deployment].target_<Y>
Commit 3 of 3 in the configurator-as-SSOT chain: Commit A (fef19cf): toml schema -- enable flags + [deployment] Commit B (3ea193d): configurator -- toggles for packages + targets Commit C (this): build pipe -- honor the toggles Build pipeline changes: 1. automation/lib/packages.sh now exports `_is_section_enabled <category>` -- an awk-only TOML reader (no python3 dep, safe at the very-early build phases when only base RPMs are present) that returns 0 (enabled) for missing/true values and 1 (disabled) only when the toml explicitly has `[packages.<category>].enable = false`. `install_packages` and `install_packages_optional` consult `_is_section_enabled` first and skip the dnf invocation entirely when the operator unchecked the group in /configurator.html: [packages.gaming].enable=false -- skipping (operator disabled via /configurator.html) `install_packages_strict` is unchanged on purpose -- it's used for foundation-required packages (base, kernel, critical, etc.) which the configurator HTML doesn't expose as toggles. 2. /usr/libexec/mios/mios-build-driver builds BIB_FORMATS from [deployment].target_<key> in the layered toml. Resolution precedence: a. $MIOS_BIB_FORMATS env override (fast-iter dev) b. ~/.config/mios/mios.toml [deployment].target_X = true c. /etc/mios/mios.toml [deployment].target_X = true d. /usr/share/mios/mios.toml [deployment].target_X = true e. historical hard-default: "vhdx qcow2 iso raw wsl" Underscore-to-hyphen translation for BIB --type: toml: target_anaconda_iso -> BIB --type anaconda-iso Default behavior with shipped vendor toml: identical to before (vhdx qcow2 iso raw wsl). Difference is the operator can now toggle ami / ova / anaconda_iso ON via the configurator without editing build-mios.ps1 / mios-build-driver. Verified the awk parsers against the real /usr/share/mios/mios.toml on this box: [packages.bloat].enable -> false (will be skipped) [packages.gaming].enable -> true (will install) [deployment] targets enabled -> vhdx qcow2 iso raw wsl Bash syntax of both edited files: clean. End-to-end behavior the operator now sees: 1. Open /configurator.html in Epiphany (mios-build-driver step). 2. Uncheck e.g. "ceph" + "freeipa" + check "ami" + "ova". 3. Save -> mios.toml writes [packages.ceph].enable = false [packages.freeipa].enable = false [deployment].target_ami = true [deployment].target_ova = true 4. Build proceeds: [packages.sh] [packages.ceph].enable=false -- skipping [packages.sh] [packages.freeipa].enable=false -- skipping building vhdx ... qcow2 ... iso ... raw ... wsl ... ami ... ova 5. Output artifacts in /var/lib/mios/build/output/ now include ami + ova in addition to the 5 portable formats. The full configurator-as-SSOT chain is in place. The operator's choices in the HTML drive the actual build with no terminal prompts (other than password when password_policy=interactive, per the toml schema's secrets policy). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3ea193d commit 23594c2

2 files changed

Lines changed: 83 additions & 8 deletions

File tree

automation/lib/packages.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,46 @@ _PKG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
126126
# shellcheck source=automation/lib/common.sh
127127
source "${_PKG_DIR}/common.sh"
128128

129+
# _is_section_enabled <section>
130+
# Returns 0 (enabled) if [packages.<section>].enable is missing OR true.
131+
# Returns 1 (disabled) only when explicitly set to false in the toml.
132+
# This is the runtime side of the configurator HTML's package toggles --
133+
# the operator unchecks a box, the configurator writes
134+
# `[packages.<name>].enable = false` to mios.toml, and this helper
135+
# tells install_packages* to skip that group's dnf install.
136+
#
137+
# Parses with awk (no python3 dependency -- safe even at very-early
138+
# build phases before python is layered in).
139+
_is_section_enabled() {
140+
local section="$1"
141+
local toml result
142+
toml=$(_resolve_mios_toml) || return 0 # no toml at all -> default enabled
143+
result=$(awk -v sect="[packages.$section]" '
144+
$0 == sect { in_section = 1; next }
145+
/^\[/ && in_section { in_section = 0 }
146+
in_section && /^[[:space:]]*enable[[:space:]]*=/ {
147+
# match "enable = false" or "enable = true" (any whitespace).
148+
# Anything other than literal "false" is treated as enabled
149+
# (covers "true", missing-quote variants, comments after the
150+
# value, etc.) since the schema default is true.
151+
if ($0 ~ /=[[:space:]]*false[[:space:]]*($|#)/) print "false"
152+
else print "true"
153+
exit
154+
}
155+
' "$toml" 2>/dev/null)
156+
[[ "$result" != "false" ]]
157+
}
158+
129159
# install_packages <section>
130160
# Best-effort: warns on per-package install failures, doesn't return non-zero.
161+
# Honors [packages.<section>].enable -- if the operator unchecked the
162+
# group in /configurator.html, this is a no-op.
131163
install_packages() {
132164
local category="$1"
165+
if ! _is_section_enabled "$category"; then
166+
echo "[packages.sh] [packages.${category}].enable=false -- skipping (operator disabled via /configurator.html)"
167+
return 0
168+
fi
133169
local packages
134170
packages=$(get_packages "$category")
135171
if [[ -n "${packages// }" ]]; then
@@ -165,11 +201,14 @@ install_packages_strict() {
165201
}
166202

167203
# install_packages_optional <section>
168-
# Silent skip when the section is absent / empty (intentionally disabled
169-
# via the configurator HTML or a /etc/mios/mios.toml host override).
204+
# Silent skip when the section is absent / empty / disabled.
170205
# Otherwise behaves like install_packages (best-effort).
171206
install_packages_optional() {
172207
local category="$1"
208+
if ! _is_section_enabled "$category"; then
209+
echo "[packages.sh] INFO: [packages.${category}].enable=false -- skipping (operator disabled via /configurator.html)"
210+
return 0
211+
fi
173212
local packages
174213
packages=$(get_packages "$category")
175214
if [[ -z "${packages// }" ]]; then

usr/libexec/mios/mios-build-driver

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,23 +353,59 @@ else
353353
_log "BIB image: $BIB_IMG"
354354
_log "Output dir: $BIB_OUT"
355355

356-
# The artifact format list. Operator can override via
357-
# MIOS_BIB_FORMATS="vhdx qcow2" to skip slow ones during iteration.
358-
BIB_FORMATS="${MIOS_BIB_FORMATS:-vhdx qcow2 iso raw wsl}"
359-
_log "Formats: $BIB_FORMATS"
356+
# Build BIB_FORMATS from [deployment].target_<key> in the layered
357+
# mios.toml -- the configurator HTML's "Deployment targets" section
358+
# toggles these. Operator override via $MIOS_BIB_FORMATS="vhdx qcow2"
359+
# still wins for fast-iter dev cycles. Final fallback to the
360+
# historical 5-format default if the toml is missing entirely.
361+
if [[ -n "${MIOS_BIB_FORMATS:-}" ]]; then
362+
BIB_FORMATS="$MIOS_BIB_FORMATS"
363+
_log "Formats from MIOS_BIB_FORMATS env: $BIB_FORMATS"
364+
else
365+
DEP_TOML=""
366+
for cand in \
367+
"${HOME:-/root}/.config/mios/mios.toml" \
368+
/etc/mios/mios.toml \
369+
/usr/share/mios/mios.toml \
370+
; do
371+
if [[ -r "$cand" ]]; then DEP_TOML="$cand"; break; fi
372+
done
373+
BIB_FORMATS=""
374+
if [[ -n "$DEP_TOML" ]]; then
375+
while read -r tgt; do
376+
[[ -n "$tgt" ]] && BIB_FORMATS+="${tgt} "
377+
done < <(awk '
378+
/^\[deployment\]$/ { in_deploy=1; next }
379+
/^\[/ && in_deploy { in_deploy=0 }
380+
in_deploy && /^[[:space:]]*target_[a-z0-9_]+[[:space:]]*=[[:space:]]*true/ {
381+
sub(/^[[:space:]]*target_/, "")
382+
sub(/[[:space:]]*=.*$/, "")
383+
print
384+
}
385+
' "$DEP_TOML")
386+
_log "Formats from $DEP_TOML [deployment]: ${BIB_FORMATS:-<none enabled>}"
387+
fi
388+
if [[ -z "${BIB_FORMATS// }" ]]; then
389+
BIB_FORMATS="vhdx qcow2 iso raw wsl"
390+
_log "Formats fallback to historical default: $BIB_FORMATS"
391+
fi
392+
fi
360393

361394
BIB_OK=()
362395
BIB_FAIL=()
363396
for fmt in $BIB_FORMATS; do
397+
# toml field names use underscores (target_anaconda_iso); BIB
398+
# --type uses hyphens (anaconda-iso). Translate.
399+
bib_type="${fmt//_/-}"
364400
_log ""
365-
_log "→ building $fmt"
401+
_log "→ building $fmt (BIB --type $bib_type) "
366402
if sudo podman run --rm --privileged \
367403
--pull=newer \
368404
--security-opt label=type:unconfined_t \
369405
-v "$BIB_OUT:/output:Z" \
370406
-v /var/lib/containers/storage:/var/lib/containers/storage \
371407
"$BIB_IMG" \
372-
--type "$fmt" \
408+
--type "$bib_type" \
373409
--local localhost/mios:latest 2>&1 | tee -a "$LOG_FILE"; then
374410
_log "[ok] $fmt artifact written under $BIB_OUT"
375411
BIB_OK+=("$fmt")

0 commit comments

Comments
 (0)