From 48c71953db7b45d29636207ac0ce8cdd6717066d Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Wed, 15 Nov 2023 14:57:17 -0500 Subject: [PATCH] osbuild: add support for metal platform This reworks the coreos.osbuild.mpp.yaml to use the new kernel-cmdline.bls-append stage [1], enabling us to share earlier stages among the platform specific pipelines. We have renamed the pipeline stages to be more appropriate. Now we have - tree - the filesystem tree - raw-image - builds on "tree" - a raw disk image with nothing platform specific, like kernel arguments - raw-metal-image - builds on "raw-image" - adds kernel arguments specific to `metal` platform - raw-qemu-image - builds on "raw-image" - adds kernel arguments specific to `qemu` platform - metal - builds on "raw-metal-image" - copies out raw image file from "raw-metal-image" stage - no other modifications needed - qemu - builds on "raw-qemu-image" - converts raw image file from "raw-qemu-image" into a qcow2 We have also modified cmd-buildextend-metal to support calling runvm-osbuild for either metal or qemu platform images and also added support for running with the cache qcow2. The cache qcow will allow us to call osbuild multiple times, with later invocations building on work done in previous invocations. For example if we checkpiont the `tree` and `raw-image` stages (as depicted above) then when we call osbuild to build the `metal` image it won't have to do the work for that. The benefits of this will compound when we start to build more disk images in this way. [1] https://github.com/osbuild/osbuild/pull/1429 --- src/cmd-buildextend-metal | 12 +++-- src/coreos.osbuild.mpp.yaml | 98 +++++++++++++++++++++++++++++++++---- src/runvm-osbuild | 26 ++++++---- 3 files changed, 114 insertions(+), 22 deletions(-) diff --git a/src/cmd-buildextend-metal b/src/cmd-buildextend-metal index 990210bf57..804314d552 100755 --- a/src/cmd-buildextend-metal +++ b/src/cmd-buildextend-metal @@ -262,9 +262,15 @@ cat "${image_json}" image-dynamic.json | jq -s add > image-for-disk.json platforms_json="${workdir}/tmp/platforms.json" yaml2json "${configdir}/platforms.yaml" "${platforms_json}" -if [ "${image_type}" == "qemu" ] && [ "${COSA_USE_OSBUILD:-}" != "" ]; then - runvm -- /usr/lib/coreos-assembler/runvm-osbuild \ - "${ostree_repo}" "${ref}" \ +# Currently we only support OSBuild for qemu and metal disk images +if [ "${image_type}" == "qemu" ] || [ "${image_type}" == "metal" ]; then + OSBUILD_SUPPORTED=1 +fi + +# Run with OSBuild if it's supported and requested, otherwise use create_disk +if [ "${OSBUILD_SUPPORTED:-}" != "" ] && [ "${COSA_USE_OSBUILD:-}" != "" ]; then + runvm_with_cache -- /usr/lib/coreos-assembler/runvm-osbuild \ + "${ostree_repo}" "${ref}" ${image_type} \ /usr/lib/coreos-assembler/coreos.osbuild.mpp.yaml \ "${path}.tmp" else diff --git a/src/coreos.osbuild.mpp.yaml b/src/coreos.osbuild.mpp.yaml index 3b825ce591..e04e01ed34 100644 --- a/src/coreos.osbuild.mpp.yaml +++ b/src/coreos.osbuild.mpp.yaml @@ -1,6 +1,6 @@ version: '2' mpp-vars: - release: 38 + filename: $filename mpp-define-image: id: image #10G @@ -28,7 +28,7 @@ mpp-define-image: type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 uuid: CA7D7CCB-63ED-4C53-861C-1742536059CC pipelines: - - name: image-tree + - name: tree source-epoch: 1659397331 stages: - type: org.osbuild.ostree.init-fs @@ -57,9 +57,6 @@ pipelines: - /boot/efi kernel_opts: - rw - - console=tty0 - - console=ttyS0 - - ignition.platform.id=qemu - '$ignition_firstboot' inputs: commits: @@ -88,7 +85,7 @@ pipelines: write_defaults: false greenboot: false ignition: true - - name: image + - name: raw-image stages: - type: org.osbuild.truncate options: @@ -151,7 +148,7 @@ pipelines: type: org.osbuild.tree origin: org.osbuild.pipeline references: - - name:image-tree + - name:tree options: paths: - from: input://tree/ @@ -211,7 +208,87 @@ pipelines: number: mpp-format-int: '{image.layout[''boot''].index}' path: /grub2 - - name: qcow2 + - name: raw-metal-image + stages: + - type: org.osbuild.copy + inputs: + tree: + type: org.osbuild.tree + origin: org.osbuild.pipeline + references: + - name:raw-image + options: + paths: + - from: input://tree/disk.img + to: tree:///disk.img + - type: org.osbuild.kernel-cmdline.bls-append + options: + bootpath: mount:/// + kernel_opts: + - ignition.platform.id=metal + devices: + boot: + type: org.osbuild.loopback + options: + filename: disk.img + start: + mpp-format-int: '{image.layout[''boot''].start}' + size: + mpp-format-int: '{image.layout[''boot''].size}' + mounts: + - name: boot + type: org.osbuild.ext4 + source: boot + target: / + - name: raw-qemu-image + stages: + - type: org.osbuild.copy + inputs: + tree: + type: org.osbuild.tree + origin: org.osbuild.pipeline + references: + - name:raw-image + options: + paths: + - from: input://tree/disk.img + to: tree:///disk.img + - type: org.osbuild.kernel-cmdline.bls-append + options: + bootpath: mount:/// + kernel_opts: + - console=tty0 + - console=ttyS0,115200n8 + - ignition.platform.id=qemu + devices: + boot: + type: org.osbuild.loopback + options: + filename: disk.img + start: + mpp-format-int: '{image.layout[''boot''].start}' + size: + mpp-format-int: '{image.layout[''boot''].size}' + mounts: + - name: boot + type: org.osbuild.ext4 + source: boot + target: / + - name: metal + stages: + - type: org.osbuild.copy + inputs: + tree: + type: org.osbuild.tree + origin: org.osbuild.pipeline + references: + - name:raw-metal-image + options: + paths: + - from: input://tree/disk.img + to: + mpp-format-string: 'tree:///{filename}' + - name: qemu stages: - type: org.osbuild.qemu inputs: @@ -219,10 +296,11 @@ pipelines: type: org.osbuild.files origin: org.osbuild.pipeline references: - name:image: + name:raw-qemu-image: file: disk.img options: - filename: disk.qcow2 + filename: + mpp-format-string: '{filename}' format: type: qcow2 compat: '1.1' diff --git a/src/runvm-osbuild b/src/runvm-osbuild index 92328a7551..42c71957a9 100755 --- a/src/runvm-osbuild +++ b/src/runvm-osbuild @@ -3,28 +3,36 @@ set -eux -o pipefail repo=$1 ref=$2 -mppyaml=$3 -path=$4 +platform=$3 +mppyaml=$4 +path=$5 +filename=$(basename "$path") # Since it doesn't exist create loop-control mknod /dev/loop-control c 10 237 -# get away from the virtiofs share because the xattrs that -# are written out by the ostree deploy will cause SELinux denials. -mkdir /root/osbuild && cd /root/osbuild +# Tell osbuild to write out artifacts into a file in the root +# filesystem of the supermin VM, which is ephemeral. +mkdir /var/osbuild +outdir=/var/osbuild/out # Run through the preprocessor osbuild-mpp \ -D ref=\""${ref}"\" \ -D repourl=\""file://${repo}"\" \ + -D filename=\""${filename}"\" \ "${mppyaml}" \ processed.json # Build the image -osbuild --store store/ \ - --output-directory out/ \ - --export qcow2 processed.json +osbuild \ + --out "$outdir" \ + --store cache/osbuild/store/ \ + --cache-max-size 9GiB \ + --checkpoint tree \ + --checkpoint raw-image \ + --export "$platform" processed.json # Copy it out to the specified location -cp out/qcow2/disk.qcow2 "${path}" +cp "${outdir}/${platform}/${filename}" "${path}"