Skip to content

Commit f2fbc76

Browse files
container: add ability to build RPMs from python sources
Signed-off-by: John Mulligan <[email protected]>
1 parent 1ab1a37 commit f2fbc76

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

tests/container/build.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ url="https://github.com/samba-in-kubernetes/sambacc"
77
bdir="/var/tmp/build/sambacc"
88
distname="${SAMBACC_DISTNAME}"
99
# use SAMBACC_BUILD_TASKS to limit build tasks if needed
10-
tasks="${SAMBACC_BUILD_TASKS:-task_test_tox task_py_build task_gen_sums}"
10+
tasks="${SAMBACC_BUILD_TASKS:-task_test_tox task_py_build task_rpm_build task_gen_sums}"
1111

1212
info() {
1313
echo "[[sambacc/build]] $*"
@@ -48,6 +48,13 @@ chk() {
4848
info "skipping task: $1"
4949
}
5050

51+
get_distdir() {
52+
dname="$1"
53+
ddir="/srv/dist/$dname"
54+
mkdir -p "$ddir" >/dev/null
55+
echo "$ddir"
56+
}
57+
5158
setup_fetch() {
5259
# allow customizing the repo on the cli or environment
5360
if [ "$1" ]; then
@@ -85,20 +92,51 @@ task_py_build() {
8592
if [ "$distname" ]; then
8693
# building for a given "distribution name" - meaning this could be
8794
# consumed externally
88-
distdir="/srv/dist/$distname"
95+
distdir="$(get_distdir "$distname")"
8996
info "using dist dir: $distdir"
90-
mkdir -p "$distdir"
9197
$python -m build --outdir "$distdir"
9298
else
9399
# just run the build as a test to make sure it succeeds
94100
$python -m build
95101
fi
96102
}
97103

104+
task_rpm_build() {
105+
if ! [ "$distname" ]; then
106+
return
107+
fi
108+
if ! command -v rpmbuild ; then
109+
info "rpmbuild not found ... skipping"
110+
return
111+
fi
112+
113+
distdir="$(get_distdir "$distname")"
114+
info "using dist dir: $distdir"
115+
for spkg in "$distdir/sambacc"-*.tar.gz; do
116+
info "RPM build for: ${spkg}"
117+
ver="$(basename "${spkg}" | sed -e 's/^sambacc-//' -e 's/.tar.gz$//')"
118+
if echo "$ver" | grep -q "+" ; then
119+
rversion="$(echo "${ver}" | sed -e 's/\.dev/~/' -e 's/+/./')"
120+
else
121+
rversion="$ver"
122+
fi
123+
info "Using rpm-version=${rversion} pkg-version=${ver}"
124+
rpmbuild --nocheck -ta \
125+
-D "pversion ${ver}" -D"rversion ${rversion}" \
126+
-D "_rpmdir ${distdir}/RPMS" \
127+
-D "_srcrpmdir ${distdir}/SRPMS" \
128+
"$spkg"
129+
done
130+
}
131+
98132
task_gen_sums() {
99133
if [ "$distname" ]; then
100134
info "generating checksums"
101-
(cd "$distdir" && sha512sum * > "$distdir/sha512sums")
135+
distdir="$(get_distdir "$distname")"
136+
info "using dist dir: $distdir"
137+
(cd "$distdir" && \
138+
find . -type f -not -name 'sha*sums' -print0 | \
139+
xargs -0 sha512sum > "$distdir/sha512sums")
102140
fi
103141
}
104142

@@ -119,4 +157,5 @@ setup_update "$1"
119157

120158
chk task_test_tox
121159
chk task_py_build
160+
chk task_rpm_build
122161
chk task_gen_sums

0 commit comments

Comments
 (0)