2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 read -rd "\000" helpmessage <<EOF
7 $(basename $0): Orchestrate run-build-packages.sh for one target
10 WORKSPACE=/path/to/arvados $(basename $0) [options]
13 Distribution to build packages for (default: debian10)
15 Build command to execute (default: use built-in Docker image command)
17 Run package install test script "test-packages-[target].sh"
19 Output debug information (default: false)
20 --only-build <package>
21 Build only a specific package
23 Test only a specific package
25 Build even if the package exists upstream or if it has already been
28 Test even if there is no new untested package
29 --build-version <string>
30 Version to build (default:
31 \$ARVADOS_BUILDING_VERSION-\$ARVADOS_BUILDING_ITERATION or
32 0.1.timestamp.commithash)
34 WORKSPACE=path Path to the Arvados source tree to build packages from
40 if ! [[ -n "$WORKSPACE" ]]; then
41 echo >&2 "$helpmessage"
43 echo >&2 "Error: WORKSPACE environment variable not set"
48 if ! [[ -d "$WORKSPACE" ]]; then
49 echo >&2 "$helpmessage"
51 echo >&2 "Error: $WORKSPACE is not a directory"
56 PARSEDOPTS=$(getopt --name "$0" --longoptions \
57 help,debug,test-packages,target:,command:,only-test:,force-test,only-build:,force-build,build-version: \
68 eval set -- "$PARSEDOPTS"
69 while [ $# -gt 0 ]; do
72 echo >&2 "$helpmessage"
91 ONLY_BUILD="$2"; shift
104 if [[ -z "$2" ]]; then
106 elif ! [[ "$2" =~ (.*)-(.*) ]]; then
107 echo >&2 "FATAL: --build-version '$2' does not include an iteration. Try '${2}-1'?"
109 elif ! [[ "$2" =~ ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+|)(~rc[0-9]+|~dev[0-9]+|)-[0-9]+$ ]]; then
110 echo >&2 "FATAL: --build-version '$2' is invalid, must match pattern ^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+|)(~rc[0-9]+|~dev[0-9]+|)-[0-9]+$"
113 [[ "$2" =~ (.*)-(.*) ]]
114 ARVADOS_BUILDING_VERSION="${BASH_REMATCH[1]}"
115 ARVADOS_BUILDING_ITERATION="${BASH_REMATCH[2]}"
120 if [ $# -gt 1 ]; then
121 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
131 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
132 echo "build version='$ARVADOS_BUILDING_VERSION', package iteration='$ARVADOS_BUILDING_ITERATION'"
135 if [[ -n "$test_packages" ]]; then
136 if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.rpm')" ]] ; then
138 /usr/bin/which createrepo >/dev/null
139 if [[ "$?" != "0" ]]; then
141 echo >&2 "Error: please install createrepo. E.g. sudo apt-get install createrepo"
146 createrepo $WORKSPACE/packages/$TARGET
149 if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.deb')" ]] ; then
151 /usr/bin/which dpkg-scanpackages >/dev/null
152 if [[ "$?" != "0" ]]; then
154 echo >&2 "Error: please install dpkg-dev. E.g. sudo apt-get install dpkg-dev"
158 /usr/bin/which apt-ftparchive >/dev/null
159 if [[ "$?" != "0" ]]; then
161 echo >&2 "Error: please install apt-utils. E.g. sudo apt-get install apt-utils"
166 (cd $WORKSPACE/packages/$TARGET
167 dpkg-scanpackages . 2> >(grep -v 'warning' 1>&2) | tee Packages | gzip -c > Packages.gz
168 apt-ftparchive -o APT::FTPArchive::Release::Origin=Arvados release . > Release
172 COMMAND="/jenkins/package-testing/test-packages-$TARGET.sh"
173 IMAGE="arvados/package-test:$TARGET"
175 IMAGE="arvados/build:$TARGET"
176 if [[ "$COMMAND" != "" ]]; then
177 COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET$DEBUG"
181 JENKINS_DIR=$(dirname "$(readlink -e "$0")")
183 if [[ -n "$test_packages" ]]; then
184 pushd "$JENKINS_DIR/package-test-dockerfiles"
185 make "$TARGET/generated"
187 pushd "$JENKINS_DIR/package-build-dockerfiles"
188 make "$TARGET/generated"
193 time docker build --tag=$IMAGE .
196 if test -z "$packages" ; then
197 packages="arvados-api-server
200 arvados-dispatch-cloud
202 arvados-docker-cleaner
211 crunch-dispatch-local
212 crunch-dispatch-slurm
228 python3-arvados-python-client
229 python3-arvados-cwl-runner
230 python3-crunchstat-summary
231 python3-arvados-user-activity"
238 mkdir -p "$WORKSPACE/apps/workbench/vendor/cache-$TARGET"
239 mkdir -p "$WORKSPACE/services/api/vendor/cache-$TARGET"
242 -v "$JENKINS_DIR:/jenkins"
243 -v "$WORKSPACE:/arvados"
244 -v /arvados/services/api/vendor/bundle
245 -v /arvados/apps/workbench/vendor/bundle
246 -v "$WORKSPACE/services/api/vendor/cache-$TARGET:/arvados/services/api/vendor/cache"
247 -v "$WORKSPACE/apps/workbench/vendor/cache-$TARGET:/arvados/apps/workbench/vendor/cache"
250 if [[ -n "$test_packages" ]]; then
251 for p in $packages ; do
252 if [[ -n "$ONLY_BUILD" ]] && [[ "$p" != "$ONLY_BUILD" ]]; then
255 if [[ -e "${WORKSPACE}/packages/.last_test_${TARGET}" ]] && [[ -z "$FORCE_TEST" ]]; then
256 MATCH=`find ${WORKSPACE}/packages/ -newer ${WORKSPACE}/packages/.last_test_${TARGET} -regex .*${TARGET}/$p.*`
257 if [[ "$MATCH" == "" ]]; then
258 # No new package has been built that needs testing
259 echo "Skipping $p test because no new package was built since the last test."
263 # If we're testing all packages, we should not error out on packages that don't exist.
264 # If we are testing one specific package only (i.e. --only-test was given), we should
265 # error out if that package does not exist.
266 if [[ -z "$testing_one_package" ]]; then
267 MATCH=`find ${WORKSPACE}/packages/ -regextype posix-extended -regex .*${TARGET}/$p.*\\(deb\\|rpm\\)`
268 if [[ "$MATCH" == "" ]]; then
269 # No new package has been built that needs testing
270 echo "Skipping $p test because no package file is available to test."
275 echo "START: $p test on $IMAGE" >&2
278 "${docker_volume_args[@]}" \
279 --env ARVADOS_DEBUG=$ARVADOS_DEBUG \
280 --env "TARGET=$TARGET" \
281 --env "WORKSPACE=/arvados" \
284 echo "OK: $p test on $IMAGE succeeded" >&2
287 package_fails="$package_fails $p"
288 echo "ERROR: $p test on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
292 if [[ "$FINAL_EXITCODE" == "0" ]]; then
293 touch ${WORKSPACE}/packages/.last_test_${TARGET}
297 echo "START: build packages on $IMAGE" >&2
298 # Move existing packages and other files into the processed/ subdirectory
299 if [[ ! -e "${WORKSPACE}/packages/${TARGET}/processed" ]]; then
300 mkdir -p "${WORKSPACE}/packages/${TARGET}/processed"
303 mv -f ${WORKSPACE}/packages/${TARGET}/* ${WORKSPACE}/packages/${TARGET}/processed/ 2>/dev/null
308 "${docker_volume_args[@]}" \
309 --env ARVADOS_BUILDING_VERSION="$ARVADOS_BUILDING_VERSION" \
310 --env ARVADOS_BUILDING_ITERATION="$ARVADOS_BUILDING_ITERATION" \
311 --env ARVADOS_DEBUG=$ARVADOS_DEBUG \
312 --env "ONLY_BUILD=$ONLY_BUILD" \
313 --env "FORCE_BUILD=$FORCE_BUILD" \
317 echo "OK: build packages on $IMAGE succeeded" >&2
320 echo "ERROR: build packages on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
324 if test -n "$package_fails" ; then
325 echo "Failed package tests:$package_fails" >&2