add in primary_variant to do further linking if necessary

This commit is contained in:
Louis Abel 2022-11-12 19:34:53 -07:00
parent d028b28d63
commit d98c4ee01b
Signed by untrusted user: label
GPG Key ID: B37E62D143879B36
2 changed files with 121 additions and 82 deletions

View File

@ -77,12 +77,15 @@
Azure:
format: vhd
variants: [Base, LVM]
primary_variant: 'Base'
EC2:
format: raw
variants: [Base, LVM]
primary_variant: 'Base'
GenericCloud:
format: qcow2
variants: [Base, LVM]
primary_variant: 'Base'
Container:
format: tar.xz
variants: [Base, Minimal, UBI]

View File

@ -1366,6 +1366,8 @@ class IsoBuild:
formattype = extra['format']
variants = extra['variants'] if 'variants' in extra.keys() else [None] # need to loop once
imagename = name
primary_variant = extra['primary_variant'] if 'primary_variant' in extra else None
latest_artifacts = []
for variant in variants:
@ -1398,18 +1400,19 @@ class IsoBuild:
continue
self.log.info(Color.INFO + 'Attempting to download requested artifacts')
for item in latest_artifacts:
for arch in arches_to_unpack:
image_arch_dir = os.path.join(
self.image_work_dir,
arch
)
if arch not in latest_artifacts.keys():
if arch not in item.keys():
self.log.warn(Color.WARN + 'Artifact for ' + name +
' ' + arch + ' (' + formattype + ') does not exist.')
continue
source_path = latest_artifacts[arch]
source_path = item[arch]
drop_name = source_path.split('/')[-1]
checksum_name = drop_name + '.CHECKSUM'
full_drop = '{}/{}'.format(
@ -1470,6 +1473,24 @@ class IsoBuild:
arch,
formattype
)
# If an image is the primary, we set this.
latest_primary_name = '{}/{}-{}-{}.latest.{}.{}'.format(
image_arch_dir,
self.shortname,
self.major_version,
imagename,
arch,
formattype
)
latest_primary_checksum = '{}/{}-{}-{}.latest.{}.{}.CHECKSUM'.format(
image_arch_dir,
self.shortname,
self.major_version,
imagename,
arch,
formattype
)
latest_primary_path = latest_name.split('/')[-1]
# For some reason python doesn't have a "yeah just change this
# link" part of the function
if os.path.exists(latest_name):
@ -1488,6 +1509,21 @@ class IsoBuild:
link.write(checkdata)
link.close()
# If this is the primary image, set the appropriate symlink
# and checksum
if primary_variant and primary_variant in drop_name:
self.log.info('This is the primary image, setting link and checksum')
if os.path.exists(latest_primary_name):
os.remove(latest_primary_name)
os.symlink(drop_name, latest_primary_name)
shutil.copy2(checksum_drop, latest_primary_checksum)
with open(latest_primary_checksum) as link:
checkpdata = link.read()
checkpdata = checkpdata.replace(drop_name, latest_primary_path)
with open(latest_primary_checksum, 'w+') as link:
link.write(checkpdata)
link.close()
self.log.info(Color.INFO + 'Image download phase completed')