Skip to content

Commit 5a1bd04

Browse files
dustymabecgwalters
authored andcommitted
add proof of concept for building with osbuild
This is proof of concept code with many things hardcoded in the coreos.osbuild.mpp.yaml that need to become more dynamically defined. To use this you can set the COSA_USE_OSBUILD env var to have a value. COSA_USE_OSBUILD=1 should work just fine.
1 parent 138e2df commit 5a1bd04

9 files changed

+422
-13
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ COPY ./ /root/containerbuild/
2323
RUN ./build.sh write_archive_info
2424
RUN ./build.sh make_and_makeinstall
2525
RUN ./build.sh configure_user
26+
RUN ./build.sh patch_osbuild
2627

2728
# clean up scripts (it will get cached in layers, but oh well)
2829
WORKDIR /srv/

build.sh

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if [ $# -gt 1 ]; then
2222
echo " configure_yum_repos"
2323
echo " install_rpms"
2424
echo " make_and_makeinstall"
25+
echo " patch_osbuild"
2526
exit 1
2627
fi
2728

@@ -168,6 +169,12 @@ write_archive_info() {
168169
prepare_git_artifacts "${srcdir}" /cosa/coreos-assembler-git.json /cosa/coreos-assembler-git.tar.gz
169170
}
170171

172+
patch_osbuild() {
173+
# A few patches that either haven't made it into a release or
174+
# that will be obsoleted with other work that will be done soon.
175+
cat /usr/lib/coreos-assembler/*.patch | patch -p1 -d /usr/lib/python3.11/site-packages/
176+
}
177+
171178
if [ $# -ne 0 ]; then
172179
# Run the function specified by the calling script
173180
${1}
@@ -182,4 +189,5 @@ else
182189
install_ocp_tools
183190
trust_redhat_gpg_keys
184191
configure_user
192+
patch_osbuild
185193
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From d4b3e3655deb7d55792e52fe6a11c609fb24e3b8 Mon Sep 17 00:00:00 2001
2+
From: Dusty Mabe <[email protected]>
3+
Date: Tue, 24 Oct 2023 14:08:44 -0400
4+
Subject: [PATCH] objectstore: also mount /etc/containers for "host" buildroot
5+
6+
In the case we are not using a buildroot (i.e. we are using
7+
the host as the buildroot) let's also mount in /etc/containers
8+
into the environment. There are sometimes where software running
9+
from /usr can't operate without configuration in /etc and this
10+
will allow it to work.
11+
12+
An example of software hitting this problem is skopeo. With a
13+
simple config like:
14+
15+
```
16+
version: '2'
17+
mpp-vars:
18+
release: 38
19+
pipelines:
20+
- name: skopeo-tree
21+
# build: name:build
22+
source-epoch: 1659397331
23+
stages:
24+
- type: org.osbuild.skopeo
25+
inputs:
26+
images:
27+
type: org.osbuild.containers
28+
origin: org.osbuild.source
29+
mpp-resolve-images:
30+
images:
31+
- source: quay.io/fedora/fedora-coreos
32+
tag: stable
33+
name: localhost/fcos
34+
options:
35+
destination:
36+
type: containers-storage
37+
storage-path: /usr/share/containers/storage
38+
```
39+
40+
We end up hitting an error like this:
41+
42+
```
43+
time="2023-10-24T18:27:14Z" level=fatal msg="Error loading trust policy: open /etc/containers/policy.json: no such file or directory"
44+
Traceback (most recent call last):
45+
File "/run/osbuild/bin/org.osbuild.skopeo", line 90, in <module>
46+
r = main(args["inputs"], args["tree"], args["options"])
47+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
File "/run/osbuild/bin/org.osbuild.skopeo", line 73, in main
49+
subprocess.run(["skopeo", "copy", image_source, dest], check=True)
50+
File "/usr/lib64/python3.11/subprocess.py", line 571, in run
51+
raise CalledProcessError(retcode, process.args,
52+
subprocess.CalledProcessError: Command '['skopeo', 'copy', 'dir:/tmp/tmp5_qcng99/image', 'containers-storage:[overlay@/run/osbuild/tree/usr/share/containers/storage+/run/containers/storage]localhost/fcos']' returned non-zero exit status 1.
53+
```
54+
55+
This PR adds in a mount for /etc/containers from the host so that
56+
/etc/containers/policy.json can be accessed.
57+
---
58+
osbuild/objectstore.py | 12 ++++++++++--
59+
1 file changed, 10 insertions(+), 2 deletions(-)
60+
61+
diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py
62+
index 4a19ce9..922d5ee 100644
63+
--- a/osbuild/objectstore.py
64+
+++ b/osbuild/objectstore.py
65+
@@ -283,14 +283,22 @@ class HostTree:
66+
self._root = self.store.tempdir(prefix="host")
67+
68+
root = self._root.name
69+
- # Create a bare bones root file system
70+
- # with just /usr mounted from the host
71+
+ # Create a bare bones root file system. Starting with just
72+
+ # /usr mounted from the host.
73+
usr = os.path.join(root, "usr")
74+
os.makedirs(usr)
75+
+ # Also add in /etc/containers, which will allow us to access
76+
+ # /etc/containers/policy.json and enable moving containers
77+
+ # (skopeo): https://github.com/osbuild/osbuild/pull/1410
78+
+ # If https://github.com/containers/image/issues/2157 ever gets
79+
+ # fixed we can probably remove this bind mount.
80+
+ etc_containers = os.path.join(root, "etc", "containers")
81+
+ os.makedirs(etc_containers)
82+
83+
# ensure / is read-only
84+
mount(root, root)
85+
mount("/usr", usr)
86+
+ mount("/etc/containers", etc_containers)
87+
88+
@property
89+
def tree(self) -> os.PathLike:
90+
--
91+
2.41.0
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From 2e34303f2e9ef1d48b965703976ef1029d7309f1 Mon Sep 17 00:00:00 2001
2+
From: Dusty Mabe <[email protected]>
3+
Date: Fri, 1 Sep 2023 12:18:25 -0400
4+
Subject: [PATCH] Mount boot from host in host builder case
5+
6+
---
7+
osbuild/buildroot.py | 2 +-
8+
osbuild/objectstore.py | 3 +++
9+
2 files changed, 4 insertions(+), 1 deletion(-)
10+
11+
diff --git a/osbuild/buildroot.py b/osbuild/buildroot.py
12+
index 5b47d70..a0f654d 100644
13+
--- a/osbuild/buildroot.py
14+
+++ b/osbuild/buildroot.py
15+
@@ -196,7 +196,7 @@ class BuildRoot(contextlib.AbstractContextManager):
16+
17+
# Import directories from the caller-provided root.
18+
imports = ["usr"]
19+
- if self.mount_boot:
20+
+ if True:
21+
imports.insert(0, "boot")
22+
23+
for p in imports:
24+
diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py
25+
index 922d5ee..6a3f89a 100644
26+
--- a/osbuild/objectstore.py
27+
+++ b/osbuild/objectstore.py
28+
@@ -294,11 +294,14 @@ class HostTree:
29+
# fixed we can probably remove this bind mount.
30+
etc_containers = os.path.join(root, "etc", "containers")
31+
os.makedirs(etc_containers)
32+
+ boot = os.path.join(root, "boot")
33+
+ os.makedirs(boot)
34+
35+
# ensure / is read-only
36+
mount(root, root)
37+
mount("/usr", usr)
38+
mount("/etc/containers", etc_containers)
39+
+ mount("/boot", boot)
40+
41+
@property
42+
def tree(self) -> os.PathLike:
43+
--
44+
2.41.0
45+

src/cmd-buildextend-metal

+15-7
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,21 @@ EOF
261261
cat "${image_json}" image-dynamic.json | jq -s add > image-for-disk.json
262262
platforms_json="${workdir}/tmp/platforms.json"
263263
yaml2json "${configdir}/platforms.yaml" "${platforms_json}"
264-
runvm "${qemu_args[@]}" -- \
265-
/usr/lib/coreos-assembler/create_disk.sh \
266-
--config "$(pwd)"/image-for-disk.json \
267-
--kargs "${kargs}" \
268-
--platform "${ignition_platform_id}" \
269-
--platforms-json "${platforms_json}" \
270-
"${disk_args[@]}"
264+
265+
if [ "${image_type}" == "qemu" ] && [ "${COSA_USE_OSBUILD:-}" != "" ]; then
266+
runvm -- /usr/lib/coreos-assembler/runvm-osbuild \
267+
"${ostree_repo}" "${ref}" \
268+
/usr/lib/coreos-assembler/coreos.osbuild.mpp.yaml \
269+
"${path}.tmp"
270+
else
271+
runvm "${qemu_args[@]}" -- \
272+
/usr/lib/coreos-assembler/create_disk.sh \
273+
--config "$(pwd)"/image-for-disk.json \
274+
--kargs "${kargs}" \
275+
--platform "${ignition_platform_id}" \
276+
--platforms-json "${platforms_json}" \
277+
"${disk_args[@]}"
278+
fi
271279

272280
if [[ $secure_execution -eq "1" && -z "${hostkey}" ]]; then
273281
/usr/lib/coreos-assembler/secex-genprotimgvm-scripts/runvm.sh \

0 commit comments

Comments
 (0)