2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # A library of functions shared by the various scripts in this directory.
8 # This is the timestamp about when we merged changed to include licenses
9 # with Arvados packages. We use it as a heuristic to add revisions for
11 LICENSE_PACKAGE_TS=20151208015500
13 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
14 RAILS_PACKAGE_ITERATION=1
16 RAILS_PACKAGE_ITERATION="$ARVADOS_BUILDING_ITERATION"
20 echo "$@" >"$STDOUT_IF_DEBUG"
23 find_python_program() {
27 if "$prog" --version >/dev/null 2>&1; then
35 Error: $prog (from Python setuptools module) not found
41 format_last_commit_here() {
42 local format="$1"; shift
43 TZ=UTC git log -n1 --first-parent "--format=format:$format" .
47 # Output the version being built, or if we're building a
48 # dev/prerelease, output a version number based on the git log for
49 # the current working directory.
50 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
51 echo "$ARVADOS_BUILDING_VERSION"
55 local git_ts git_hash prefix
56 if [[ -n "$1" ]] ; then
62 declare $(format_last_commit_here "git_ts=%ct git_hash=%h")
63 ARVADOS_BUILDING_VERSION="$(git tag -l |sort -V -r |head -n1).$(date -ud "@$git_ts" +%Y%m%d%H%M%S)"
64 echo "$ARVADOS_BUILDING_VERSION"
67 nohash_version_from_git() {
68 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
69 echo "$ARVADOS_BUILDING_VERSION"
72 version_from_git $1 | cut -d. -f1-4
75 timestamp_from_git() {
76 format_last_commit_here "%ct"
79 handle_python_package () {
80 # This function assumes the current working directory is the python package directory
81 if [ -n "$(find dist -name "*-$(nohash_version_from_git).tar.gz" -print -quit)" ]; then
82 # This package doesn't need rebuilding.
85 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
86 python setup.py $DASHQ_UNLESS_DEBUG sdist
90 local gem_name="$1"; shift
91 local gem_version="$(nohash_version_from_git)"
92 local gem_src_dir="$(pwd)"
94 if [[ -n "$ONLY_BUILD" ]] && [[ "$gem_name" != "$ONLY_BUILD" ]] ; then
98 if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
99 find -maxdepth 1 -name "${gem_name}-*.gem" -delete
101 # -q appears to be broken in gem version 2.2.2
102 $GEM build "$gem_name.gemspec" $DASHQ_UNLESS_DEBUG >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
106 calculate_go_package_version() {
107 local -n __returnvar="$1"; shift
108 local src_path="$1"; shift
110 mkdir -p "$GOPATH/src/git.curoverse.com"
111 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
112 (cd "$GOPATH/src/git.curoverse.com/arvados.git" && "$GOPATH/bin/govendor" sync -v)
114 cd "$GOPATH/src/git.curoverse.com/arvados.git/$src_path"
115 local version="$(version_from_git)"
116 local timestamp="$(timestamp_from_git)"
118 # Update the version number and build a new package if the vendor
119 # bundle has changed, or the command imports anything from the
120 # Arvados SDK and the SDK has changed.
121 declare -a checkdirs=(vendor)
122 if grep -qr git.curoverse.com/arvados .; then
123 checkdirs+=(sdk/go lib)
125 for dir in ${checkdirs[@]}; do
126 cd "$GOPATH/src/git.curoverse.com/arvados.git/$dir"
127 ts="$(timestamp_from_git)"
128 if [[ "$ts" -gt "$timestamp" ]]; then
129 version=$(version_from_git)
134 __returnvar="$version"
137 # Usage: package_go_binary services/foo arvados-foo "Compute foo to arbitrary precision"
138 package_go_binary() {
139 local src_path="$1"; shift
140 local prog="$1"; shift
141 local description="$1"; shift
142 local license_file="${1:-agpl-3.0.txt}"; shift
144 if [[ -n "$ONLY_BUILD" ]] && [[ "$prog" != "$ONLY_BUILD" ]]; then
145 # arvados-workbench depends on arvados-server at build time, so even when
146 # only arvados-workbench is being built, we need to build arvados-server too
147 if [[ "$prog" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
152 debug_echo "package_go_binary $src_path as $prog"
154 local basename="${src_path##*/}"
155 calculate_go_package_version go_package_version $src_path
157 cd $WORKSPACE/packages/$TARGET
158 test_package_presence $prog $go_package_version go
160 if [[ "$?" != "0" ]]; then
164 go get -ldflags "-X main.version=${go_package_version}" "git.curoverse.com/arvados.git/$src_path"
167 systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
168 if [[ -e "${systemd_unit}" ]]; then
170 --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
171 --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
172 "${systemd_unit}=/lib/systemd/system/${prog}.service")
174 switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
176 fpm_build "$GOPATH/bin/${basename}=/usr/bin/${prog}" "${prog}" dir "${go_package_version}" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=${description}" "${switches[@]}"
179 default_iteration() {
180 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
181 echo "$ARVADOS_BUILDING_ITERATION"
184 local package_name="$1"; shift
185 local package_version="$1"; shift
186 local package_type="$1"; shift
188 if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
189 [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
192 if [[ $package_type =~ ^python ]]; then
193 # Fix --iteration for #9242.
199 _build_rails_package_scripts() {
200 local pkgname="$1"; shift
201 local destdir="$1"; shift
202 local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
203 for scriptname in postinst prerm postrm; do
204 cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
205 >"$destdir/$scriptname" || return $?
209 test_rails_package_presence() {
210 local pkgname="$1"; shift
211 local srcdir="$1"; shift
213 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
221 local version="$(version_from_git)"
225 test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
228 get_complete_package_name() {
229 # if the errexit flag is set, unset it until this function returns
230 # otherwise, the shift calls below will abort the program if optional arguments are not supplied
231 if [ -o errexit ]; then
235 local -n __returnvar="$1"; shift
236 local pkgname="$1"; shift
237 local version="$1"; shift
238 local pkgtype="$1"; shift
239 local iteration="$1"; shift
240 local arch="$1"; shift
241 if [[ "$iteration" == "" ]]; then
242 iteration="$(default_iteration "$pkgname" "$version" "$pkgtype")"
245 if [[ "$arch" == "" ]]; then
246 rpm_architecture="x86_64"
247 deb_architecture="amd64"
249 if [[ "$pkgtype" =~ ^(src)$ ]]; then
250 rpm_architecture="noarch"
251 deb_architecture="all"
254 # These python packages have binary components
255 if [[ "$pkgname" =~ (ruamel|ciso|pycrypto|pyyaml) ]]; then
256 rpm_architecture="x86_64"
257 deb_architecture="amd64"
260 rpm_architecture=$arch
261 deb_architecture=$arch
264 local complete_pkgname="${pkgname}_$version${iteration:+-$iteration}_$deb_architecture.deb"
265 if [[ "$FORMAT" == "rpm" ]]; then
266 # rpm packages get iteration 1 if we don't supply one
267 iteration=${iteration:-1}
268 complete_pkgname="$pkgname-$version-${iteration}.$rpm_architecture.rpm"
270 __returnvar=${complete_pkgname}
273 # Test if the package already exists, if not return 0, if it does return 1
274 test_package_presence() {
275 local pkgname="$1"; shift
276 local version="$1"; shift
277 local pkgtype="$1"; shift
278 local iteration="$1"; shift
279 local arch="$1"; shift
280 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
281 # arvados-workbench depends on arvados-server at build time, so even when
282 # only arvados-workbench is being built, we need to build arvados-server too
283 if [[ "$pkgname" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
289 get_complete_package_name full_pkgname $pkgname $version $pkgtype $iteration $arch
291 # See if we can skip building the package, only if it already exists in the
292 # processed/ directory. If so, move it back to the packages directory to make
293 # sure it gets picked up by the test and/or upload steps.
294 # Get the list of packages from the repos
296 if [[ "$FORMAT" == "deb" ]]; then
300 dd[ubuntu1604]=xenial
301 dd[ubuntu1804]=bionic
303 if [ ${pkgname:0:3} = "lib" ]; then
304 repo_subdir=${pkgname:0:4}
306 repo_subdir=${pkgname:0:1}
309 repo_pkg_list=$(curl -s -o - http://apt.arvados.org/pool/${D}/main/${repo_subdir}/)
310 echo ${repo_pkg_list} |grep -q ${full_pkgname}
311 if [ $? -eq 0 ] ; then
312 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
313 curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" http://apt.arvados.org/pool/${D}/main/${repo_subdir}/${full_pkgname}
315 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
316 echo "Package $full_pkgname exists, not rebuilding!"
319 echo "Package $full_pkgname not found, building"
323 centos_repo="http://rpm.arvados.org/CentOS/7/dev/x86_64/"
325 repo_pkg_list=$(curl -s -o - ${centos_repo})
326 echo ${repo_pkg_list} |grep -q ${full_pkgname}
327 if [ $? -eq 0 ]; then
328 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
329 curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" ${centos_repo}${full_pkgname}
331 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
332 echo "Package $full_pkgname exists, not rebuilding!"
335 echo "Package $full_pkgname not found, building"
341 handle_rails_package() {
342 local pkgname="$1"; shift
344 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
347 local srcdir="$1"; shift
349 local license_path="$1"; shift
350 local version="$(version_from_git)"
351 echo "$version" >package-build.version
352 local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
355 _build_rails_package_scripts "$pkgname" "$scripts_dir"
358 git rev-parse HEAD >git-commit.version
361 if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
362 echo "ERROR: $pkgname package prep failed" >&2
363 rm -rf "$scripts_dir"
367 local railsdir="/var/www/${pkgname%-server}/current"
368 local -a pos_args=("$srcdir/=$railsdir" "$pkgname" dir "$version")
369 local license_arg="$license_path=$railsdir/$(basename "$license_path")"
370 local -a switches=(--after-install "$scripts_dir/postinst"
371 --before-remove "$scripts_dir/prerm"
372 --after-remove "$scripts_dir/postrm")
373 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
374 switches+=(--iteration $RAILS_PACKAGE_ITERATION)
376 # For some reason fpm excludes need to not start with /.
377 local exclude_root="${railsdir#/}"
378 # .git and packages are for the SSO server, which is built from its
380 local -a exclude_list=(.git packages tmp log coverage Capfile\* \
381 config/deploy\* config/application.yml)
382 # for arvados-workbench, we need to have the (dummy) config/database.yml in the package
383 if [[ "$pkgname" != "arvados-workbench" ]]; then
384 exclude_list+=('config/database.yml')
386 for exclude in ${exclude_list[@]}; do
387 switches+=(-x "$exclude_root/$exclude")
389 fpm_build "${pos_args[@]}" "${switches[@]}" \
390 -x "$exclude_root/vendor/cache-*" \
391 -x "$exclude_root/vendor/bundle" "$@" "$license_arg"
392 rm -rf "$scripts_dir"
395 # Build python packages with a virtualenv built-in
396 fpm_build_virtualenv () {
401 PACKAGE_TYPE=${1:-python}
405 STDOUT_IF_DEBUG=/dev/null
406 STDERR_IF_DEBUG=/dev/null
407 DASHQ_UNLESS_DEBUG=-q
408 if [[ "$DEBUG" != "0" ]]; then
409 STDOUT_IF_DEBUG=/dev/stdout
410 STDERR_IF_DEBUG=/dev/stderr
413 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
414 ARVADOS_BUILDING_ITERATION=1
418 case "$PACKAGE_TYPE" in
421 if [[ "$FORMAT" != "rpm" ]]; then
424 # In CentOS, we use a different mechanism to get the right version of pip
427 PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
430 # All Arvados Python2 packages depend on Python 2.7.
431 # Make sure we build with that for consistency.
434 PACKAGE_PREFIX=$PYTHON2_PKG_PREFIX
438 if [[ "$PKG" != "libpam-arvados" ]] &&
439 [[ "$PKG" != "arvados-node-manager" ]] &&
440 [[ "$PKG" != "arvados-docker-cleaner" ]]; then
441 PYTHON_PKG=$PACKAGE_PREFIX-$PKG
443 # Exception to our package naming convention
447 # arvados-python-client sdist should always be built, to be available
448 # for other dependant packages.
449 if [[ -n "$ONLY_BUILD" ]] && [[ "arvados-python-client" != "$PKG" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
453 cd $WORKSPACE/$PKG_DIR
457 # Get the latest setuptools
458 if ! $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools; then
459 echo "Error, unable to upgrade setuptools with"
460 echo " $pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools"
463 # filter a useless warning (when building the cwltest package) from the stderr output
464 if ! $python setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
465 echo "Error, unable to run $python setup.py sdist for $PKG"
469 PACKAGE_PATH=`(cd dist; ls *tar.gz)`
471 if [[ "arvados-python-client" == "$PKG" ]]; then
472 PYSDK_PATH=`pwd`/dist/
475 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
479 # Determine the package version from the generated sdist archive
480 PYTHON_VERSION=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)}
482 # See if we actually need to build this package; does it exist already?
483 # We can't do this earlier than here, because we need PYTHON_VERSION...
484 # This isn't so bad; the sdist call above is pretty quick compared to
485 # the invocation of virtualenv and fpm, below.
486 if ! test_package_presence "$PYTHON_PKG" $PYTHON_VERSION $PACKAGE_TYPE $ARVADOS_BUILDING_ITERATION; then
490 echo "Building $FORMAT package for $PKG from $PKG_DIR"
492 # Package the sdist in a virtualenv
493 echo "Creating virtualenv..."
498 rm -f $PYTHON_PKG*deb
499 echo "virtualenv version: `virtualenv --version`"
500 virtualenv_command="virtualenv --python `which $python` $DASHQ_UNLESS_DEBUG build/usr/share/$python/dist/$PYTHON_PKG"
502 if ! $virtualenv_command; then
503 echo "Error, unable to run"
504 echo " $virtualenv_command"
508 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip; then
509 echo "Error, unable to upgrade pip with"
510 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U pip"
513 echo "pip version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip --version`"
515 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools; then
516 echo "Error, unable to upgrade setuptools with"
517 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U setuptools"
520 echo "setuptools version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/$python -c 'import setuptools; print(setuptools.__version__)'`"
522 if ! build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel; then
523 echo "Error, unable to upgrade wheel with"
524 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -U wheel"
527 echo "wheel version: `build/usr/share/$python/dist/$PYTHON_PKG/bin/wheel version`"
529 if [[ "$TARGET" != "centos7" ]] || [[ "$PYTHON_PKG" != "python-arvados-fuse" ]]; then
530 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
532 # centos7 needs these special tweaks to install python-arvados-fuse
533 build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG docutils
534 PYCURL_SSL_LIBRARY=nss build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH
537 if [[ "$?" != "0" ]]; then
538 echo "Error, unable to run"
539 echo " build/usr/share/$python/dist/$PYTHON_PKG/bin/$pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG -f $PYSDK_PATH $PACKAGE_PATH"
543 cd build/usr/share/$python/dist/$PYTHON_PKG/
545 # Replace the shebang lines in all python scripts, and handle the activate
546 # scripts too This is a functional replacement of the 237 line
547 # virtualenv_tools.py script that doesn't work in python3 without serious
548 # patching, minus the parts we don't need (modifying pyc files, etc).
549 for binfile in `ls bin/`; do
550 if ! file --mime bin/$binfile |grep -q binary; then
552 if [[ "$binfile" =~ ^activate(.csh|.fish|)$ ]]; then
553 # these 'activate' scripts need special treatment
554 sed -i "s/VIRTUAL_ENV=\".*\"/VIRTUAL_ENV=\"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
555 sed -i "s/VIRTUAL_ENV \".*\"/VIRTUAL_ENV \"\/usr\/share\/$python\/dist\/$PYTHON_PKG\"/" bin/$binfile
557 if grep -q -E '^#!.*/bin/python\d?' bin/$binfile; then
558 # Replace shebang line
559 sed -i "1 s/^.*$/#!\/usr\/share\/$python\/dist\/$PYTHON_PKG\/bin\/python/" bin/$binfile
565 cd - >$STDOUT_IF_DEBUG
567 find build -iname '*.pyc' -exec rm {} \;
568 find build -iname '*.pyo' -exec rm {} \;
570 # Finally, generate the package
571 echo "Creating package..."
573 declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$FORMAT")
575 if [[ "$MAINTAINER" != "" ]]; then
576 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
579 if [[ "$VENDOR" != "" ]]; then
580 COMMAND_ARR+=('--vendor' "$VENDOR")
583 COMMAND_ARR+=('--url' 'https://arvados.org')
586 DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
587 COMMAND_ARR+=('--description' "$DESCRIPTION")
590 LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
591 COMMAND_ARR+=('--license' "$LICENSE_STRING")
593 # 12271 - As FPM-generated packages don't include scripts by default, the
594 # packages cleanup on upgrade depends on files being listed on the %files
595 # section in the generated SPEC files. To remove DIRECTORIES, they need to
596 # be listed in that sectiontoo, so we need to add this parameter to properly
597 # remove lingering dirs. But this only works for python2: if used on
598 # python33, it includes dirs like /opt/rh/python33 that belong to
600 if [[ "$FORMAT" == "rpm" ]] && [[ "$python" == "python2.7" ]]; then
601 COMMAND_ARR+=('--rpm-auto-add-directories')
604 if [[ "$PKG" == "arvados-python-client" ]]; then
605 if [[ "$python" == "python2.7" ]]; then
606 COMMAND_ARR+=('--conflicts' "$PYTHON3_PKG_PREFIX-$PKG")
608 COMMAND_ARR+=('--conflicts' "$PYTHON2_PKG_PREFIX-$PKG")
612 if [[ "$DEBUG" != "0" ]]; then
613 COMMAND_ARR+=('--verbose' '--log' 'info')
616 COMMAND_ARR+=('-v' "$PYTHON_VERSION")
617 COMMAND_ARR+=('--iteration' "$ARVADOS_BUILDING_ITERATION")
618 COMMAND_ARR+=('-n' "$PYTHON_PKG")
619 COMMAND_ARR+=('-C' "build")
621 if [[ -e "$WORKSPACE/$PKG_DIR/$PKG.service" ]]; then
622 COMMAND_ARR+=('--after-install' "${WORKSPACE}/build/go-python-package-scripts/postinst")
623 COMMAND_ARR+=('--before-remove' "${WORKSPACE}/build/go-python-package-scripts/prerm")
626 if [[ "$python" == "python2.7" ]]; then
627 COMMAND_ARR+=('--depends' "$PYTHON2_PACKAGE")
629 COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
633 COMMAND_ARR+=('--deb-no-default-config-files')
635 # Append --depends X and other arguments specified by fpm-info.sh in
636 # the package source dir. These are added last so they can override
637 # the arguments added by this script.
638 declare -a fpm_args=()
639 declare -a fpm_depends=()
641 fpminfo="$WORKSPACE/$PKG_DIR/fpm-info.sh"
642 if [[ -e "$fpminfo" ]]; then
643 echo "Loading fpm overrides from $fpminfo"
644 if ! source "$fpminfo"; then
645 echo "Error, unable to source $WORKSPACE/$PKG_DIR/fpm-info.sh for $PKG"
650 for i in "${fpm_depends[@]}"; do
651 COMMAND_ARR+=('--depends' "$i")
654 COMMAND_ARR+=("${fpm_args[@]}")
656 # Make sure to install all our package binaries in /usr/bin.
657 # We have to walk $WORKSPACE/$PKG_DIR/bin rather than
658 # $WORKSPACE/build/usr/share/$python/dist/$PYTHON_PKG/bin/ to get the list
659 # because the latter also includes all the python binaries for the virtualenv.
660 # We have to take the copies of our binaries from the latter directory, though,
661 # because those are the ones we rewrote the shebang line of, above.
662 if [[ -e "$WORKSPACE/$PKG_DIR/bin" ]]; then
663 for binary in `ls $WORKSPACE/$PKG_DIR/bin`; do
664 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/bin/$binary=/usr/bin/")
668 # the libpam module should place a few files in the correct place for the pam
670 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/lib/security/libpam_arvados.py" ]]; then
671 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/lib/security/libpam_arvados.py=/usr/lib/security/")
673 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/$python/dist/$PYTHON_PKG/share/pam-configs/arvados" ]]; then
674 COMMAND_ARR+=("usr/share/$python/dist/$PYTHON_PKG/share/pam-configs/arvados=/usr/share/pam-configs/")
677 # the python-arvados-cwl-runner package comes with cwltool, expose that version
678 if [[ -e "$WORKSPACE/$PKG_DIR/dist/build/usr/share/python2.7/dist/python-arvados-cwl-runner/bin/cwltool" ]]; then
679 COMMAND_ARR+=("usr/share/python2.7/dist/python-arvados-cwl-runner/bin/cwltool=/usr/bin/")
684 FPM_RESULTS=$("${COMMAND_ARR[@]}")
687 # if something went wrong and debug is off, print out the fpm command that errored
688 if ! fpm_verify $FPM_EXIT_CODE $FPM_RESULTS && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
689 echo "fpm returned an error executing the command:"
691 echo -e "\n${COMMAND_ARR[@]}\n"
694 mv $WORKSPACE/$PKG_DIR/dist/*$FORMAT $WORKSPACE/packages/$TARGET/
699 # Build packages for everything
701 # The package source. Depending on the source type, this can be a
702 # path, or the name of the package in an upstream repository (e.g.,
706 # The name of the package to build.
709 # The type of source package. Passed to fpm -s. Default "dir".
710 PACKAGE_TYPE=${1:-dir}
712 # Optional: the package version number. Passed to fpm -v.
716 if [[ -n "$ONLY_BUILD" ]] && [[ "$PACKAGE_NAME" != "$ONLY_BUILD" ]] && [[ "$PACKAGE" != "$ONLY_BUILD" ]] ; then
717 # arvados-workbench depends on arvados-server at build time, so even when
718 # only arvados-workbench is being built, we need to build arvados-server too
719 if [[ "$PACKAGE_NAME" != "arvados-server" ]] || [[ "$ONLY_BUILD" != "arvados-workbench" ]]; then
724 local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
726 declare -a COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
727 if [ python = "$PACKAGE_TYPE" ] && [ deb = "$FORMAT" ]; then
728 # Dependencies are built from setup.py. Since setup.py will never
729 # refer to Debian package iterations, it doesn't make sense to
730 # enforce those in the .deb dependencies.
731 COMMAND_ARR+=(--deb-ignore-iteration-in-dependencies)
734 # 12271 - As FPM-generated packages don't include scripts by default, the
735 # packages cleanup on upgrade depends on files being listed on the %files
736 # section in the generated SPEC files. To remove DIRECTORIES, they need to
737 # be listed in that section too, so we need to add this parameter to properly
738 # remove lingering dirs. But this only works for python2: if used on
739 # python33, it includes dirs like /opt/rh/python33 that belong to
741 if [[ "$FORMAT" = rpm ]] && [[ "$python" = python2.7 ]]; then
742 COMMAND_ARR+=('--rpm-auto-add-directories')
745 if [[ "$DEBUG" != "0" ]]; then
746 COMMAND_ARR+=('--verbose' '--log' 'info')
749 if [[ -n "$PACKAGE_NAME" ]]; then
750 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
753 if [[ "$MAINTAINER" != "" ]]; then
754 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
757 if [[ "$VENDOR" != "" ]]; then
758 COMMAND_ARR+=('--vendor' "$VENDOR")
761 if [[ "$VERSION" != "" ]]; then
762 COMMAND_ARR+=('-v' "$VERSION")
764 if [[ -n "$default_iteration_value" ]]; then
765 # We can always add an --iteration here. If another one is specified in $@,
766 # that will take precedence, as desired.
767 COMMAND_ARR+=(--iteration "$default_iteration_value")
770 # Append --depends X and other arguments specified by fpm-info.sh in
771 # the package source dir. These are added last so they can override
772 # the arguments added by this script.
773 declare -a fpm_args=()
774 declare -a build_depends=()
775 declare -a fpm_depends=()
776 declare -a fpm_exclude=()
777 declare -a fpm_dirs=(
778 # source dir part of 'dir' package ("/source=/dest" => "/source"):
780 for pkgdir in "${fpm_dirs[@]}"; do
781 fpminfo="$pkgdir/fpm-info.sh"
782 if [[ -e "$fpminfo" ]]; then
783 debug_echo "Loading fpm overrides from $fpminfo"
788 for pkg in "${build_depends[@]}"; do
789 if [[ $TARGET =~ debian|ubuntu ]]; then
790 pkg_deb=$(ls "$WORKSPACE/packages/$TARGET/$pkg_"*.deb | sort -rg | awk 'NR==1')
791 if [[ -e $pkg_deb ]]; then
792 echo "Installing build_dep $pkg from $pkg_deb"
795 echo "Attemping to install build_dep $pkg using apt-get"
796 apt-get install -y "$pkg"
798 apt-get -y -f install
800 pkg_rpm=$(ls "$WORKSPACE/packages/$TARGET/$pkg"-[0-9]*.rpm | sort -rg | awk 'NR==1')
801 if [[ -e $pkg_rpm ]]; then
802 echo "Installing build_dep $pkg from $pkg_rpm"
805 echo "Attemping to install build_dep $pkg"
810 for i in "${fpm_depends[@]}"; do
811 COMMAND_ARR+=('--depends' "$i")
813 for i in "${fpm_exclude[@]}"; do
814 COMMAND_ARR+=('--exclude' "$i")
817 # Append remaining function arguments directly to fpm's command line.
822 COMMAND_ARR+=("${fpm_args[@]}")
824 COMMAND_ARR+=("$PACKAGE")
826 debug_echo -e "\n${COMMAND_ARR[@]}\n"
828 FPM_RESULTS=$("${COMMAND_ARR[@]}")
831 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
833 # if something went wrong and debug is off, print out the fpm command that errored
834 if [[ 0 -ne $? ]] && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
835 echo -e "\n${COMMAND_ARR[@]}\n"
839 # verify build results
846 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
847 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
850 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
853 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
858 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
859 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
861 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
863 echo "Error building package for $1:\n $FPM_RESULTS"
870 if [[ "$FORMAT" == "deb" ]]; then
871 $SUDO apt-get install $PACKAGES --yes
872 elif [[ "$FORMAT" == "rpm" ]]; then
873 $SUDO yum -q -y install $PACKAGES
878 printf '%s %s\n' "=======" "$1"
882 if [[ "$1" != "0" ]]; then
884 failures+=("$2 (`timer`)")
886 successes+=("$2 (`timer`)")
895 echo -n "$(($SECONDS - $t0))s"
899 for x in "${successes[@]}"
904 if [[ ${#failures[@]} == 0 ]]
906 if [[ ${#successes[@]} != 0 ]]; then
907 echo "All test suites passed."
910 echo "Failures (${#failures[@]}):"
911 for x in "${failures[@]}"