1
0
mirror of https://github.com/openSUSE/osc.git synced 2026-01-09 08:17:04 +01:00

Return preinstallimage.info and allow podman to use preinstallimage

Download and return preinstallimage.info if preinstallimage exists to
be able to check the list of packages in preinstallimage without unpacking
it in build environment.
Download preinstallimage and preinstallimage.info in a unique named
temp file first.
Allow podman to use preinstallimage to speed up the build process
This commit is contained in:
Mahdiyeh Mirsharifi
2025-08-26 10:54:10 +03:00
committed by Maya Mirsharifi
parent 141157e0cd
commit 57bdcf2ef3

View File

@@ -325,8 +325,9 @@ def get_preinstall_image(apiurl, arch, cache_dir, img_info, offline=False):
.. note::
preinstall image can be used only for new build roots!
"""
imagefile = ''
imagesource = ''
imagefile = ""
imagesource = ""
info_file = "preinstallimage.info"
img_bins = []
for bin in img_info.findall('binary'):
img_bins.append(bin.text)
@@ -339,16 +340,17 @@ def get_preinstall_image(apiurl, arch, cache_dir, img_info, offline=False):
img_hdrmd5 = img_info.get('hdrmd5')
if not img_hdrmd5:
img_hdrmd5 = img_file
cache_path = '%s/%s/%s/%s' % (cache_dir, img_project, img_repository, img_arch)
ifile_path = '%s/%s' % (cache_path, img_file)
ifile_path_part = '%s.part' % ifile_path
cache_path = "%s/%s/%s/%s" % (cache_dir, img_project, img_repository, img_arch)
ifile_path = "%s/%s" % (cache_path, img_file)
info_file_path = "%s/%s" % (cache_path, info_file)
imagefile = ifile_path
imagesource = "%s/%s/%s [%s]" % (img_project, img_repository, img_pkg, img_hdrmd5)
imageinfo = info_file_path
if not os.path.exists(ifile_path):
if offline:
return '', '', []
return "", "", "", []
url = "%s/build/%s/%s/%s/%s/%s" % (apiurl, img_project, img_repository, img_arch, img_pkg, img_file)
print("downloading preinstall image %s" % imagesource)
if not os.path.exists(cache_path):
@@ -362,14 +364,34 @@ def get_preinstall_image(apiurl, arch, cache_dir, img_info, offline=False):
if sys.stdout.isatty():
progress_obj = create_text_meter(use_pb_fallback=False)
gr = OscFileGrabber(progress_obj=progress_obj)
try:
gr.urlgrab(url, filename=ifile_path_part, text='fetching image')
except HTTPError as e:
print("Failed to download! ecode:%i reason:%s" % (e.code, e.reason))
return ('', '', [])
# download ok, rename partial file to final file name
os.rename(ifile_path_part, ifile_path)
return (imagefile, imagesource, img_bins)
with NamedTemporaryFile(dir=cache_path, delete=False) as temp_file:
try:
gr.urlgrab(url, filename=temp_file.name, text="fetching image")
# download ok, rename temp file to final file name
os.rename(temp_file.name, ifile_path)
except HTTPError as e:
print("Failed to download! ecode:%i reason:%s" % (e.code, e.reason))
# Clean up temp file if it still exists
if os.path.exists(temp_file.name):
os.unlink(temp_file.name)
return ("", "", "", [])
# Also download the corresponding .info file
if not os.path.exists(info_file_path):
info_url = "%s/build/%s/%s/%s/%s/%s" % (apiurl, img_project, img_repository, img_arch, img_pkg, info_file)
print("downloading preinstall image info file")
with NamedTemporaryFile(dir=cache_path, delete=False) as temp_file:
try:
gr.urlgrab(info_url, filename=temp_file.name, text="fetching image info")
# download ok, rename temp file to final file name
os.rename(temp_file.name, info_file_path)
except HTTPError as e:
print("Failed to download info file! ecode:%i reason:%s" % (e.code, e.reason))
# Clean up temp file if it still exists
if os.path.exists(temp_file.name):
os.unlink(temp_file.name)
return (imagefile, imagesource, imageinfo, img_bins)
def get_built_files(pacdir, buildtype):
@@ -1188,23 +1210,40 @@ def main(apiurl, store, opts, argv):
# implicitly trust the project we are building for
check_trusted_projects(apiurl, [i for i in bi.projects.keys() if not i == prj])
imagefile = ''
imagesource = ''
imagefile = ""
imagesource = ""
imageinfo = ""
imagebins = []
if build_as_user(vm_type):
# Check if using container preinstallimage for podman
using_container_preinstall = (
vm_type == "podman"
and opts.build_opt
and any("--vm-use-container-preinstallimage" in opt for opt in opts.build_opt)
)
if build_as_user(vm_type) and not using_container_preinstall:
# preinstallimage extraction will fail because unprivileged user cannot chroot or extract devices from the tarball
bi.preinstallimage = None
if build_type == 'preinstallimage':
# preinstallimage would repackage just the previously built preinstallimage
bi.preinstallimage = None
if (not config['no_preinstallimage'] and not opts.nopreinstallimage and
bi.preinstallimage and
not opts.noinit and
(opts.clean or (not os.path.exists(build_root + "/installed-pkg") and
not os.path.exists(build_root + "/.build/init_buildsystem.data")))):
(imagefile, imagesource, imagebins) = get_preinstall_image(apiurl, arch, cache_dir, bi.preinstallimage,
opts.offline)
if (
not config["no_preinstallimage"]
and not opts.nopreinstallimage
and bi.preinstallimage
and not opts.noinit
and (
opts.clean
or (
not os.path.exists(build_root + "/installed-pkg")
and not os.path.exists(build_root + "/.build/init_buildsystem.data")
)
)
):
(imagefile, imagesource, imageinfo, imagebins) = get_preinstall_image(
apiurl, arch, cache_dir, bi.preinstallimage, opts.offline
)
if imagefile:
# remove binaries from build deps which are included in preinstall image
for i in bi.deps:
@@ -1495,9 +1534,11 @@ def main(apiurl, store, opts, argv):
rpmlist += ["%s %s\n" % (i[0], i[1]) for i in rpmlist_prefers]
if imagefile:
rpmlist.append('preinstallimage: %s\n' % imagefile)
rpmlist.append(f"preinstallimage: {imagefile}\n")
if imagesource:
rpmlist.append('preinstallimagesource: %s\n' % imagesource)
rpmlist.append(f"preinstallimagesource: {imagesource}\n")
if imageinfo:
rpmlist.append(f"preinstallimageinfo: {imageinfo}\n")
rpmlist.append('preinstall: ' + ' '.join(bi.preinstall_list) + '\n')
rpmlist.append('vminstall: ' + ' '.join(bi.vminstall_list) + '\n')