build-rootfs: support injecting content manifests

In RHCOS today, cosa injects a content manifest at build time, which is
a JSON file describing the repos used to assemble the system. Lift the
related logic from cosa and re-implement it here.
This commit is contained in:
Jonathan Lebon 2025-06-16 14:24:01 -04:00 committed by Dusty Mabe
parent 6afe93f10c
commit f0c2728ac2
3 changed files with 37 additions and 0 deletions

View file

@ -28,6 +28,7 @@ ARG MANIFEST
# add this bit to the RUN command to make the developer path less painful.
# --mount=type=cache,rw,id=coreos-build-cache,target=/cache
RUN --mount=type=secret,id=yumrepos,target=/etc/yum.repos.d/secret.repo \
--mount=type=secret,id=contentsets \
--mount=type=bind,target=/run/src \
/run/src/build-rootfs "${MANIFEST}" "${VERSION}" /target-rootfs

View file

@ -13,6 +13,7 @@ ARG MANIFEST
# add this bit to the RUN command to make the developer path less painful.
# --mount=type=cache,rw,id=coreos-build-cache,target=/cache
RUN --mount=type=secret,id=yumrepos,target=/etc/yum.repos.d/secret.repo \
--mount=type=secret,id=contentsets \
--mount=type=bind,target=/run/src \
/run/src/build-rootfs "${MANIFEST}" "${VERSION}" /target-rootfs

View file

@ -42,6 +42,7 @@ def main():
inject_live(target_rootfs)
inject_image_json(target_rootfs, manifest_path)
inject_platforms_json(target_rootfs)
inject_content_manifest(target_rootfs, manifest)
if version != "":
inject_version_info(target_rootfs, manifest['mutate-os-release'], version)
@ -176,6 +177,40 @@ def inject_image_json(rootfs, manifest_path):
json.dump(image, f, sort_keys=True)
def inject_content_manifest(target_rootfs, manifest):
content_manifest_path = '/run/secrets/contentsets'
if not os.path.exists(content_manifest_path):
return
with open(content_manifest_path) as f:
data = yaml.safe_load(f)
repos = []
for base_repo in manifest['repos']:
if base_repo in data['repo_mapping']:
if data['repo_mapping'][base_repo]['name'] != '':
repo_name = data['repo_mapping'][base_repo]['name'].replace('$ARCH', ARCH)
repos.append(repo_name)
else:
print('Warning: No corresponding repo in repository-to-cpe.json for ' + base_repo)
else:
# Warning message for repositories with no entry in content_sets.yaml
print('Warning: No corresponding entry in content_sets.yaml for ' + base_repo)
dest = os.path.join(target_rootfs, "usr/share/buildinfo/content_manifest.json")
os.makedirs(os.path.dirname(dest), exist_ok=True)
with open(dest, 'w') as f:
json.dump(fp=f, obj={
'metadata': {
'icm_version': 1,
'icm_spec': 'https://raw.githubusercontent.com/containerbuildsystem/atomic-reactor/master/atomic_reactor/schemas/content_manifest.json',
'image_layer_index': 1
},
'content_sets': repos,
'image_contents': []
})
# Imported from cosa
# Merge two lists, avoiding duplicates. Exact duplicate kargs could be valid
# but we have no use case for them right now in our official images.