fix: preserve installed helpers, adaptations and inventory provenance
This commit is contained in:
+33
-10
@@ -212,14 +212,16 @@ if path.exists():
|
||||
if not entry.get('complete') or entry.get('inputs') != self.input_id():
|
||||
return False
|
||||
if step in ('rootfs', 'iso'):
|
||||
from . import image
|
||||
from hydra import image
|
||||
if entry.get('source_inputs') != image.source_identity(self.source_dir):
|
||||
return False
|
||||
if not image.artifacts_valid(self.work / 'artifacts', entry):
|
||||
return False
|
||||
return self.complete('packages' if step == 'rootfs' else 'rootfs')
|
||||
if step == 'packages':
|
||||
if not (self.work / 'artifacts/packages.json').is_file():
|
||||
try:
|
||||
self.package_inventory()
|
||||
except (BuildError, OSError):
|
||||
return False
|
||||
return self.complete('prepare')
|
||||
if step == 'prepare':
|
||||
@@ -244,6 +246,16 @@ if path.exists():
|
||||
return True
|
||||
return False
|
||||
|
||||
def package_inventory(self):
|
||||
from hydra import image
|
||||
checksum = self.manifest().get('packages', {}).get('inventory_sha256')
|
||||
if not isinstance(checksum, str) or not re.fullmatch('[a-f0-9]{64}', checksum):
|
||||
raise BuildError('Package inventory has no recorded checksum')
|
||||
try:
|
||||
return image.read_package_inventory(self.work / 'artifacts/packages.json', checksum)
|
||||
except (image.ImageError, OSError) as error:
|
||||
raise BuildError(f'Package inventory validation failed: {error}') from error
|
||||
|
||||
def download(self, url, filename=None):
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
if parsed.scheme != 'https':
|
||||
@@ -345,8 +357,17 @@ fi'''
|
||||
if self.input_id() != inputs:
|
||||
raise BuildError('Image inputs changed during package installation; completion was not recorded')
|
||||
inventory = self.exec('cat /var/lib/hydra-build/packages.json', capture=True).stdout
|
||||
(self.work / 'artifacts/packages.json').write_text(inventory)
|
||||
self.record('packages', inventory='artifacts/packages.json', patched_source=patch_id)
|
||||
from hydra import image
|
||||
try:
|
||||
image.validate_package_inventory(json.loads(inventory))
|
||||
except (ValueError, image.ImageError) as error:
|
||||
raise BuildError(f'Package inventory is malformed: {error}') from error
|
||||
target = self.work / 'artifacts/packages.json'
|
||||
temporary = target.with_suffix('.tmp')
|
||||
temporary.write_text(inventory)
|
||||
temporary.replace(target)
|
||||
self.record('packages', inventory='artifacts/packages.json', patched_source=patch_id,
|
||||
inventory_sha256=image.digest(target))
|
||||
|
||||
def assembly(self, snapshot_digest=None):
|
||||
"""A separate rootless container processes an exported copy, never the builder."""
|
||||
@@ -378,7 +399,7 @@ fi'''
|
||||
return name
|
||||
|
||||
def rootfs(self):
|
||||
from . import image
|
||||
from hydra import image
|
||||
if self.active_package_job():
|
||||
raise BuildError('A contained package job is running; wait before export')
|
||||
if not self.complete('packages'):
|
||||
@@ -412,15 +433,17 @@ chmod 0644 /hydra-output/artifacts/vmlinuz /hydra-output/artifacts/initramfs-liv
|
||||
if image.source_identity(self.source_dir) != source_inputs:
|
||||
raise BuildError('Source inputs changed during rootfs assembly; completion not recorded')
|
||||
manifest = json.loads((self.work / 'artifacts/rootfs-manifest.json').read_text())
|
||||
if not manifest.get('packages') or manifest.get('source_files') != image.source_files(self.source_dir):
|
||||
raise BuildError('Payload inventory/source manifest is incomplete or stale')
|
||||
if manifest.get('packages') != self.package_inventory():
|
||||
raise BuildError('Payload package inventory differs from the validated package checkpoint')
|
||||
if manifest.get('source_files') != image.source_files(self.source_dir):
|
||||
raise BuildError('Payload source manifest is incomplete or stale')
|
||||
artifacts = {name: image.digest(self.work / 'artifacts' / name) for name in
|
||||
('vmlinuz', 'initramfs-live.img', 'squashfs.img', 'rootfs-manifest.json')}
|
||||
('vmlinuz', 'initramfs-live.img', 'squashfs.img', 'rootfs-manifest.json', 'packages.json')}
|
||||
self.record('rootfs', source_inputs=source_inputs, snapshot_sha256=snapshot,
|
||||
assembler=assembler, kernel=manifest['kernel'], artifacts=artifacts)
|
||||
|
||||
def iso(self):
|
||||
from . import image
|
||||
from hydra import image
|
||||
if not self.complete('rootfs'):
|
||||
raise BuildError('Verified rootfs artifacts are required before ISO assembly')
|
||||
if self.complete('iso'):
|
||||
@@ -450,7 +473,7 @@ chmod 0644 /hydra-output/artifacts/hydra-os.iso /hydra-output/artifacts/iso-insp
|
||||
checksum = image.digest(self.work / 'artifacts/hydra-os.iso')
|
||||
(self.work / 'artifacts/hydra-os.iso.sha256').write_text(checksum + ' hydra-os.iso\n')
|
||||
artifacts = {name: image.digest(self.work / 'artifacts' / name) for name in
|
||||
('hydra-os.iso', 'hydra-os.iso.sha256', 'iso-inspection.txt')}
|
||||
('hydra-os.iso', 'hydra-os.iso.sha256', 'iso-inspection.txt', 'packages.json')}
|
||||
self.record('iso', source_inputs=source_inputs, label=image.LABEL, artifacts=artifacts)
|
||||
|
||||
def status(self):
|
||||
|
||||
Reference in New Issue
Block a user