Skip to content

Commit bf41ab7

Browse files
PeaceRebeljlebon
andcommitted
Add new cosa build-with-buildah command
This command is a wrapper around `buildah build` within a supermin VM. If `COSA_BUILD_WITH_BUILDAH=1`, `cosa build` automatically dispatches to that to build the ostree artifact. Else, got the traditional way. This will be useful for turning this on in the pipeline. Co-authored-by: Jonathan Lebon <[email protected]>
1 parent 6e607c7 commit bf41ab7

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ patch_osbuild() {
195195
## in the places delivered by the RPM.
196196
mv /usr/lib/osbuild/tools/osbuild-mpp /usr/bin/osbuild-mpp
197197
mv /usr/lib/osbuild/osbuild /usr/lib/python3.13/site-packages/osbuild
198-
mkdir /usr/lib/osbuild/osbuild
198+
mkdir -p /usr/lib/osbuild/osbuild
199199
}
200200

201201
if [ $# -ne 0 ]; then

src/cmd-build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
if [ -n "${COSA_BUILD_WITH_BUILDAH:-}" ]; then
5+
exec /usr/lib/coreos-assembler/cmd-build-with-buildah "$@"
6+
fi
7+
48
dn=$(dirname "$0")
59
# shellcheck source=src/cmdlib.sh
610
. "${dn}"/cmdlib.sh

src/cmd-build-with-buildah

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
dn=$(dirname "$0")
5+
# shellcheck source=src/cmdlib.sh
6+
. "${dn}"/cmdlib.sh
7+
8+
print_help() {
9+
cat 1>&2 <<'EOF'
10+
Usage: coreos-assembler build-with-buildah
11+
coreos-assembler build-with-buildah [OPTIONS]...
12+
13+
Build bootable container (ostree) and image base artifacts using the container runtime (buildah).
14+
`cosa build` will pivot to this script when the environment variable `COREOS_ASSEMBLER_BUILD_WITH_BUILDAH` is set.
15+
16+
The following options are supported:
17+
--versionary Use the versionary script from the source config to drive version.
18+
EOF
19+
}
20+
21+
VERSIONARY=
22+
VERSION=
23+
rc=0
24+
options=$(getopt --options h,v --longoptions help,versionary -- "$@") || rc=$?
25+
[ $rc -eq 0 ] || {
26+
print_help
27+
exit 1
28+
}
29+
eval set -- "$options"
30+
while true; do
31+
case "$1" in
32+
-h | --help)
33+
print_help
34+
exit 0
35+
;;
36+
-v | --versionary)
37+
VERSIONARY=1
38+
;;
39+
--)
40+
shift
41+
break
42+
;;
43+
-*)
44+
fatal "$0: unrecognized option: $1"
45+
;;
46+
*)
47+
break
48+
;;
49+
esac
50+
shift
51+
done
52+
53+
if [ -n "${VERSIONARY}" ]; then
54+
# let error out if file does not exist
55+
VERSION=$(src/config/versionary)
56+
echo "New version will be ${VERSION}"
57+
fi
58+
59+
build_with_buildah() {
60+
VERSION=$1
61+
echo "Building with container runtime (buildah)..."
62+
63+
tempdir=$(mktemp -d --tmpdir=tmp "build-with-buildah.XXXXXXXX")
64+
65+
# the config dir virtiofs mount is mounted ro; copy it to the tempdir
66+
cp -r src/config/ "${tempdir}/src"
67+
68+
tmp_oci_archive_path=$(realpath "${tempdir}/out.ociarchive")
69+
70+
argsfile=build-args.conf
71+
if [ -n "${variant:-}" ]; then
72+
argsfile=build-args-${variant}.conf
73+
fi
74+
75+
set -- build --security-opt=label=disable --cap-add=all --device /dev/fuse \
76+
--build-arg-file "$argsfile" -v "$(realpath "${tempdir}/src")":/run/src \
77+
-t oci-archive:"${tmp_oci_archive_path}"
78+
79+
if [ -n "${VERSION}" ]; then
80+
set -- "$@" --build-arg VERSION="${VERSION}"
81+
fi
82+
83+
/usr/lib/coreos-assembler/cmd-supermin-run --cache \
84+
env -C "${tempdir}/src" TMPDIR="$(realpath cache)" buildah "$@" .
85+
86+
/usr/lib/coreos-assembler/cmd-import "oci-archive:${tmp_oci_archive_path}"
87+
88+
rm -rf "${tempdir}"
89+
}
90+
91+
build_with_buildah "$VERSION"

0 commit comments

Comments
 (0)