Skip to content

Commit 46af48f

Browse files
committed
cmdlib: make a helper for manifest.metadata knobs
Prep work to add a knob for using bootc install in osbuild. Refactor the override logic in a helper function so we can easily add those knobs down the line.
1 parent 6ce8e88 commit 46af48f

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/cmdlib.sh

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,49 @@ yaml2json() {
148148
python3 -c 'import sys, json, yaml; json.dump(yaml.safe_load(sys.stdin), sys.stdout, sort_keys=True)' < "$1" > "$2"
149149
}
150150

151-
should_build_with_buildah() {
152-
local variant manifest
153-
if [ -n "${COSA_BUILD_WITH_BUILDAH:-}" ]; then
154-
if [ "${COSA_BUILD_WITH_BUILDAH:-}" = 1 ]; then
151+
# Common helper to check for features that can be enabled via an env var or
152+
# in the manifest metadata.
153+
_should_enable_feature() {
154+
local env_var_name=$1
155+
local metadata_key=$2
156+
local env_var_value
157+
# Indirect expansion
158+
env_var_value=${!env_var_name:-}
159+
160+
if [ -n "${env_var_value}" ]; then
161+
if [ "${env_var_value}" = 1 ]; then
155162
return 0
156163
else
157164
return 1
158165
fi
159166
fi
167+
168+
# Make sure we are in the config directory (e.g. cmd-osbuild set a different working directory).
169+
# When called very early (e.g. cmd-fetch), configdir isn't initialized yet so we assume we are in the top
170+
# cosa initialized dir and use `src/config`.
171+
# We redirect the output to /dev/null to avoid the noisy `dirs` output.
172+
set +u
173+
pushd "${configdir:-src/config}" > /dev/null
174+
set -u
160175
# this slightly duplicates some logic in `prepare_build`, but meh...
161-
if [[ -f "src/config.json" ]]; then
162-
variant="$(jq --raw-output '."coreos-assembler.config-variant"' src/config.json)"
163-
manifest="src/config/manifest-${variant}.yaml"
176+
if [[ -f "../config.json" ]]; then
177+
variant="$(jq --raw-output '."coreos-assembler.config-variant"' ../config.json)"
178+
manifest="manifest-${variant}.yaml"
164179
else
165-
manifest="src/config/manifest.yaml"
180+
manifest="manifest.yaml"
166181
fi
167-
if [ "$(yq .metadata.build_with_buildah "${manifest}")" = true ]; then
182+
if [ "$(yq ".metadata.${metadata_key}" "${manifest}")" = true ]; then
183+
popd > /dev/null
168184
return 0
169185
fi
186+
popd > /dev/null
170187
return 1
171188
}
172189

190+
should_use_bootc_install() {
191+
_should_enable_feature "COSA_OSBUILD_USE_BOOTC_INSTALL" "use_bootc_install"
192+
}
193+
173194
prepare_build() {
174195
preflight
175196
preflight_kvm

0 commit comments

Comments
 (0)