Skip to content

Commit

Permalink
oscontainer: add com.coreos.rpm.* labels
Browse files Browse the repository at this point in the history
These labels allow one to query the RPM version of a subset of packages
without having to download them. See also:

openshift/os#409 (comment)
  • Loading branch information
jlebon committed Jan 28, 2021
1 parent 420d25f commit 9c2e79a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/oscontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
# https://access.redhat.com/documentation/en-us/openshift_container_platform/4.1/html/builds/custom-builds-buildah
NESTED_BUILD_ARGS = ['--storage-driver', 'vfs']

# These packages have their versions as labels
IMPORTANT_PACKAGES = ['kernel', 'kernel-rt', 'systemd', 'ignition', 'ostree',
'rpm-ostree', 'runc', 'strace']


def run_get_json(args):
return json.loads(subprocess.check_output(args))
Expand Down Expand Up @@ -159,11 +163,16 @@ def oscontainer_build(containers_storage, tmpdir, src, ref, image_name_and_tag,
if ostree_version is not None:
config += ['-l', 'version=' + ostree_version]

base_pkgs = RpmOstree.db_query_all(r, rev, None)
for pkg in base_pkgs:
name = pkg.get_name()
if name in IMPORTANT_PACKAGES:
config += ['-l', f"com.coreos.rpm.{name}={pkg.get_evr()}.{pkg.get_arch()}"]

# Generate pkglist.txt in to the oscontainer at /
pkg_list_dest = os.path.join(mnt, 'pkglist.txt')
pkgs = RpmOstree.db_query_all(r, rev, None)
# should already be sorted, but just re-sort to be sure
nevras = sorted([pkg.get_nevra() for pkg in pkgs])
nevras = sorted([pkg.get_nevra() for pkg in base_pkgs])
with open(pkg_list_dest, 'w') as f:
for nevra in nevras:
f.write(nevra)
Expand Down Expand Up @@ -199,6 +208,11 @@ def oscontainer_build(containers_storage, tmpdir, src, ref, image_name_and_tag,
extensions_label = ';'.join(extensions['extensions'])
config += ['-l', f"com.coreos.os-extensions={extensions_label}"]

for pkgname in meta['extensions']['manifest']:
if pkgname in IMPORTANT_PACKAGES:
evra = meta['extensions']['manifest'][pkgname]
config += ['-l', f"com.coreos.rpm.{pkgname}={evra}"]

if display_name is not None:
config += ['-l', 'io.openshift.build.version-display-names=machine-os=' + display_name,
'-l', 'io.openshift.build.versions=machine-os=' + ostree_version]
Expand Down

0 comments on commit 9c2e79a

Please sign in to comment.