Skip to content

Commit f7203df

Browse files
qemu-secex: reuse locally generated genprotimgvm when available
1 parent e3e3038 commit f7203df

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/cmd-osbuild

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,31 @@ json.dump(j, sys.stdout, indent=4)
7878
# VM to run genprotimg and save off the pubkey for Ignition.
7979
postprocess_qemu_secex() {
8080
if [ ! -f "${genprotimgvm}" ]; then
81-
if [ ! -f "${hostkey}" ]; then
82-
fatal "No hostkey and no genprotimgvm provided"
81+
echo "No genprotimgvm provided"
82+
genprotimgvm="${workdir}/tmp/fake-secure-vm.qcow2"
83+
if [ -f "${genprotimgvm}" ]; then
84+
echo "Found locally generated ${genprotimgvm}, skipping generation"
85+
else
86+
if [ ! -f "${hostkey}" ]; then
87+
fatal "No hostkey and no genprotimgvm provided"
88+
fi
89+
echo "Generating ${genprotimgvm} locally"
90+
local ignition_cfg=$(mktemp -p "${tmp_builddir}")
91+
local butane_cfg=$(mktemp -p "${tmp_builddir}")
92+
93+
echo "Injecting user-provided hostkey into config"
94+
local hostkey_name=$(basename "${hostkey}")
95+
local hostkey_path=$(dirname "${hostkey}")
96+
cp /usr/lib/coreos-assembler/secex-genprotimgvm-scripts/genprotimg.bu "${butane_cfg}"
97+
sed -i 's/HOSTKEY-FILE/'"${hostkey_name}"'/g' "${butane_cfg}"
98+
butane -p -d "${hostkey_path}" "${butane_cfg}" -o "${ignition_cfg}"
99+
100+
cp "/srv/builds/latest/${basearch}/${name}-${build}-qemu.${basearch}.${image_format}" "${genprotimgvm}"
101+
chmod +w "${genprotimgvm}"
102+
genvm_args=("-drive" "if=none,id=hda,file=${genprotimgvm},auto-read-only=off,cache=unsafe" \
103+
"-device" "virtio-blk,drive=hda,bootindex=1")
104+
kola qemuexec -i "${ignition_cfg}" -- "${genvm_args[@]}"
83105
fi
84-
echo "Generating genprotimgvm locally"
85-
local ignition_cfg=$(mktemp -p "${tmp_builddir}")
86-
local butane_cfg=$(mktemp -p "${tmp_builddir}")
87-
88-
echo "Injecting user-provided hostkey into config"
89-
local hostkey_name=$(basename "${hostkey}")
90-
local hostkey_path=$(dirname "${hostkey}")
91-
cp /usr/lib/coreos-assembler/secex-genprotimgvm-scripts/genprotimg.bu "${butane_cfg}"
92-
sed -i 's/HOSTKEY-FILE/'"${hostkey_name}"'/g' "${butane_cfg}"
93-
butane -p -d "${hostkey_path}" "${butane_cfg}" -o "${ignition_cfg}"
94-
95-
genprotimgvm=/srv/fake-secure-vm.qcow2
96-
cp "/srv/builds/latest/${basearch}/${name}-${build}-qemu.${basearch}.${image_format}" "${genprotimgvm}"
97-
chmod +w "${genprotimgvm}"
98-
genvm_args=("-drive" "if=none,id=hda,file=${genprotimgvm},auto-read-only=off,cache=unsafe" \
99-
"-device" "virtio-blk,drive=hda,bootindex=1")
100-
kola qemuexec -i "${ignition_cfg}" -- "${genvm_args[@]}"
101106
fi
102107

103108
# Basic qemu args:

0 commit comments

Comments
 (0)