Skip to content

Commit

Permalink
osbuild: add support for metal platform
Browse files Browse the repository at this point in the history
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] osbuild/osbuild#1429
  • Loading branch information
dustymabe committed Nov 16, 2023
1 parent ed24f50 commit 48c7195
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 22 deletions.
12 changes: 9 additions & 3 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 88 additions & 10 deletions src/coreos.osbuild.mpp.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '2'
mpp-vars:
release: 38
filename: $filename
mpp-define-image:
id: image
#10G
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -57,9 +57,6 @@ pipelines:
- /boot/efi
kernel_opts:
- rw
- console=tty0
- console=ttyS0
- ignition.platform.id=qemu
- '$ignition_firstboot'
inputs:
commits:
Expand Down Expand Up @@ -88,7 +85,7 @@ pipelines:
write_defaults: false
greenboot: false
ignition: true
- name: image
- name: raw-image
stages:
- type: org.osbuild.truncate
options:
Expand Down Expand Up @@ -151,7 +148,7 @@ pipelines:
type: org.osbuild.tree
origin: org.osbuild.pipeline
references:
- name:image-tree
- name:tree
options:
paths:
- from: input://tree/
Expand Down Expand Up @@ -211,18 +208,99 @@ 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:
image:
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'
26 changes: 17 additions & 9 deletions src/runvm-osbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 48c7195

Please sign in to comment.