@@ -23,6 +23,10 @@ from cosalib.cmdlib import runcmd, sha256sum_file
23
23
from cosalib .cmdlib import import_ostree_commit , get_basearch , ensure_glob
24
24
from cosalib .meta import GenericBuildMeta
25
25
26
+ from pathlib import Path
27
+
28
+ COSA_USE_LIVEISO = os .getenv ("COSA_USE_LIVEISO" , "" )
29
+
26
30
live_exclude_kargs = set ([
27
31
'$ignition_firstboot' , # unsubstituted variable in grub config
28
32
'console' , # no serial console by default on ISO
@@ -91,42 +95,69 @@ name_version = f'{base_name}-{args.build}'
91
95
# to shorten this more intelligently, otherwise we truncate the
92
96
# version which may impede uniqueness.
93
97
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
+ })
94
157
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 } " )
119
160
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
130
161
def align_initrd_for_uncompressed_append (destf ):
131
162
offset = destf .tell ()
132
163
if offset % 4 :
@@ -214,6 +245,42 @@ def make_stream_hash(src, dest):
214
245
215
246
216
247
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
217
284
# convention for kernel and initramfs names
218
285
kernel_img = 'vmlinuz'
219
286
initrd_img = 'initrd.img'
@@ -765,12 +832,6 @@ boot
765
832
})
766
833
shutil .move (tmpisofile , f"{ builddir } /{ iso_name } " )
767
834
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 )
774
835
shutil .copyfile (os .path .join (tmpisoimagespxe , kernel_img ), kernel_file )
775
836
shutil .move (pxe_initramfs , initramfs_file )
776
837
shutil .move (pxe_rootfs , rootfs_file )
@@ -801,7 +862,21 @@ with open(build_semaphore, 'w') as f:
801
862
f .write (f"{ time .time_ns ()} " )
802
863
803
864
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 ()
805
880
finally :
806
881
if os .path .exists (build_semaphore ):
807
882
os .unlink (build_semaphore )
0 commit comments