Skip to content

Commit 4bbcf0a

Browse files
committed
buildextend-live: Add support OSBUILD
- Add support for OSBUILD via COSA_USE_LIVEISO env var for now Signed-off-by: Renata Ravanelli <[email protected]>
1 parent daa7046 commit 4bbcf0a

File tree

1 file changed

+116
-41
lines changed

1 file changed

+116
-41
lines changed

src/cmd-buildextend-live

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ from cosalib.cmdlib import runcmd, sha256sum_file
2323
from cosalib.cmdlib import import_ostree_commit, get_basearch, ensure_glob
2424
from cosalib.meta import GenericBuildMeta
2525

26+
from pathlib import Path
27+
28+
COSA_USE_LIVEISO = os.getenv("COSA_USE_LIVEISO", "")
29+
2630
live_exclude_kargs = set([
2731
'$ignition_firstboot', # unsubstituted variable in grub config
2832
'console', # no serial console by default on ISO
@@ -91,42 +95,69 @@ name_version = f'{base_name}-{args.build}'
9195
# to shorten this more intelligently, otherwise we truncate the
9296
# version which may impede uniqueness.
9397
volid = name_version[0:32]
98+
build_path = Path(f"./{builddir}/{base_name}-{args.build}").resolve()
99+
kernel_name = f'{base_name}-{args.build}-live-kernel-{basearch}'
100+
initramfs_name = f'{base_name}-{args.build}-live-initramfs.{basearch}.img'
101+
rootfs_name = f'{base_name}-{args.build}-live-rootfs.{basearch}.img'
102+
kernel_file = os.path.join(builddir, kernel_name)
103+
initramfs_file = os.path.join(builddir, initramfs_name)
104+
rootfs_file = os.path.join(builddir, rootfs_name)
105+
106+
data = {
107+
"buildid": args.build,
108+
"imgid": iso_name,
109+
"ostree-commit": buildmeta_commit,
110+
"container-imgref": "",
111+
"deploy-via-container": "",
112+
"osname": base_name,
113+
"ostree-ref": args.build,
114+
"ostree-container": f"{build_path}-ostree.{basearch}.ociarchive",
115+
"metal-filename": f"{build_path}-metal.{basearch}.raw",
116+
"metal4k-filename": f"{build_path}-metal4k.{basearch}.raw",
117+
"ostree-repo": repo,
118+
"extra-kargs-string": "mitigations=auto,nosmt",
119+
"image-type": "live-iso",
120+
"cloud-image-size": "10240",
121+
"metal-image-size": "2405",
122+
"squashfs-compression": squashfs_compression,
123+
"rootfs-size": 0,
124+
"live-efiboot-img-size": 16
125+
}
126+
127+
image_for_disk_json = "runvm.json"
128+
with open(image_for_disk_json, 'w') as file:
129+
json.dump(data, file, indent=4)
130+
131+
132+
def update_buildmeta():
133+
buildmeta['images'].update({
134+
'live-iso': {
135+
'path': iso_name,
136+
'sha256': sha256sum_file(tmpisofile),
137+
'skip-compression': True,
138+
}
139+
})
140+
buildmeta['images'].update({
141+
'live-kernel': {
142+
'path': kernel_name,
143+
'sha256': sha256sum_file(kernel_file),
144+
'skip-compression': True,
145+
},
146+
'live-initramfs': {
147+
'path': initramfs_name,
148+
'sha256': sha256sum_file(initramfs_file),
149+
'skip-compression': True,
150+
},
151+
'live-rootfs': {
152+
'path': rootfs_name,
153+
'sha256': sha256sum_file(rootfs_file),
154+
'skip-compression': True,
155+
}
156+
})
94157

95-
tmpdir = os.environ.get("FORCE_TMPDIR", f"{workdir}/tmp/buildpost-live")
96-
if os.path.isdir(tmpdir):
97-
shutil.rmtree(tmpdir)
98-
99-
tmpisoroot = os.path.join(tmpdir, 'live')
100-
tmpisocoreos = os.path.join(tmpisoroot, 'coreos')
101-
tmpisoimages = os.path.join(tmpisoroot, 'images')
102-
tmpisoimagespxe = os.path.join(tmpisoimages, 'pxeboot')
103-
tmpisoisolinux = os.path.join(tmpisoroot, 'isolinux')
104-
# contents of initramfs on both PXE and ISO
105-
tmpinitrd_base = os.path.join(tmpdir, 'initrd')
106-
# contents of rootfs image
107-
tmpinitrd_rootfs = os.path.join(tmpdir, 'initrd-rootfs')
108-
109-
for d in (tmpdir, tmpisoroot, tmpisocoreos, tmpisoimages, tmpisoimagespxe,
110-
tmpisoisolinux, tmpinitrd_base, tmpinitrd_rootfs):
111-
os.mkdir(d)
112-
113-
# Size of file used to embed an Ignition config within a CPIO.
114-
ignition_img_size = 256 * 1024
115-
116-
# Size of the file used to embed miniso data.
117-
miniso_data_file_size = 16 * 1024
118-
158+
buildmeta.write(artifact_name='live')
159+
print(f"Updated: {buildmeta_path}")
119160

120-
# The kernel requires that uncompressed cpio archives appended to an initrd
121-
# start on a 4-byte boundary. If there's misalignment, it stops unpacking
122-
# and says:
123-
#
124-
# Initramfs unpacking failed: invalid magic at start of compressed archive
125-
#
126-
# Append NUL bytes to destf until its size is a multiple of 4 bytes.
127-
#
128-
# https://www.kernel.org/doc/Documentation/early-userspace/buffer-format.txt
129-
# https://github.com/torvalds/linux/blob/47ec5303/init/initramfs.c#L463
130161
def align_initrd_for_uncompressed_append(destf):
131162
offset = destf.tell()
132163
if offset % 4:
@@ -214,6 +245,42 @@ def make_stream_hash(src, dest):
214245

215246

216247
def generate_iso():
248+
249+
tmpdir = os.environ.get("FORCE_TMPDIR", f"{workdir}/tmp/buildpost-live")
250+
if os.path.isdir(tmpdir):
251+
shutil.rmtree(tmpdir)
252+
253+
tmpisoroot = os.path.join(tmpdir, 'live')
254+
tmpisocoreos = os.path.join(tmpisoroot, 'coreos')
255+
tmpisoimages = os.path.join(tmpisoroot, 'images')
256+
tmpisoimagespxe = os.path.join(tmpisoimages, 'pxeboot')
257+
tmpisoisolinux = os.path.join(tmpisoroot, 'isolinux')
258+
# contents of initramfs on both PXE and ISO
259+
tmpinitrd_base = os.path.join(tmpdir, 'initrd')
260+
# contents of rootfs image
261+
tmpinitrd_rootfs = os.path.join(tmpdir, 'initrd-rootfs')
262+
263+
for d in (tmpdir, tmpisoroot, tmpisocoreos, tmpisoimages, tmpisoimagespxe,
264+
tmpisoisolinux, tmpinitrd_base, tmpinitrd_rootfs):
265+
os.mkdir(d)
266+
267+
# Size of file used to embed an Ignition config within a CPIO.
268+
ignition_img_size = 256 * 1024
269+
270+
# Size of the file used to embed miniso data.
271+
miniso_data_file_size = 16 * 1024
272+
273+
274+
# The kernel requires that uncompressed cpio archives appended to an initrd
275+
# start on a 4-byte boundary. If there's misalignment, it stops unpacking
276+
# and says:
277+
#
278+
# Initramfs unpacking failed: invalid magic at start of compressed archive
279+
#
280+
# Append NUL bytes to destf until its size is a multiple of 4 bytes.
281+
#
282+
# https://www.kernel.org/doc/Documentation/early-userspace/buffer-format.txt
283+
# https://github.com/torvalds/linux/blob/47ec5303/init/initramfs.c#L463
217284
# convention for kernel and initramfs names
218285
kernel_img = 'vmlinuz'
219286
initrd_img = 'initrd.img'
@@ -765,12 +832,6 @@ boot
765832
})
766833
shutil.move(tmpisofile, f"{builddir}/{iso_name}")
767834

768-
kernel_name = f'{base_name}-{args.build}-live-kernel-{basearch}'
769-
initramfs_name = f'{base_name}-{args.build}-live-initramfs.{basearch}.img'
770-
rootfs_name = f'{base_name}-{args.build}-live-rootfs.{basearch}.img'
771-
kernel_file = os.path.join(builddir, kernel_name)
772-
initramfs_file = os.path.join(builddir, initramfs_name)
773-
rootfs_file = os.path.join(builddir, rootfs_name)
774835
shutil.copyfile(os.path.join(tmpisoimagespxe, kernel_img), kernel_file)
775836
shutil.move(pxe_initramfs, initramfs_file)
776837
shutil.move(pxe_rootfs, rootfs_file)
@@ -801,7 +862,21 @@ with open(build_semaphore, 'w') as f:
801862
f.write(f"{time.time_ns()}")
802863

803864
try:
804-
generate_iso()
865+
if COSA_USE_LIVEISO is None:
866+
generate_iso()
867+
else:
868+
command = [
869+
"/usr/bin/cosa", "supermin-run",
870+
"--cache", "/usr/lib/coreos-assembler/runvm-osbuild",
871+
"--config",
872+
image_for_disk_json,
873+
"--mpp",
874+
f"/usr/lib/coreos-assembler/osbuild-manifests/coreos.osbuild.{basearch}.mpp.yaml",
875+
"--filepath",
876+
tmpisofile
877+
]
878+
subprocess.run(command)
879+
update_buildmeta()
805880
finally:
806881
if os.path.exists(build_semaphore):
807882
os.unlink(build_semaphore)

0 commit comments

Comments
 (0)