|
| 1 | +From 6e9192e138c4b2da4e6ed0dcfa639b2438438b29 Mon Sep 17 00:00:00 2001 |
| 2 | +From: jbtrystram <jbtrystram@redhat.com> |
| 3 | +Date: Mon, 9 Mar 2026 11:15:36 +0100 |
| 4 | +Subject: [PATCH] stages/aleph: make path parametrizable |
| 5 | + |
| 6 | +Allow passing a mount to specify where to write the alep file. |
| 7 | +This is because when running bootc install we want to write the aleph |
| 8 | +after the deployement, so we need to write to the mount instead of the |
| 9 | +tree. |
| 10 | + |
| 11 | +See also https://github.com/osbuild/osbuild/pull/2149 for a similar fix |
| 12 | +for the ignition stage. |
| 13 | + |
| 14 | +Longer term, we will use the aleph file that bootc write, but it's not |
| 15 | +shipping enough details at the moment. This is tracked in https://github.com/bootc-dev/bootc/issues/2038 |
| 16 | + |
| 17 | +Signed-off-by: jbtrystram <jbtrystram@redhat.com> |
| 18 | +--- |
| 19 | + stages/org.osbuild.ostree.aleph | 39 ++++++++++++----------- |
| 20 | + stages/org.osbuild.ostree.aleph.meta.json | 5 +++ |
| 21 | + 2 files changed, 26 insertions(+), 18 deletions(-) |
| 22 | + |
| 23 | +diff --git a/stages/org.osbuild.ostree.aleph b/stages/org.osbuild.ostree.aleph |
| 24 | +index 28e4c7d9..62a6508f 100755 |
| 25 | +--- a/stages/org.osbuild.ostree.aleph |
| 26 | ++++ b/stages/org.osbuild.ostree.aleph |
| 27 | +@@ -4,20 +4,20 @@ import os |
| 28 | + import sys |
| 29 | + |
| 30 | + import osbuild.api |
| 31 | +-from osbuild.util import ostree |
| 32 | ++from osbuild.util import ostree, parsing |
| 33 | + |
| 34 | + ALEPH_FILENAME = ".aleph-version.json" |
| 35 | + COREOS_ALEPH_FILENAME = ".coreos-aleph-version.json" |
| 36 | + |
| 37 | + |
| 38 | +-def aleph_commit(tree, imgref): |
| 39 | ++def aleph_commit(sysroot_path, imgref): |
| 40 | + extra_args = [] |
| 41 | + extra_args.append("--print-metadata-key=version") |
| 42 | + |
| 43 | +- aleph_version = ostree.cli("show", f"--repo={tree}/ostree/repo", imgref, *extra_args).stdout.rstrip().strip('\'') |
| 44 | ++ aleph_version = ostree.cli("show", f"--repo={sysroot_path}/ostree/repo", imgref, *extra_args).stdout.rstrip().strip('\'') |
| 45 | + aleph_ref = imgref |
| 46 | + # get the commit by parsing the revision of the deployment |
| 47 | +- aleph_ostree_commit = ostree.rev_parse(tree + "/ostree/repo", imgref) |
| 48 | ++ aleph_ostree_commit = ostree.rev_parse(sysroot_path + "/ostree/repo", imgref) |
| 49 | + |
| 50 | + aleph_version_data = { |
| 51 | + "osbuild-version": osbuild.__version__, |
| 52 | +@@ -29,7 +29,7 @@ def aleph_commit(tree, imgref): |
| 53 | + return aleph_version_data |
| 54 | + |
| 55 | + |
| 56 | +-def aleph_container(tree, imgref): |
| 57 | ++def aleph_container(sysroot_path, imgref): |
| 58 | + # Determine the image name used for the deployment. We first attempt to do this by checking |
| 59 | + # how many container images are stored in the OSTree repo. If it's only one then clearly |
| 60 | + # that's the one to inspect here and we'll use that. If there's more than one we'll |
| 61 | +@@ -46,7 +46,7 @@ def aleph_container(tree, imgref): |
| 62 | + # $ ostree container image list --repo=/sysroot/ostree/repo |
| 63 | + # docker://quay.io/podman/machine-os:6.0 |
| 64 | + # |
| 65 | +- extra_args = [f"--repo={tree}/ostree/repo"] |
| 66 | ++ extra_args = [f"--repo={sysroot_path}/ostree/repo"] |
| 67 | + container_list = ostree.cli("container", "image", "list", *extra_args).stdout.splitlines() |
| 68 | + if len(container_list) == 1: |
| 69 | + img_name = container_list[0] |
| 70 | +@@ -96,40 +96,43 @@ def aleph_container(tree, imgref): |
| 71 | + return aleph_version_data |
| 72 | + |
| 73 | + |
| 74 | +-def construct_aleph_json(tree, origin): |
| 75 | ++def construct_aleph_json(sysroot_path, origin): |
| 76 | + deploy_type, imgref = ostree.parse_origin(origin) |
| 77 | + data = {} |
| 78 | + # null deploy_type and imgref error is caught in the parse_origin() function |
| 79 | + if deploy_type == "container": |
| 80 | +- data = aleph_container(tree, imgref) |
| 81 | ++ data = aleph_container(sysroot_path, imgref) |
| 82 | + elif deploy_type == "ostree_commit": |
| 83 | +- data = aleph_commit(tree, imgref) |
| 84 | ++ data = aleph_commit(sysroot_path, imgref) |
| 85 | + else: |
| 86 | + raise ValueError("Unknown deployment type") |
| 87 | + |
| 88 | + return data |
| 89 | + |
| 90 | + |
| 91 | +-def main(tree, options): |
| 92 | ++def main(args): |
| 93 | ++ options = args["options"] |
| 94 | ++ sysroot_path = options.get("sysroot_path", "tree:///") |
| 95 | ++ sysroot = parsing.parse_location(sysroot_path, args) |
| 96 | ++ |
| 97 | + coreos_compat = options.get("coreos_compat", False) |
| 98 | + dep = options["deployment"] |
| 99 | +- osname, ref, serial = ostree.parse_deployment_option(tree, dep) |
| 100 | ++ osname, ref, serial = ostree.parse_deployment_option(sysroot, dep) |
| 101 | + |
| 102 | +- origin = ostree.deployment_path(tree, osname, ref, serial) + ".origin" |
| 103 | +- data = construct_aleph_json(tree, origin) |
| 104 | ++ origin = ostree.deployment_path(sysroot, osname, ref, serial) + ".origin" |
| 105 | ++ data = construct_aleph_json(sysroot, origin) |
| 106 | + |
| 107 | + # write the data out to the file |
| 108 | +- with open(os.path.join(tree, ALEPH_FILENAME), "w", encoding="utf8") as f: |
| 109 | ++ with open(os.path.join(sysroot, ALEPH_FILENAME), "w", encoding="utf8") as f: |
| 110 | + json.dump(data, f, indent=4, sort_keys=True) |
| 111 | + f.write("\n") |
| 112 | + |
| 113 | + # create a symlink for backwards compatibility with CoreOS |
| 114 | + if coreos_compat: |
| 115 | +- os.symlink(ALEPH_FILENAME, os.path.join(tree, COREOS_ALEPH_FILENAME)) |
| 116 | ++ os.symlink(ALEPH_FILENAME, os.path.join(sysroot, COREOS_ALEPH_FILENAME)) |
| 117 | + |
| 118 | + |
| 119 | + if __name__ == '__main__': |
| 120 | +- stage_args = osbuild.api.arguments() |
| 121 | +- r = main(stage_args["tree"], |
| 122 | +- stage_args["options"]) |
| 123 | ++ args = osbuild.api.arguments() |
| 124 | ++ r = main(args) |
| 125 | + sys.exit(r) |
| 126 | +diff --git a/stages/org.osbuild.ostree.aleph.meta.json b/stages/org.osbuild.ostree.aleph.meta.json |
| 127 | +index 29ea0b7d..142de55b 100644 |
| 128 | +--- a/stages/org.osbuild.ostree.aleph.meta.json |
| 129 | ++++ b/stages/org.osbuild.ostree.aleph.meta.json |
| 130 | +@@ -15,6 +15,11 @@ |
| 131 | + "description": "boolean to allow for CoreOS aleph version backwards compatibility", |
| 132 | + "type": "boolean" |
| 133 | + }, |
| 134 | ++ "sysroot_path": { |
| 135 | ++ "type": "string", |
| 136 | ++ "description": "Location of the OSTree sysroot to read the repo and deployments from.", |
| 137 | ++ "default": "tree:///" |
| 138 | ++ }, |
| 139 | + "deployment": { |
| 140 | + "additionalProperties": false, |
| 141 | + "oneOf": [ |
| 142 | +-- |
| 143 | +2.53.0 |
| 144 | + |
0 commit comments