Skip to content

Commit 8ee823b

Browse files
committed
osbuild: allow for multiple files to be output from a pipeline
In this case we'll just copy out the entire exported tree for a given pipeline (which we specify as --export=platform). For individual artifacts we'll just name the file the same name as the platform and then copy them into the right place in the calling script. The benefits of this can be seen immediately because now we don't have to know about or copy around qemu-secex bootfs_hash and rootfs_hash inside the supermin VM.
1 parent 08b3780 commit 8ee823b

File tree

8 files changed

+29
-38
lines changed

8 files changed

+29
-38
lines changed

src/cmd-buildextend-metal

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,15 @@ EOF
226226
# This is OK because we don't checkpoint (cache) any of those stages.
227227
[ "${platform}" == "qemu" ] && snapshot="off" || snapshot="on"
228228
runvm_osbuild_config_json="$(generate_runvm_osbuild_config)"
229+
outdir=$(mktemp -p "${tmp_builddir}" -d)
229230
runvm_with_cache_snapshot "$snapshot" -- /usr/lib/coreos-assembler/runvm-osbuild \
230231
--config "${runvm_osbuild_config_json}" \
231232
--mpp "/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.${basearch}.mpp.yaml" \
232-
--filepath "${imgpath}" \
233+
--outdir "${outdir}" \
233234
--platform "${platform}"
234235

236+
mv "${outdir}/${platform}/${platform}" "${imgpath}"
237+
235238
if [[ "${platform}" == "qemu-secex" ]]; then
236239
if [ ! -f "${genprotimgvm}" ]; then
237240
fatal "No genprotimgvm provided at ${genprotimgvm}"
@@ -249,7 +252,9 @@ if [[ "${platform}" == "qemu-secex" ]]; then
249252
genprotimg_dir=$(mktemp -p "${tmp_builddir}" -d)
250253
cp "${se_script_dir}/genprotimg-script.sh" "${se_script_dir}/post-script.sh" "${genprotimg_dir}"
251254
# Extra kargs with dm-verity hashes
252-
secex_kargs="ignition.firstboot rootfs.roothash=$(<"${PWD}"/rootfs_hash) bootfs.roothash=$(<"${PWD}"/bootfs_hash)"
255+
secex_kargs="ignition.firstboot"
256+
secex_kargs+=" rootfs.roothash=$(<"${outdir}/${platform}/rootfs_hash")"
257+
secex_kargs+=" bootfs.roothash=$(<"${outdir}/${platform}/bootfs_hash")"
253258
echo "${secex_kargs}" > "${genprotimg_dir}/parmfile"
254259
virt-make-fs --format=raw --type=ext4 "${genprotimg_dir}" "${genprotimg_img}"
255260
rm -rf "${genprotimg_dir}"

src/osbuild-manifests/platform.applehv.ipp.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,4 @@ pipelines:
6565
options:
6666
paths:
6767
- from: input://tree/disk.img
68-
to:
69-
mpp-format-string: 'tree:///{filename}'
68+
to: tree:///applehv

src/osbuild-manifests/platform.gcp.ipp.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,4 @@ pipelines:
8585
name:raw-gcp-image-tar:
8686
file: disk.tar
8787
options:
88-
filename:
89-
mpp-format-string: '{filename}'
88+
filename: gcp

src/osbuild-manifests/platform.hyperv.ipp.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ pipelines:
6464
name:raw-hyperv-image:
6565
file: disk.img
6666
options:
67-
filename:
68-
mpp-format-string: '{filename}'
67+
filename: hyperv
6968
format:
7069
type: vhdx

src/osbuild-manifests/platform.metal.ipp.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ pipelines:
9090
options:
9191
paths:
9292
- from: input://tree/disk.img
93-
to:
94-
mpp-format-string: 'tree:///{filename}'
93+
to: tree:///metal
9594
- name: raw-metal4k-image
9695
build:
9796
mpp-format-string: '{buildroot}'
@@ -184,5 +183,4 @@ pipelines:
184183
options:
185184
paths:
186185
- from: input://tree/disk.img
187-
to:
188-
mpp-format-string: 'tree:///{filename}'
186+
to: tree:///metal4k

src/osbuild-manifests/platform.qemu-secex.ipp.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ pipelines:
288288
name:raw-qemu-secex-image:
289289
file: disk.img
290290
options:
291-
filename:
292-
mpp-format-string: '{filename}'
291+
filename: qemu-secex
293292
format:
294293
type: qcow2
295294
compression: false

src/osbuild-manifests/platform.qemu.ipp.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ pipelines:
9393
name:raw-qemu-image:
9494
file: disk.img
9595
options:
96-
filename:
97-
mpp-format-string: '{filename}'
96+
filename: qemu
9897
format:
9998
type: qcow2
10099
compression: false

src/runvm-osbuild

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Options:
1010
--config: JSON-formatted image.yaml
1111
--help: show this help
1212
--mpp: the path to the OSBuild mpp.yaml file
13-
--filepath: where to write the created image file
13+
--outdir: where to write the created files
1414
--platform: the platform to generate an artifact for
1515
1616
You probably don't want to run this script by hand. This script is
@@ -39,15 +39,12 @@ do
3939
--config) config="${1}"; shift;;
4040
--help) usage; exit;;
4141
--mpp) mppyaml="${1}"; shift;;
42-
--filepath) filepath="${1}"; shift;;
42+
--outdir) outdir="${1}"; shift;;
4343
--platform) platform="${1}"; shift;;
4444
*) echo "${flag} is not understood."; usage; exit 10;;
4545
esac;
4646
done
4747

48-
# Get the base filename of the desired file output path
49-
filename=$(basename "$filepath")
50-
5148
ostree_container=$(getconfig "ostree-container")
5249
osname=$(getconfig "osname")
5350
deploy_via_container=$(getconfig_def "deploy-via-container" "")
@@ -70,12 +67,20 @@ fi
7067
# Since it doesn't exist create loop-control
7168
[ ! -e /dev/loop-control ] && mknod /dev/loop-control c 10 237
7269

73-
# Put the store and the output dir on the cache. At the end we'll mv
74-
# out the created artifact from the output dir to the place it's supposed
75-
# to go.
76-
outdir=cache/osbuild/out
70+
# Put the store on the cache filesystem since in the case we are
71+
# running unprivileged in COSA we won't be able to create files
72+
# with SELinux labels that the host's policy doesn't know about.
7773
storedir=cache/osbuild/store
7874

75+
# Musical chairs for now with the outdir because osbuild does
76+
# cp -a and that will fail to preserve ownership when copying
77+
# from the cache qcow2 (where files are owned by root) to the
78+
# virtiofs mount. Eventually we can use idmapped virtiofs mount
79+
# inside the supermin VM and we won't need this.
80+
# https://gitlab.com/virtio-fs/virtiofsd/-/merge_requests/245
81+
orig_outdir=$outdir
82+
outdir=cache/osbuild/out
83+
7984
processed_json=$(mktemp -t osbuild-XXXX.json)
8085

8186
# Run `podman images` here to initialize a few directories inside the
@@ -90,7 +95,6 @@ osbuild-mpp \
9095
-D arch=\""$(arch)"\" \
9196
-D ostree_ref=\""${ostree_ref}"\" \
9297
-D ostree_repo=\""${ostree_repo}"\" \
93-
-D filename=\""${filename}"\" \
9498
-D ociarchive=\""${ostree_container}"\" \
9599
-D osname=\""${osname}"\" \
96100
-D container_imgref=\""${container_imgref}"\" \
@@ -112,16 +116,5 @@ osbuild \
112116
--checkpoint raw-image \
113117
--export "$platform" "${processed_json}"
114118

115-
116-
# Copy it out to the specified location. Use mv here so we remove it
117-
# from the cache qcow2 so we don't cache it.
118-
mv "${outdir}/${platform}/${filename}" "${filepath}"
119-
120-
# In case of IBM Secure Execution there are more artifacts
121-
if [ "${platform}" == 'qemu-secex' ]; then
122-
dir=$(dirname "${filepath}")
123-
mv "${outdir}/${platform}/bootfs_hash" "${dir}"
124-
mv "${outdir}/${platform}/rootfs_hash" "${dir}"
125-
fi
126-
119+
mv "${outdir}"/* "${orig_outdir}/"
127120
rm -f "${processed_json}"

0 commit comments

Comments
 (0)