Skip to content

Commit da66c4e

Browse files
container: break build.sh up into discrete steps
Break build.sh up into discrete steps. The steps that are executed can be controlled via SAMBACC_BUILD_STEPS env var. Dependencies between steps may exist - this script is not meant to be super smart, the option is for developers to control things during testing/development only. Signed-off-by: John Mulligan <[email protected]>
1 parent 1b3f054 commit da66c4e

File tree

1 file changed

+75
-38
lines changed

1 file changed

+75
-38
lines changed

tests/container/build.sh

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ python=python3
66
url="https://github.com/samba-in-kubernetes/sambacc"
77
bdir="/var/tmp/build/sambacc"
88
distname="${SAMBACC_DISTNAME}"
9+
# use SAMBACC_BUILD_TASKS to limit build tasks if needed
10+
tasks="${SAMBACC_BUILD_TASKS:-task_test_tox task_py_build task_gen_sums}"
911

1012
info() {
1113
echo "[[sambacc/build]] $*"
@@ -33,27 +35,73 @@ update() {
3335
fi
3436
}
3537

36-
# allow customizing the repo on the cli or environment
37-
if [ "$2" ]; then
38-
url="$2"
39-
elif [ "${SAMBACC_REPO_URL}" ]; then
40-
url="${SAMBACC_REPO_URL}"
41-
fi
42-
43-
mkdir -p /var/tmp/build/ || true
44-
if checked_out "${bdir}" ; then
45-
info "repo already checked out"
46-
else
47-
info "cloning sambacc repo"
48-
clone "$url" "${bdir}"
49-
fi
38+
chk() {
39+
for x in $tasks; do
40+
case "$1" in
41+
"$x")
42+
# execute the named task if it is in $tasks
43+
"$1"
44+
return $?
45+
;;
46+
esac
47+
done
48+
info "skipping task: $1"
49+
}
5050

51-
cd "${bdir}"
51+
setup_fetch() {
52+
# allow customizing the repo on the cli or environment
53+
if [ "$1" ]; then
54+
url="$1"
55+
elif [ "${SAMBACC_REPO_URL}" ]; then
56+
url="${SAMBACC_REPO_URL}"
57+
fi
58+
59+
mkdir -p /var/tmp/build/ || true
60+
if checked_out "${bdir}" ; then
61+
info "repo already checked out"
62+
else
63+
info "cloning sambacc repo"
64+
clone "$url" "${bdir}"
65+
fi
66+
}
67+
68+
setup_update() {
69+
if [ "$1" ]; then
70+
# a tag or revision id was specified on the cli
71+
update "${bdir}" "$1"
72+
fi
73+
}
74+
75+
task_test_tox() {
76+
# Run tox with sitepackages enabled to allow access to system installed samba
77+
# modules. The container env already provides us control over the env.
78+
info "running test suite with tox"
79+
tox
80+
}
81+
82+
task_py_build() {
83+
info "building python package(s)"
84+
pip -qq install build
85+
if [ "$distname" ]; then
86+
# building for a given "distribution name" - meaning this could be
87+
# consumed externally
88+
distdir="/srv/dist/$distname"
89+
info "using dist dir: $distdir"
90+
mkdir -p "$distdir"
91+
$python -m build --outdir "$distdir"
92+
else
93+
# just run the build as a test to make sure it succeeds
94+
$python -m build
95+
fi
96+
}
97+
98+
task_gen_sums() {
99+
if [ "$distname" ]; then
100+
info "generating checksums"
101+
(cd "$distdir" && sha512sum * > "$distdir/sha512sums")
102+
fi
103+
}
52104

53-
if [ "$1" ]; then
54-
# a tag or revision id was specified on the cli
55-
update "${bdir}" "$1"
56-
fi
57105

58106
# Allow the tests to use customized passwd file contents in order
59107
# to test samba passdb support. It's a bit strange, but should work.
@@ -64,22 +112,11 @@ export WRITABLE_PASSWD=yes
64112
export NSS_WRAPPER_PASSWD=/etc/passwd
65113
export NSS_WRAPPER_GROUP=/etc/group
66114

67-
# Run tox with sitepackages enabled to allow access to system installed samba
68-
# modules. The container env already provides us control over the env.
69-
info "running test suite with tox"
70-
tox
71-
72-
info "building python package(s)"
73-
pip -qq install build
74-
if [ "$distname" ]; then
75-
# building for a given "distribution name" - meaning this could be
76-
# consumed externally
77-
distdir="/srv/dist/$distname"
78-
info "using dist dir: $distdir"
79-
mkdir -p "$distdir"
80-
$python -m build --outdir "$distdir"
81-
(cd "$distdir" && sha512sum * > "$distdir/sha512sums")
82-
else
83-
# just run the build as a test to make sure it succeeds
84-
$python -m build
85-
fi
115+
116+
setup_fetch "$2"
117+
cd "${bdir}"
118+
setup_update "$1"
119+
120+
chk task_test_tox
121+
chk task_py_build
122+
chk task_gen_sums

0 commit comments

Comments
 (0)