Skip to content

Commit ca80131

Browse files
committed
add proof of concept for building with osbuild
This is proof of concept code with many things hardcoded in the coreos.osbuild.mpp.yaml that need to become more dynamically defined. To use this you can set the COSA_USE_OSBUILD env var to have a value. COSA_USE_OSBUILD=1 should work just fine.
1 parent fd7a277 commit ca80131

File tree

5 files changed

+282
-13
lines changed

5 files changed

+282
-13
lines changed

src/cmd-buildextend-metal

+15-7
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,21 @@ EOF
261261
cat "${image_json}" image-dynamic.json | jq -s add > image-for-disk.json
262262
platforms_json="${workdir}/tmp/platforms.json"
263263
yaml2json "${configdir}/platforms.yaml" "${platforms_json}"
264-
runvm "${qemu_args[@]}" -- \
265-
/usr/lib/coreos-assembler/create_disk.sh \
266-
--config "$(pwd)"/image-for-disk.json \
267-
--kargs "${kargs}" \
268-
--platform "${ignition_platform_id}" \
269-
--platforms-json "${platforms_json}" \
270-
"${disk_args[@]}"
264+
265+
if [ "${image_type}" == "qemu" -a "${COSA_USE_OSBUILD:-}" != "" ]; then
266+
runvm -- /usr/lib/coreos-assembler/runvm-osbuild \
267+
$ostree_repo $ref \
268+
/usr/lib/coreos-assembler/coreos.osbuild.mpp.yaml \
269+
"${path}.tmp"
270+
else
271+
runvm "${qemu_args[@]}" -- \
272+
/usr/lib/coreos-assembler/create_disk.sh \
273+
--config "$(pwd)"/image-for-disk.json \
274+
--kargs "${kargs}" \
275+
--platform "${ignition_platform_id}" \
276+
--platforms-json "${platforms_json}" \
277+
"${disk_args[@]}"
278+
fi
271279

272280
if [[ $secure_execution -eq "1" && -z "${hostkey}" ]]; then
273281
/usr/lib/coreos-assembler/secex-genprotimgvm-scripts/runvm.sh \

src/coreos.osbuild.mpp.yaml

+228
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
version: '2'
2+
mpp-vars:
3+
release: 38
4+
mpp-define-image:
5+
id: image
6+
#10G
7+
size: '10737418240'
8+
table:
9+
uuid: 00000000-0000-4000-a000-000000000001
10+
label: gpt
11+
partitions:
12+
- id: BIOS-BOOT
13+
size: 2048
14+
type: 21686148-6449-6E6F-744E-656564454649
15+
bootable: true
16+
uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
17+
- id: EFI-SYSTEM
18+
size: 260096
19+
type: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
20+
uuid: 68B2905B-DF3E-4FB3-80FA-49D1E773AA33
21+
- id: boot
22+
size: 786432
23+
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
24+
uuid: 61B2905B-DF3E-4FB3-80FA-49D1E773AA32
25+
- id: root
26+
# XXX: Dynamically set this size in the future
27+
size: 4194304
28+
type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
29+
uuid: CA7D7CCB-63ED-4C53-861C-1742536059CC
30+
pipelines:
31+
- name: image-tree
32+
source-epoch: 1659397331
33+
stages:
34+
- type: org.osbuild.ostree.init-fs
35+
- type: org.osbuild.ostree.os-init
36+
options:
37+
osname: fedora-coreos
38+
- type: org.osbuild.ostree.config
39+
options:
40+
repo: /ostree/repo
41+
config:
42+
sysroot:
43+
readonly: false
44+
bootloader: none
45+
- type: org.osbuild.mkdir
46+
options:
47+
paths:
48+
- path: /boot/efi
49+
mode: 448
50+
- type: org.osbuild.ignition
51+
- type: org.osbuild.ostree.deploy
52+
options:
53+
osname: fedora-coreos
54+
remote: fedora
55+
mounts:
56+
- /boot
57+
- /boot/efi
58+
kernel_opts:
59+
- rw
60+
- console=tty0
61+
- console=ttyS0
62+
- ignition.platform.id=qemu
63+
- '$ignition_firstboot'
64+
inputs:
65+
commits:
66+
type: org.osbuild.ostree
67+
origin: org.osbuild.source
68+
mpp-resolve-ostree-commits:
69+
commits:
70+
- ref: $ref
71+
remote:
72+
url: $repourl
73+
- type: org.osbuild.ostree.selinux
74+
options:
75+
deployment:
76+
osname: fedora-coreos
77+
ref: ostree/1/1/0
78+
- type: org.osbuild.grub2
79+
options:
80+
rootfs:
81+
label: root
82+
bootfs:
83+
label: boot
84+
uefi:
85+
vendor: fedora
86+
install: true
87+
legacy: i386-pc
88+
write_defaults: false
89+
greenboot: false
90+
ignition: true
91+
- name: image
92+
stages:
93+
- type: org.osbuild.truncate
94+
options:
95+
filename: disk.img
96+
size:
97+
mpp-format-string: '{image.size}'
98+
- type: org.osbuild.sfdisk
99+
devices:
100+
device:
101+
type: org.osbuild.loopback
102+
options:
103+
filename: disk.img
104+
options:
105+
mpp-format-json: '{image.layout}'
106+
- type: org.osbuild.mkfs.fat
107+
devices:
108+
device:
109+
type: org.osbuild.loopback
110+
options:
111+
filename: disk.img
112+
start:
113+
mpp-format-int: '{image.layout[''EFI-SYSTEM''].start}'
114+
size:
115+
mpp-format-int: '{image.layout[''EFI-SYSTEM''].size}'
116+
lock: true
117+
options:
118+
label: EFI-SYSTEM
119+
volid: 7B7795E7
120+
- type: org.osbuild.mkfs.ext4
121+
devices:
122+
device:
123+
type: org.osbuild.loopback
124+
options:
125+
filename: disk.img
126+
start:
127+
mpp-format-int: '{image.layout[''boot''].start}'
128+
size:
129+
mpp-format-int: '{image.layout[''boot''].size}'
130+
lock: true
131+
options:
132+
uuid: 96d15588-3596-4b3c-adca-a2ff7279ea63
133+
label: boot
134+
- type: org.osbuild.mkfs.xfs
135+
devices:
136+
device:
137+
type: org.osbuild.loopback
138+
options:
139+
filename: disk.img
140+
start:
141+
mpp-format-int: '{image.layout[''root''].start}'
142+
size:
143+
mpp-format-int: '{image.layout[''root''].size}'
144+
lock: true
145+
options:
146+
uuid: 910678ff-f77e-4a7d-8d53-86f2ac47a823
147+
label: root
148+
- type: org.osbuild.copy
149+
inputs:
150+
tree:
151+
type: org.osbuild.tree
152+
origin: org.osbuild.pipeline
153+
references:
154+
- name:image-tree
155+
options:
156+
paths:
157+
- from: input://tree/
158+
to: mount://root/
159+
devices:
160+
efi:
161+
type: org.osbuild.loopback
162+
options:
163+
filename: disk.img
164+
start:
165+
mpp-format-int: '{image.layout[''EFI-SYSTEM''].start}'
166+
size:
167+
mpp-format-int: '{image.layout[''EFI-SYSTEM''].size}'
168+
boot:
169+
type: org.osbuild.loopback
170+
options:
171+
filename: disk.img
172+
start:
173+
mpp-format-int: '{image.layout[''boot''].start}'
174+
size:
175+
mpp-format-int: '{image.layout[''boot''].size}'
176+
root:
177+
type: org.osbuild.loopback
178+
options:
179+
filename: disk.img
180+
start:
181+
mpp-format-int: '{image.layout[''root''].start}'
182+
size:
183+
mpp-format-int: '{image.layout[''root''].size}'
184+
mounts:
185+
- name: root
186+
type: org.osbuild.xfs
187+
source: root
188+
target: /
189+
- name: boot
190+
type: org.osbuild.ext4
191+
source: boot
192+
target: /boot
193+
- name: efi
194+
type: org.osbuild.fat
195+
source: efi
196+
target: /boot/efi
197+
- type: org.osbuild.grub2.inst
198+
options:
199+
platform: i386-pc
200+
filename: disk.img
201+
location:
202+
mpp-format-int: '{image.layout[''BIOS-BOOT''].start}'
203+
core:
204+
type: mkimage
205+
partlabel: gpt
206+
filesystem: ext4
207+
prefix:
208+
type: partition
209+
partlabel:
210+
mpp-format-string: '{image.layout.label}'
211+
number:
212+
mpp-format-int: '{image.layout[''boot''].index}'
213+
path: /grub2
214+
- name: qcow2
215+
stages:
216+
- type: org.osbuild.qemu
217+
inputs:
218+
image:
219+
type: org.osbuild.files
220+
origin: org.osbuild.pipeline
221+
references:
222+
name:image:
223+
file: disk.img
224+
options:
225+
filename: disk.qcow2
226+
format:
227+
type: qcow2
228+
compat: '1.1'

src/deps.txt

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ dumb-init
1616
rpm-ostree createrepo_c openssh-clients python3-createrepo_c
1717
dnf-utils
1818

19-
# We don't actually use this right now but we intend to share
20-
# code in the future.
21-
# XXX: temporarily disabled until we fix
22-
# https://github.com/osbuild/osbuild-composer/issues/1915
23-
# osbuild-composer
24-
2519
# For generating ISO images
2620
genisoimage
2721

src/runvm-osbuild

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -eux -o pipefail
3+
4+
repo=$1
5+
ref=$2
6+
mppyaml=$3
7+
path=$4
8+
9+
workdir=$PWD
10+
11+
# Since it doesn't exist create loop-control
12+
mknod /dev/loop-control c 10 237
13+
14+
# get away from the virtiofs share because the xattrs that
15+
# are written out by the ostree deploy will cause SELinux denials.
16+
mkdir /root/osbuild && cd /root/osbuild
17+
18+
# Use osbuild from the dusty-fedora-coreos fork for now
19+
git clone https://github.com/dustymabe/osbuild.git --branch dusty-fedora-coreos .
20+
21+
# Run through the preprocessor
22+
./tools/osbuild-mpp \
23+
-D ref=\"${ref}\" \
24+
-D repourl=\"file://${repo}\" \
25+
$mppyaml \
26+
processed.json
27+
28+
# Build the image
29+
python3 -m osbuild --libdir . \
30+
--store store/ --output-directory out/ \
31+
--export qcow2 processed.json
32+
33+
34+
# Copy it out to the specified location
35+
cp out/qcow2/disk.qcow2 $path

src/vmdeps.txt

+4
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ tar
3535

3636
# needed for extensions container build
3737
podman
38+
39+
# For running osbuild
40+
osbuild osbuild-ostree osbuild-selinux osbuild-tools python3-pyrsistent
41+
patch git

0 commit comments

Comments
 (0)