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: debian9)
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 Test even if there is no new untested package
26 --build-version <string>
27 Version to build (default:
28 \$ARVADOS_BUILDING_VERSION-\$ARVADOS_BUILDING_ITERATION or
29 0.1.timestamp.commithash)
31 WORKSPACE=path Path to the Arvados source tree to build packages from
37 if ! [[ -n "$WORKSPACE" ]]; then
38 echo >&2 "$helpmessage"
40 echo >&2 "Error: WORKSPACE environment variable not set"
45 if ! [[ -d "$WORKSPACE" ]]; then
46 echo >&2 "$helpmessage"
48 echo >&2 "Error: $WORKSPACE is not a directory"
53 PARSEDOPTS=$(getopt --name "$0" --longoptions \
54 help,debug,test-packages,target:,command:,only-test:,force-test,only-build:,build-version: \
64 eval set -- "$PARSEDOPTS"
65 while [ $# -gt 0 ]; do
68 echo >&2 "$helpmessage"
84 ONLY_BUILD="$2"; shift
97 if [[ -z "$2" ]]; then
99 elif ! [[ "$2" =~ (.*)-(.*) ]]; then
100 echo >&2 "FATAL: --build-version '$2' does not include an iteration. Try '${2}-1'?"
103 ARVADOS_BUILDING_VERSION="${BASH_REMATCH[1]}"
104 ARVADOS_BUILDING_ITERATION="${BASH_REMATCH[2]}"
109 if [ $# -gt 1 ]; then
110 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
120 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
121 echo "build version='$ARVADOS_BUILDING_VERSION', package iteration='$ARVADOS_BUILDING_ITERATION'"
124 if [[ -n "$test_packages" ]]; then
125 if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.rpm')" ]] ; then
127 /usr/bin/which createrepo >/dev/null
128 if [[ "$?" != "0" ]]; then
130 echo >&2 "Error: please install createrepo. E.g. sudo apt-get install createrepo"
135 createrepo $WORKSPACE/packages/$TARGET
138 if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.deb')" ]] ; then
139 (cd $WORKSPACE/packages/$TARGET
140 dpkg-scanpackages . 2> >(grep -v 'warning' 1>&2) | tee Packages | gzip -c > Packages.gz
141 apt-ftparchive -o APT::FTPArchive::Release::Origin=Arvados release . > Release
145 COMMAND="/jenkins/package-testing/test-packages-$TARGET.sh"
146 IMAGE="arvados/package-test:$TARGET"
148 IMAGE="arvados/build:$TARGET"
149 if [[ "$COMMAND" != "" ]]; then
150 COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET$DEBUG"
154 JENKINS_DIR=$(dirname "$(readlink -e "$0")")
156 if [[ -n "$test_packages" ]]; then
157 pushd "$JENKINS_DIR/package-test-dockerfiles"
158 make "$TARGET/generated"
160 pushd "$JENKINS_DIR/package-build-dockerfiles"
161 make "$TARGET/generated"
166 time docker build --tag=$IMAGE .
169 if test -z "$packages" ; then
170 packages="arvados-api-server
172 arvados-docker-cleaner
177 crunch-dispatch-local
178 crunch-dispatch-slurm
189 python-arvados-python-client
190 python-arvados-cwl-runner"
197 mkdir -p "$WORKSPACE/apps/workbench/vendor/cache-$TARGET"
198 mkdir -p "$WORKSPACE/services/api/vendor/cache-$TARGET"
201 -v "$JENKINS_DIR:/jenkins"
202 -v "$WORKSPACE:/arvados"
203 -v /arvados/services/api/vendor/bundle
204 -v /arvados/apps/workbench/vendor/bundle
205 -v "$WORKSPACE/services/api/vendor/cache-$TARGET:/arvados/services/api/vendor/cache"
206 -v "$WORKSPACE/apps/workbench/vendor/cache-$TARGET:/arvados/apps/workbench/vendor/cache"
209 if [[ -n "$test_packages" ]]; then
210 for p in $packages ; do
211 if [[ -n "$ONLY_BUILD" ]] && [[ "$p" != "$ONLY_BUILD" ]]; then
214 if [[ -e "${WORKSPACE}/packages/.last_test_${TARGET}" ]] && [[ -z "$FORCE_TEST" ]]; then
215 MATCH=`find ${WORKSPACE}/packages/ -newer ${WORKSPACE}/packages/.last_test_${TARGET} -regex .*${TARGET}/$p.*`
216 if [[ "$MATCH" == "" ]]; then
217 # No new package has been built that needs testing
218 echo "Skipping $p test because no new package was built since the last test."
222 # If we're testing all packages, we should not error out on packages that don't exist.
223 # If we are testing one specific package only (i.e. --only-test was given), we should
224 # error out if that package does not exist.
225 if [[ -z "$testing_one_package" ]]; then
226 MATCH=`find ${WORKSPACE}/packages/ -regextype posix-extended -regex .*${TARGET}/$p.*\\(deb\\|rpm\\)`
227 if [[ "$MATCH" == "" ]]; then
228 # No new package has been built that needs testing
229 echo "Skipping $p test because no package file is available to test."
234 echo "START: $p test on $IMAGE" >&2
237 "${docker_volume_args[@]}" \
238 --env ARVADOS_DEBUG=$ARVADOS_DEBUG \
239 --env "TARGET=$TARGET" \
240 --env "WORKSPACE=/arvados" \
243 echo "OK: $p test on $IMAGE succeeded" >&2
246 package_fails="$package_fails $p"
247 echo "ERROR: $p test on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
251 if [[ "$FINAL_EXITCODE" == "0" ]]; then
252 touch ${WORKSPACE}/packages/.last_test_${TARGET}
256 echo "START: build packages on $IMAGE" >&2
257 # Move existing packages and other files into the processed/ subdirectory
258 if [[ ! -e "${WORKSPACE}/packages/${TARGET}/processed" ]]; then
259 mkdir -p "${WORKSPACE}/packages/${TARGET}/processed"
262 mv -f ${WORKSPACE}/packages/${TARGET}/* ${WORKSPACE}/packages/${TARGET}/processed/ 2>/dev/null
267 "${docker_volume_args[@]}" \
268 --env ARVADOS_BUILDING_VERSION="$ARVADOS_BUILDING_VERSION" \
269 --env ARVADOS_BUILDING_ITERATION="$ARVADOS_BUILDING_ITERATION" \
270 --env ARVADOS_DEBUG=$ARVADOS_DEBUG \
271 --env "ONLY_BUILD=$ONLY_BUILD" \
275 echo "OK: build packages on $IMAGE succeeded" >&2
278 echo "ERROR: build packages on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
282 if test -n "$package_fails" ; then
283 echo "Failed package tests:$package_fails" >&2