Skip to content

Commit 543fdf6

Browse files
committed
buildextend-live: Add OSBUILD support
- Add support for OSBUILD via COSA_OSBUILD_LIVEISO env var for now. Once we finish the OSBUILD integration we can disable it via var. Signed-off-by: Renata Ravanelli <[email protected]>
1 parent a54a683 commit 543fdf6

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

src/cmd-buildextend-live

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ IGNITION_IMG_SIZE = 256 * 1024
2929
# Size of the file used to embed miniso data.
3030
MINISO_DATA_FILE_SIZE = 16 * 1024
3131

32+
COSA_OSBUILD_LIVEISO = os.getenv("COSA_OSBUILD_LIVEISO", "")
33+
3234
live_exclude_kargs = set([
3335
'$ignition_firstboot', # unsubstituted variable in grub config
3436
'console', # no serial console by default on ISO
@@ -97,12 +99,39 @@ name_version = f'{base_name}-{args.build}'
9799
# to shorten this more intelligently, otherwise we truncate the
98100
# version which may impede uniqueness.
99101
volid = name_version[0:32]
102+
build_path = os.path.abspath(f"{builddir}/{base_name}-{args.build}")
100103
kernel_name = f'{base_name}-{args.build}-live-kernel-{basearch}'
101104
initramfs_name = f'{base_name}-{args.build}-live-initramfs.{basearch}.img'
102105
rootfs_name = f'{base_name}-{args.build}-live-rootfs.{basearch}.img'
103106
kernel_file = os.path.join(builddir, kernel_name)
104107
initramfs_file = os.path.join(builddir, initramfs_name)
105108
rootfs_file = os.path.join(builddir, rootfs_name)
109+
110+
if COSA_OSBUILD_LIVEISO != "":
111+
data = {
112+
"buildid": args.build,
113+
"imgid": iso_name,
114+
"ostree-commit": buildmeta_commit,
115+
"container-imgref": "",
116+
"deploy-via-container": "",
117+
"osname": base_name,
118+
"ostree-ref": args.build,
119+
"ostree-container": f"{build_path}-ostree.{basearch}.ociarchive",
120+
"metal-filename": f"{build_path}-metal.{basearch}.raw",
121+
"metal4k-filename": f"{build_path}-metal4k.{basearch}.raw",
122+
"ostree-repo": repo,
123+
"extra-kargs-string": "mitigations=auto,nosmt",
124+
"image-type": "live-iso",
125+
"cloud-image-size": "10240",
126+
"metal-image-size": "2405",
127+
"squashfs-compression": squashfs_compression,
128+
"rootfs-size": 0,
129+
"live-efiboot-img-size": 16
130+
}
131+
132+
image_for_disk_json = "runvm.json"
133+
with open(image_for_disk_json, 'w') as file:
134+
json.dump(data, file, indent=4)
106135
# The kernel requires that uncompressed cpio archives appended to an initrd
107136
# start on a 4-byte boundary. If there's misalignment, it stops unpacking
108137
# and says:
@@ -119,6 +148,35 @@ def align_initrd_for_uncompressed_append(destf):
119148
destf.write(b'\0' * (4 - offset % 4))
120149

121150

151+
def update_buildmeta():
152+
buildmeta['images'].update({
153+
'live-iso': {
154+
'path': iso_name,
155+
'sha256': sha256sum_file(tmpisofile),
156+
'skip-compression': True,
157+
}
158+
})
159+
buildmeta['images'].update({
160+
'live-kernel': {
161+
'path': kernel_name,
162+
'sha256': sha256sum_file(kernel_file),
163+
'skip-compression': True,
164+
},
165+
'live-initramfs': {
166+
'path': initramfs_name,
167+
'sha256': sha256sum_file(initramfs_file),
168+
'skip-compression': True,
169+
},
170+
'live-rootfs': {
171+
'path': rootfs_name,
172+
'sha256': sha256sum_file(rootfs_file),
173+
'skip-compression': True,
174+
}
175+
})
176+
buildmeta.write(artifact_name='live')
177+
print(f"Updated: {buildmeta_path}")
178+
179+
122180
# Return OS features table for features.json, which is read by
123181
# coreos-installer {iso|pxe} customize
124182
def get_os_features():
@@ -798,7 +856,24 @@ with open(build_semaphore, 'w') as f:
798856
f.write(f"{time.time_ns()}")
799857

800858
try:
801-
generate_iso()
859+
if COSA_OSBUILD_LIVEISO == "":
860+
generate_iso()
861+
else:
862+
command = [
863+
"/usr/bin/cosa", "supermin-run",
864+
"--cache", "/usr/lib/coreos-assembler/runvm-osbuild",
865+
"--config",
866+
image_for_disk_json,
867+
"--mpp",
868+
f"/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.{basearch}.mpp.yaml",
869+
"--filepath",
870+
tmpisofile
871+
]
872+
subprocess.run(command)
873+
update_buildmeta()
874+
# Extract live artifacts from ISO. OSBUILD does not support an output with multiple files
875+
command = ["coreos-installer", "iso", "extract", "pxe", tmpisofile]
876+
subprocess.run(command)
802877
finally:
803878
if os.path.exists(build_semaphore):
804879
os.unlink(build_semaphore)

0 commit comments

Comments
 (0)