139139imgname=${name} -${build} -${image_type} .${basearch} .${image_format}
140140imgpath=${PWD} /${imgname}
141141
142- deploy_via_container=" "
143- if jq -re ' .["deploy-via-container"]' < " ${image_json} " ; then
144- deploy_via_container=" true"
145- fi
142+ # Parse the passed config JSON and extract a mandatory value
143+ getconfig () {
144+ k=$1
145+ config=$2
146+ jq -re .\" " $k " \" < " ${config} "
147+ }
148+ # Return a configuration value, or default if not set
149+ getconfig_def () {
150+ k=$1
151+ shift
152+ default=$1
153+ config=$2
154+ jq -re .\" " $k " \" //\" " ${default} " \" < " ${config} "
155+ }
156+
157+ # Grab a few values from ${image_json}
158+ deploy_via_container=$( getconfig_def " deploy-via-container" " " " ${image_json} " )
159+ extra_kargs=" $( python3 -c ' import sys, json; args = json.load(sys.stdin)["extra-kargs"]; print(" ".join(args))' < " ${image_json} " ) "
160+
146161# OStree container ociarchive file path
147162ostree_container=" ${builddir} /$( meta_key images.ostree.path) "
148- container_imgref=$( jq -r ' .["container-imgref"]//""' < " ${image_json} " )
149- if [ -z " ${container_imgref} " ]; then
150- # If no container_imgref was set let's just set it to some professional
151- # looking default. The name of the ociarchive file should suffice.
152- container_imgref=" ostree-image-signed:oci-archive:/$( basename " ${ostree_container} " ) "
153- fi
163+ # If no container_imgref was set let's just set it to some professional
164+ # looking default. The name of the ociarchive file should suffice.
165+ container_imgref_default=" ostree-image-signed:oci-archive:/$( basename " ${ostree_container} " ) "
166+ container_imgref=$( getconfig_def " container_imgref" " ${container_imgref_default} " " ${image_json} " )
154167
155168echo " Estimating disk size..."
156169# The additional 35% here is obviously a hack, but we can't easily completely fill the filesystem,
157170# and doing so has apparently negative performance implications.
158- /usr/lib/coreos-assembler/estimate-commit-disk-size --repo " $ostree_repo " " $commit " --add-percent 35 > " $PWD /tmp/ostree-size.json "
159- rootfs_size_mb=" $( jq ' ."estimate-mb".final' " $PWD /tmp/ostree-size.json " ) "
171+ ostree_size_json= " $( /usr/lib/coreos-assembler/estimate-commit-disk-size --repo " $ostree_repo " " $commit " --add-percent 35) "
172+ rootfs_size_mb=" $( jq ' ."estimate-mb".final' <<< " ${ostree_size_json} " ) "
160173# The minimum size of a disk image we'll need will be the rootfs_size
161174# estimate plus the size of the non-root partitions. We'll use this
162175# size for the metal images, but for the IaaS/virt image we'll use
@@ -176,14 +189,9 @@ metal_image_size_mb="$(( rootfs_size_mb + nonroot_partition_sizes ))"
176189cloud_image_size_mb=" $( jq -r " .size*1024" < " ${image_json} " ) "
177190echo " Disk sizes: metal: ${metal_image_size_mb} M (estimated), cloud: ${cloud_image_size_mb} M"
178191
179- set -x
180- extra_kargs=" $( python3 -c ' import sys, json; args = json.load(sys.stdin)["extra-kargs"]; print(" ".join(args))' < " ${image_json} " ) "
181-
182192# Generate the JSON describing the disk we want to build
183- image_dynamic_yaml=" ${tmp_builddir} /image-dynamic.yaml"
184- image_dynamic_json=" ${tmp_builddir} /image-dynamic.json"
185- image_for_disk_json=" ${tmp_builddir} /image-for-disk.json"
186- cat > " ${image_dynamic_yaml} " << EOF
193+ runvm_osbuild_config_json=" ${tmp_builddir} /runvm-osbuild-config.json"
194+ yaml2json /dev/stdin " ${runvm_osbuild_config_json} " << EOF
187195container-imgref: "${container_imgref} "
188196deploy-via-container: "${deploy_via_container} "
189197osname: "${name} "
@@ -197,8 +205,6 @@ cloud-image-size: "${cloud_image_size_mb}"
197205# not the last partition on the disk so we need to explicitly size it
198206rootfs-size: "${rootfs_size_mb} "
199207EOF
200- yaml2json " ${image_dynamic_yaml} " " ${image_dynamic_json} "
201- cat " ${image_json} " " ${image_dynamic_json} " | jq -s add > " ${image_for_disk_json} "
202208
203209# In the jenkins pipelines we build the qemu image first and that operation
204210# will do a lot of the same work required for later artifacts (metal, metal4k, etc)
@@ -208,7 +214,7 @@ cat "${image_json}" "${image_dynamic_json}" | jq -s add > "${image_for_disk_json
208214# This is OK because we don't checkpoint (cache) any of those stages.
209215[ " ${image_type} " == " qemu" ] && snapshot=" off" || snapshot=" on"
210216runvm_with_cache_snapshot " $snapshot " -- /usr/lib/coreos-assembler/runvm-osbuild \
211- --config " ${image_for_disk_json} " \
217+ --config " ${runvm_osbuild_config_json} " \
212218 --mpp " /usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${basearch} .mpp.yaml" \
213219 --filepath " ${imgpath} " \
214220 --platform " ${image_type} "
0 commit comments