Skip to content

Commit bb4e221

Browse files
committed
osbuild/bootc-install: use ostree.aleph stage
Until we get bootc-dev/bootc#2043 released let's use the osbuild aleph stage to get the data we want in the aleph. We can remove that stage entirely when bootc create a nicer aleph. See bootc-dev/bootc#2038
1 parent b72b479 commit bb4e221

3 files changed

Lines changed: 172 additions & 33 deletions

File tree

build.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,27 @@ write_archive_info() {
195195
}
196196

197197
patch_osbuild() {
198-
return # No patches at this time
199-
### Add a few patches that either haven't made it into a release or
200-
### that will be obsoleted with other work that will be done soon.
201-
###
202-
### To make it easier to apply patches we'll move around the osbuild
203-
### code on the system first:
204-
##rmdir /usr/lib/osbuild/osbuild
205-
##python_lib_dir=$(ls -d /usr/lib/python*)
206-
##mv "${python_lib_dir}/site-packages/osbuild" /usr/lib/osbuild/
207-
##mkdir -p /usr/lib/osbuild/tools
208-
##mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/
209-
### Now all the software is under the /usr/lib/osbuild dir and we can patch
210-
### shellcheck disable=SC2002
211-
##cat \
212-
## /usr/lib/coreos-assembler/foo.patch \
213-
## | patch -d /usr/lib/osbuild -p1
214-
### And then move the files back; supermin appliance creation will need it back
215-
### in the places delivered by the RPM.
216-
##mv /usr/lib/osbuild/tools/osbuild-mpp /usr/bin/osbuild-mpp
217-
##mv /usr/lib/osbuild/osbuild "${python_lib_dir}/site-packages/osbuild"
218-
##mkdir -p /usr/lib/osbuild/osbuild
198+
# return # No patches at this time
199+
# Add a few patches that either haven't made it into a release or
200+
# that will be obsoleted with other work that will be done soon.
201+
#
202+
# To make it easier to apply patches we'll move around the osbuild
203+
# code on the system first:
204+
rmdir /usr/lib/osbuild/osbuild
205+
python_lib_dir=$(ls -d /usr/lib/python*)
206+
mv "${python_lib_dir}/site-packages/osbuild" /usr/lib/osbuild/
207+
mkdir -p /usr/lib/osbuild/tools
208+
mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/
209+
# Now all the software is under the /usr/lib/osbuild dir and we can patch
210+
# shellcheck disable=SC2002
211+
cat \
212+
/usr/lib/coreos-assembler/0001-stages-aleph-make-path-parametrizable.patch \
213+
| patch -d /usr/lib/osbuild -p1
214+
# And then move the files back; supermin appliance creation will need it back
215+
# in the places delivered by the RPM.
216+
mv /usr/lib/osbuild/tools/osbuild-mpp /usr/bin/osbuild-mpp
217+
mv /usr/lib/osbuild/osbuild "${python_lib_dir}/site-packages/osbuild"
218+
mkdir -p /usr/lib/osbuild/osbuild
219219
}
220220

221221
fixup_file_permissions() {
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+

src/osbuild-manifests/coreos.osbuild.x86_64.bootc.mpp.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,14 @@ pipelines:
394394
partition:
395395
mpp-format-int: '{image.layout[''boot''].partnum}'
396396
target: /boot
397-
# We historically created an aleph file named .coreos-aleph-version.json
398-
# in the sysroot partition, for debugging purposes. bootc create it's
399-
# own that is mostly the same content. Let's make a symlink to it
400-
# for backward compatibility.
401-
- type: org.osbuild.ln
397+
# Until we have https://github.com/bootc-dev/bootc/pull/2043
398+
# let's create the aleph manually with the old osbuild stage.
399+
- type: org.osbuild.ostree.aleph
402400
options:
403-
paths:
404-
- target: ".bootc-aleph.json"
405-
link_name: "mount://root/.coreos-aleph-version.json"
406-
symbolic: true
407-
- target: ".bootc-aleph.json"
408-
link_name: "mount://root/.aleph-version.json"
409-
symbolic: true
401+
sysroot_path: mount://root/
402+
coreos_compat: true
403+
deployment:
404+
default: true
410405
devices:
411406
disk:
412407
type: org.osbuild.loopback

0 commit comments

Comments
 (0)