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 local dir="${1:-.}"; shift
44 TZ=UTC git log -n1 --first-parent "--format=format:$format" "$dir"
48 # Output the version being built, or if we're building a
49 # dev/prerelease, output a version number based on the git log for
51 local subdir="$1"; shift
52 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
53 echo "$ARVADOS_BUILDING_VERSION"
58 declare $(format_last_commit_here "git_ts=%ct git_hash=%h" "$subdir")
59 ARVADOS_BUILDING_VERSION="$($WORKSPACE/build/version-at-commit.sh $git_hash)"
60 echo "$ARVADOS_BUILDING_VERSION"
63 nohash_version_from_git() {
64 local subdir="$1"; shift
65 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
66 echo "$ARVADOS_BUILDING_VERSION"
69 version_from_git $subdir | cut -d. -f1-4
72 timestamp_from_git() {
73 local subdir="$1"; shift
74 format_last_commit_here "%ct" "$subdir"
77 calculate_python_sdk_cwl_package_versions() {
78 python_sdk_version=$(cd sdk/python && python3 arvados_version.py)
79 cwl_runner_version=$(cd sdk/cwl && python3 arvados_version.py)
82 # Usage: get_native_arch
84 # Only amd64 and aarch64 are supported at the moment
94 echo "Error: architecture not supported"
102 local gem_name="$1"; shift
103 local gem_version="$(nohash_version_from_git)"
104 local gem_src_dir="$(pwd)"
106 if [[ -n "$ONLY_BUILD" ]] && [[ "$gem_name" != "$ONLY_BUILD" ]] ; then
110 if ! [[ -e "${gem_name}-${gem_version}.gem" ]]; then
111 find -maxdepth 1 -name "${gem_name}-*.gem" -delete
113 # -q appears to be broken in gem version 2.2.2
114 $GEM build "$gem_name.gemspec" $DASHQ_UNLESS_DEBUG >"$STDOUT_IF_DEBUG" 2>"$STDERR_IF_DEBUG"
118 # Usage: package_workbench2
119 package_workbench2() {
120 local pkgname=arvados-workbench2
121 local src=services/workbench2
122 local dst=/var/www/arvados-workbench2/workbench2
123 local description="Arvados Workbench 2"
124 local version="$(version_from_git)"
127 NODE_ENV=production yarn install
128 VERSION="$version" BUILD_NUMBER="$(default_iteration "$pkgname" "$version" yarn)" GIT_COMMIT="$(git rev-parse HEAD | head -c9)" yarn build
129 cd "$WORKSPACE/packages/$TARGET"
130 fpm_build "${WORKSPACE}/$src" "${WORKSPACE}/$src/build/=$dst" "$pkgname" dir "$version" \
131 --license="GNU Affero General Public License, version 3.0" \
132 --description="${description}" \
133 --config-files="/etc/arvados/$pkgname/workbench2.example.json" \
134 "$WORKSPACE/services/workbench2/etc/arvados/workbench2/workbench2.example.json=/etc/arvados/$pkgname/workbench2.example.json"
137 calculate_go_package_version() {
138 # $__returnvar has the nameref attribute set, which means it is a reference
139 # to another variable that is passed in as the first argument to this function.
140 # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
141 local -n __returnvar="$1"; shift
147 # Update the version number and build a new package if the vendor
148 # bundle has changed, or the command imports anything from the
149 # Arvados SDK and the SDK has changed.
150 declare -a checkdirs=(go.mod go.sum)
151 while [ -n "$1" ]; do
155 # Even our rails packages (version calculation happens here!) depend on a go component (arvados-server)
156 # Everything depends on the build directory.
157 checkdirs+=(sdk/go lib build)
159 for dir in ${checkdirs[@]}; do
161 ts="$(timestamp_from_git "$dir")"
162 if [[ "$ts" -gt "$timestamp" ]]; then
163 version=$(version_from_git "$dir")
168 __returnvar="$version"
171 # Usage: package_go_binary services/foo arvados-foo [deb|rpm] [amd64|arm64] "Compute foo to arbitrary precision" [apache-2.0.txt]
172 package_go_binary() {
173 local src_path="$1"; shift
174 local prog="$1"; shift
175 local package_format="$1"; shift
176 local target_arch="$1"; shift
177 local description="$1"; shift
178 local license_file="${1:-agpl-3.0.txt}"; shift
180 if [[ -n "$ONLY_BUILD" ]] && [[ "$prog" != "$ONLY_BUILD" ]]; then
181 debug_echo -e "Skipping build of $prog package."
185 native_arch=$(get_native_arch)
187 if [[ "$native_arch" != "amd64" ]] && [[ -n "$target_arch" ]] && [[ "$native_arch" != "$target_arch" ]]; then
188 echo "Error: no cross compilation support for Go on $native_arch, can not build $prog for $target_arch"
192 case "$package_format-$TARGET" in
193 # Older Debian/Ubuntu do not support cross compilation because the
194 # libfuse package does not support multiarch. See
195 # <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=983477>.
196 # Red Hat-based distributions do not support native cross compilation at
197 # all (they use a qemu-based solution we haven't implemented yet).
198 deb-debian10|deb-ubuntu1804|deb-ubuntu2004|rpm-*)
200 if [[ "$native_arch" == "amd64" ]] && [[ -n "$target_arch" ]] && [[ "$native_arch" != "$target_arch" ]]; then
201 echo "Error: no cross compilation support for Go on $native_arch for $TARGET, can not build $prog for $target_arch"
210 if [[ -n "$target_arch" ]]; then
213 # No target architecture specified, default to native target. When on amd64
214 # also crosscompile arm64 (when supported).
216 if [[ $cross_compilation -ne 0 ]]; then
221 for ta in ${archs[@]}; do
222 package_go_binary_worker "$src_path" "$prog" "$package_format" "$description" "$native_arch" "$ta" "$license_file"
224 if [[ $retval -ne 0 ]]; then
230 # Usage: package_go_binary services/foo arvados-foo deb "Compute foo to arbitrary precision" [amd64/arm64] [amd64/arm64] [apache-2.0.txt]
231 package_go_binary_worker() {
232 local src_path="$1"; shift
233 local prog="$1"; shift
234 local package_format="$1"; shift
235 local description="$1"; shift
236 local native_arch="${1:-amd64}"; shift
237 local target_arch="${1:-amd64}"; shift
238 local license_file="${1:-agpl-3.0.txt}"; shift
240 debug_echo "package_go_binary $src_path as $prog (native arch: $native_arch, target arch: $target_arch)"
241 local basename="${src_path##*/}"
242 calculate_go_package_version go_package_version $src_path
244 cd $WORKSPACE/packages/$TARGET
245 test_package_presence "$prog" "$go_package_version" "go" "" "$target_arch"
246 if [[ $? -ne 0 ]]; then
250 echo "Building $package_format ($target_arch) package for $prog from $src_path"
251 if [[ "$native_arch" == "amd64" ]] && [[ "$target_arch" == "arm64" ]]; then
252 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=${target_arch} go install -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path"
254 GOARCH=${arch} go install -ldflags "-X git.arvados.org/arvados.git/lib/cmd.version=${go_package_version} -X main.version=${go_package_version}" "git.arvados.org/arvados.git/$src_path"
259 binpath=$GOPATH/bin/${basename}
260 if [[ "${target_arch}" != "${native_arch}" ]]; then
261 switches+=("-a${target_arch}")
262 binpath="$GOPATH/bin/linux_${target_arch}/${basename}"
265 systemd_unit="$WORKSPACE/${src_path}/${prog}.service"
266 if [[ -e "${systemd_unit}" ]]; then
268 --after-install "${WORKSPACE}/build/go-python-package-scripts/postinst"
269 --before-remove "${WORKSPACE}/build/go-python-package-scripts/prerm"
270 "${systemd_unit}=/lib/systemd/system/${prog}.service")
272 switches+=("$WORKSPACE/${license_file}=/usr/share/doc/$prog/${license_file}")
274 fpm_build "${WORKSPACE}/${src_path}" "$binpath=/usr/bin/${prog}" "${prog}" dir "${go_package_version}" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=${description}" "${switches[@]}"
277 # Usage: package_go_so lib/foo arvados_foo.so arvados-foo deb amd64 "Arvados foo library"
279 local src_path="$1"; shift
280 local sofile="$1"; shift
281 local pkg="$1"; shift
282 local package_format="$1"; shift
283 local target_arch="$1"; shift # supported: amd64, arm64
284 local description="$1"; shift
286 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkg" != "$ONLY_BUILD" ]]; then
287 debug_echo -e "Skipping build of $pkg package."
291 debug_echo "package_go_so $src_path as $pkg"
293 calculate_go_package_version go_package_version $src_path
294 cd $WORKSPACE/packages/$TARGET
295 test_package_presence $pkg $go_package_version go || return 1
296 cd $WORKSPACE/$src_path
297 go build -buildmode=c-shared -o ${GOPATH}/bin/${sofile}
298 cd $WORKSPACE/packages/$TARGET
300 "--url=https://arvados.org"
301 "--license=Apache License, Version 2.0"
302 "--description=${description}"
303 "$WORKSPACE/apache-2.0.txt=/usr/share/doc/$pkg/apache-2.0.txt"
305 if [[ -e "$WORKSPACE/$src_path/pam-configs-arvados" ]]; then
306 fpmargs+=("$WORKSPACE/$src_path/pam-configs-arvados=/usr/share/doc/$pkg/pam-configs-arvados-go")
308 if [[ -e "$WORKSPACE/$src_path/README" ]]; then
309 fpmargs+=("$WORKSPACE/$src_path/README=/usr/share/doc/$pkg/README")
311 fpm_build "${WORKSPACE}/${src_path}" "$GOPATH/bin/${sofile}=/usr/lib/${sofile}" "${pkg}" dir "${go_package_version}" "${fpmargs[@]}"
314 default_iteration() {
315 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
316 echo "$ARVADOS_BUILDING_ITERATION"
319 local package_name="$1"; shift
320 local package_version="$1"; shift
321 local package_type="$1"; shift
323 if [[ $package_version =~ ^0\.1\.([0-9]{14})(\.|$) ]] && \
324 [[ ${BASH_REMATCH[1]} -le $LICENSE_PACKAGE_TS ]]; then
330 _build_rails_package_scripts() {
331 local pkgname="$1"; shift
332 local destdir="$1"; shift
333 local srcdir="$RUN_BUILD_PACKAGES_PATH/rails-package-scripts"
334 for scriptname in postinst prerm postrm; do
335 cat "$srcdir/$pkgname.sh" "$srcdir/step2.sh" "$srcdir/$scriptname.sh" \
336 >"$destdir/$scriptname" || return $?
340 rails_package_version() {
341 local pkgname="$1"; shift
342 local srcdir="$1"; shift
343 if [[ -n "$ARVADOS_BUILDING_VERSION" ]]; then
344 echo "$ARVADOS_BUILDING_VERSION"
347 local version="$(version_from_git)"
348 if [ $pkgname = "arvados-api-server" ] ; then
349 calculate_go_package_version version cmd/arvados-server "$srcdir"
354 test_rails_package_presence() {
355 local pkgname="$1"; shift
356 local srcdir="$1"; shift
358 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
366 local version="$(rails_package_version "$pkgname" "$srcdir")"
370 test_package_presence $pkgname $version rails "$RAILS_PACKAGE_ITERATION"
373 get_complete_package_name() {
374 # if the errexit flag is set, unset it until this function returns
375 # otherwise, the shift calls below will abort the program if optional arguments are not supplied
376 if [ -o errexit ]; then
380 # $__returnvar has the nameref attribute set, which means it is a reference
381 # to another variable that is passed in as the first argument to this function.
382 # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html
383 local -n __returnvar="$1"; shift
384 local pkgname="$1"; shift
385 local version="$1"; shift
386 local pkgtype="$1"; shift
387 local iteration="$1"; shift
388 local arch="$1"; shift
389 if [[ "$iteration" == "" ]]; then
390 iteration="$(default_iteration "$pkgname" "$version" "$pkgtype")"
393 if [[ "$arch" == "" ]]; then
394 native_arch=$(get_native_arch)
395 rpm_native_arch="x86_64"
396 if [[ "$HOSTTYPE" == "aarch64" ]]; then
397 rpm_native_arch="arm64"
399 rpm_architecture="$rpm_native_arch"
400 deb_architecture="$native_arch"
402 if [[ "$pkgtype" =~ ^(src)$ ]]; then
403 rpm_architecture="noarch"
404 deb_architecture="all"
407 rpm_architecture=$arch
408 deb_architecture=$arch
411 local complete_pkgname="${pkgname}_$version${iteration:+-$iteration}_$deb_architecture.deb"
412 if [[ "$FORMAT" == "rpm" ]]; then
413 # rpm packages get iteration 1 if we don't supply one
414 iteration=${iteration:-1}
415 complete_pkgname="$pkgname-$version-${iteration}.$rpm_architecture.rpm"
417 __returnvar=${complete_pkgname}
420 # Test if the package already exists, if not return 0, if it does return 1
421 test_package_presence() {
422 local pkgname="$1"; shift
423 local version="$1"; shift
424 local pkgtype="$1"; shift
425 local iteration="$1"; shift
426 local arch="$1"; shift
427 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
432 get_complete_package_name full_pkgname "$pkgname" "$version" "$pkgtype" "$iteration" "$arch"
434 # See if we can skip building the package, only if it already exists in the
435 # processed/ directory. If so, move it back to the packages directory to make
436 # sure it gets picked up by the test and/or upload steps.
437 # Get the list of packages from the repos
439 if [[ "$FORCE_BUILD" == "1" ]]; then
440 echo "Package $full_pkgname build forced with --force-build, building"
441 elif [[ "$FORMAT" == "deb" ]]; then
444 dd[debian11]=bullseye
445 dd[debian12]=bookworm
446 dd[ubuntu1804]=bionic
450 if [ ${pkgname:0:3} = "lib" ]; then
451 repo_subdir=${pkgname:0:4}
453 repo_subdir=${pkgname:0:1}
456 repo_pkg_list=$(curl -s -o - http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/)
457 echo "${repo_pkg_list}" |grep -q ${full_pkgname}
458 if [ $? -eq 0 ] ; then
459 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
460 curl -s -o "$WORKSPACE/packages/$TARGET/${full_pkgname}" http://apt.arvados.org/${D}/pool/main/${repo_subdir}/${pkgname}/${full_pkgname}
462 elif test -f "$WORKSPACE/packages/$TARGET/processed/${full_pkgname}" ; then
463 echo "Package $full_pkgname exists, not rebuilding!"
466 echo "Package $full_pkgname not found, building"
472 centos7) rpm_root="CentOS/7/dev" ;;
473 rocky8) rpm_root="CentOS/8/dev" ;;
475 echo "FIXME: Don't know RPM URL path for $TARGET, building"
479 local rpm_url="http://rpm.arvados.org/$rpm_root/$arch/$full_pkgname"
481 if curl -fs -o "$WORKSPACE/packages/$TARGET/$full_pkgname" "$rpm_url"; then
482 echo "Package $full_pkgname exists upstream, not rebuilding, downloading instead!"
484 elif [[ -f "$WORKSPACE/packages/$TARGET/processed/$full_pkgname" ]]; then
485 echo "Package $full_pkgname exists, not rebuilding!"
488 echo "Package $full_pkgname not found, building"
494 handle_rails_package() {
495 local pkgname="$1"; shift
497 if [[ -n "$ONLY_BUILD" ]] && [[ "$pkgname" != "$ONLY_BUILD" ]] ; then
500 local srcdir="$1"; shift
502 local license_path="$1"; shift
503 local version="$(rails_package_version "$pkgname" "$srcdir")"
504 echo "$version" >package-build.version
505 local scripts_dir="$(mktemp --tmpdir -d "$pkgname-XXXXXXXX.scripts")" && \
508 _build_rails_package_scripts "$pkgname" "$scripts_dir"
511 git rev-parse HEAD >git-commit.version
512 bundle config set cache_all true
515 if [[ 0 != "$?" ]] || ! cd "$WORKSPACE/packages/$TARGET"; then
516 echo "ERROR: $pkgname package prep failed" >&2
517 rm -rf "$scripts_dir"
521 local railsdir="/var/www/${pkgname%-server}/current"
522 local -a pos_args=("$srcdir/=$railsdir" "$pkgname" dir "$version")
523 local license_arg="$license_path=$railsdir/$(basename "$license_path")"
524 local -a switches=(--after-install "$scripts_dir/postinst"
525 --before-remove "$scripts_dir/prerm"
526 --after-remove "$scripts_dir/postrm")
527 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
528 switches+=(--iteration $RAILS_PACKAGE_ITERATION)
530 # For some reason fpm excludes need to not start with /.
531 local exclude_root="${railsdir#/}"
532 for exclude in tmp log coverage Capfile\* \
534 config/application.yml \
535 config/database.yml; do
536 switches+=(-x "$exclude_root/$exclude")
538 fpm_build "${srcdir}" "${pos_args[@]}" "${switches[@]}" \
539 -x "$exclude_root/vendor/cache-*" \
540 -x "$exclude_root/vendor/bundle" "$@" "$license_arg"
541 rm -rf "$scripts_dir"
544 # Usage: handle_api_server [amd64|arm64]
545 handle_api_server () {
546 local target_arch="${1:-amd64}"; shift
548 if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "arvados-api-server" ]] ; then
549 debug_echo -e "Skipping build of arvados-api-server package."
553 native_arch=$(get_native_arch)
554 if [[ "$target_arch" != "$native_arch" ]]; then
555 echo "Error: no cross compilation support for Rails yet, can not build arvados-api-server for $ARCH"
560 # Build the API server package
561 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
562 if [[ "$?" == "0" ]]; then
563 calculate_go_package_version arvados_server_version cmd/arvados-server
564 arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
565 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
566 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
567 --description="Arvados API server - Arvados is a free and open source platform for big data science." \
568 --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
572 # Usage: handle_cwltest [deb|rpm] [amd64|arm64]
574 local package_format="$1"; shift
575 local target_arch="${1:-amd64}"; shift
577 if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "python3-cwltest" ]] ; then
578 debug_echo -e "Skipping build of cwltest package."
582 if [[ -e "$WORKSPACE/cwltest" ]]; then
583 rm -rf "$WORKSPACE/cwltest"
585 git clone https://github.com/common-workflow-language/cwltest.git
587 # The subsequent release of cwltest confirms that files exist on disk, since
588 # our files are in Keep, all the tests fail.
589 # We should add [optional] Arvados support to cwltest so it can access
590 # Keep but for the time being just package the last working version.
591 (cd cwltest && git checkout 2.3.20230108193615)
593 # signal to our build script that we want a cwltest executable installed in /usr/bin/
594 mkdir cwltest/bin && touch cwltest/bin/cwltest
595 fpm_build_virtualenv "cwltest" "cwltest" "$package_format" "$target_arch"
597 rm -rf "$WORKSPACE/cwltest"
600 # Usage: handle_arvados_src
601 handle_arvados_src () {
602 if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "arvados-src" ]] ; then
603 debug_echo -e "Skipping build of arvados-src package."
609 COMMIT_HASH=$(format_last_commit_here "%H")
610 arvados_src_version="$(version_from_git)"
612 cd $WORKSPACE/packages/$TARGET
613 test_package_presence arvados-src "$arvados_src_version" src ""
615 if [[ "$?" == "0" ]]; then
617 SRC_BUILD_DIR=$(mktemp -d)
618 # mktemp creates the directory with 0700 permissions by default
619 chmod 755 $SRC_BUILD_DIR
620 git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
623 # go into detached-head state
624 git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
625 echo "$COMMIT_HASH" >git-commit.version
627 cd $WORKSPACE/packages/$TARGET
628 fpm_build "$WORKSPACE" $SRC_BUILD_DIR/=/usr/local/arvados/src arvados-src 'dir' "$arvados_src_version" "--exclude=usr/local/arvados/src/.git" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=The Arvados source code" "--architecture=all"
630 rm -rf "$SRC_BUILD_DIR"
635 # Build python packages with a virtualenv built-in
636 # Usage: fpm_build_virtualenv arvados-python-client sdk/python [deb|rpm] [amd64|arm64]
637 fpm_build_virtualenv () {
639 local pkg_dir=$1; shift
640 local package_format="$1"; shift
641 local target_arch="${1:-amd64}"; shift
643 native_arch=$(get_native_arch)
645 if [[ "$pkg" != "arvados-docker-cleaner" ]]; then
646 PYTHON_PKG=$PYTHON3_PKG_PREFIX-$pkg
648 # Exception to our package naming convention
652 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]]; then
653 # arvados-python-client sdist should always be built if we are building a
655 if [[ "$ONLY_BUILD" != "python3-arvados-cwl-runner" ]] &&
656 [[ "$ONLY_BUILD" != "python3-arvados-fuse" ]] &&
657 [[ "$ONLY_BUILD" != "python3-crunchstat-summary" ]] &&
658 [[ "$ONLY_BUILD" != "arvados-docker-cleaner" ]] &&
659 [[ "$ONLY_BUILD" != "python3-arvados-user-activity" ]]; then
660 debug_echo -e "Skipping build of $pkg package."
665 if [[ -n "$target_arch" ]] && [[ "$native_arch" == "$target_arch" ]]; then
666 fpm_build_virtualenv_worker "$pkg" "$pkg_dir" "$package_format" "$native_arch" "$target_arch"
667 elif [[ -z "$target_arch" ]]; then
668 fpm_build_virtualenv_worker "$pkg" "$pkg_dir" "$package_format" "$native_arch" "$native_arch"
670 echo "Error: no cross compilation support for Python yet, can not build $pkg for $target_arch"
675 # Build python packages with a virtualenv built-in
676 # Usage: fpm_build_virtualenv_worker arvados-python-client sdk/python python3 [deb|rpm] [amd64|arm64] [amd64|arm64]
677 fpm_build_virtualenv_worker () {
680 local package_format="$1"; shift
681 local native_arch="${1:-amd64}"; shift
682 local target_arch=${1:-amd64}; shift
685 STDOUT_IF_DEBUG=/dev/null
686 STDERR_IF_DEBUG=/dev/null
687 DASHQ_UNLESS_DEBUG=-q
688 if [[ "$DEBUG" != "0" ]]; then
689 STDOUT_IF_DEBUG=/dev/stdout
690 STDERR_IF_DEBUG=/dev/stderr
693 if [[ "$ARVADOS_BUILDING_ITERATION" == "" ]]; then
694 ARVADOS_BUILDING_ITERATION=1
697 PACKAGE_PREFIX=$PYTHON3_PKG_PREFIX
698 if [[ "$PKG" != "arvados-docker-cleaner" ]]; then
699 PYTHON_PKG=$PACKAGE_PREFIX-$PKG
701 # Exception to our package naming convention
705 cd $WORKSPACE/$PKG_DIR
708 local venv_dir="dist/build/usr/share/python$PYTHON3_VERSION/dist/$PYTHON_PKG"
709 echo "Creating virtualenv..."
710 if ! "$PYTHON3_EXECUTABLE" -m venv "$venv_dir"; then
711 printf "Error, unable to run\n %s -m venv %s\n" "$PYTHON3_EXECUTABLE" "$venv_dir"
715 local venv_py="$venv_dir/bin/python$PYTHON3_VERSION"
716 if ! "$venv_py" -m pip install --upgrade $DASHQ_UNLESS_DEBUG $CACHE_FLAG pip setuptools wheel; then
717 printf "Error, unable to upgrade pip, setuptools, and wheel with
718 %s -m pip install --upgrade $DASHQ_UNLESS_DEBUG $CACHE_FLAG pip setuptools wheel
723 # filter a useless warning (when building the cwltest package) from the stderr output
724 if ! "$venv_py" setup.py $DASHQ_UNLESS_DEBUG sdist 2> >(grep -v 'warning: no previously-included files matching'); then
725 echo "Error, unable to run $venv_py setup.py sdist for $PKG"
729 if [[ "arvados-python-client" == "$PKG" ]]; then
730 PYSDK_PATH="-f $(pwd)/dist/"
733 if [[ -n "$ONLY_BUILD" ]] && [[ "$PYTHON_PKG" != "$ONLY_BUILD" ]] && [[ "$PKG" != "$ONLY_BUILD" ]]; then
737 # Determine the package version from the generated sdist archive
738 if [[ -n "$ARVADOS_BUILDING_VERSION" ]] ; then
739 UNFILTERED_PYTHON_VERSION=$ARVADOS_BUILDING_VERSION
740 PYTHON_VERSION=$(echo -n $ARVADOS_BUILDING_VERSION | sed s/~dev/.dev/g | sed s/~rc/rc/g)
742 PYTHON_VERSION=$(awk '($1 == "Version:"){print $2}' *.egg-info/PKG-INFO)
743 UNFILTERED_PYTHON_VERSION=$(echo -n $PYTHON_VERSION | sed s/\.dev/~dev/g |sed 's/\([0-9]\)rc/\1~rc/g')
746 # See if we actually need to build this package; does it exist already?
747 # We can't do this earlier than here, because we need PYTHON_VERSION.
748 if ! test_package_presence "$PYTHON_PKG" "$UNFILTERED_PYTHON_VERSION" python3 "$ARVADOS_BUILDING_ITERATION" "$target_arch"; then
752 echo "Building $package_format ($target_arch) package for $PKG from $PKG_DIR"
754 local sdist_path="$(ls dist/*.tar.gz)"
755 if ! "$venv_py" -m pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG $PYSDK_PATH "$sdist_path"; then
756 printf "Error, unable to run
757 %s -m pip install $DASHQ_UNLESS_DEBUG $CACHE_FLAG %s %s
758 " "$venv_py" "$PYSDK_PATH" "$sdist_path"
762 pushd "$venv_dir" >$STDOUT_IF_DEBUG
764 # Replace the shebang lines in all python scripts, and handle the activate
765 # scripts too. This is a functional replacement of the 237 line
766 # virtualenv_tools.py script that doesn't work in python3 without serious
767 # patching, minus the parts we don't need (modifying pyc files, etc).
768 local sys_venv_dir="${venv_dir#dist/build/}"
769 local sys_venv_py="$sys_venv_dir/bin/python$PYTHON3_VERSION"
770 for binfile in `ls bin/`; do
771 if file --mime "bin/$binfile" | grep -q binary; then
772 : # Nothing to do for binary files
773 elif [[ "$binfile" =~ ^activate(.csh|.fish|)$ ]]; then
774 sed -ri "s@VIRTUAL_ENV(=| )\".*\"@VIRTUAL_ENV\\1\"/$sys_venv_dir\"@" "bin/$binfile"
776 # Replace shebang line
777 sed -ri "1 s@^#\![^[:space:]]+/bin/python[0-9.]*@#\!/$sys_venv_py@" "bin/$binfile"
781 popd >$STDOUT_IF_DEBUG
784 find build -iname '*.py[co]' -delete
786 # Finally, generate the package
787 echo "Creating package..."
789 declare -a COMMAND_ARR=("fpm" "-s" "dir" "-t" "$package_format")
791 if [[ -n "$target_arch" ]] && [[ "$target_arch" != "amd64" ]]; then
792 COMMAND_ARR+=("-a$target_arch")
795 if [[ "$MAINTAINER" != "" ]]; then
796 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
799 if [[ "$VENDOR" != "" ]]; then
800 COMMAND_ARR+=('--vendor' "$VENDOR")
803 COMMAND_ARR+=('--url' 'https://arvados.org')
806 DESCRIPTION=`grep '\sdescription' $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
807 COMMAND_ARR+=('--description' "$DESCRIPTION")
810 LICENSE_STRING=`grep license $WORKSPACE/$PKG_DIR/setup.py|cut -f2 -d=|sed -e "s/[',\\"]//g"`
811 COMMAND_ARR+=('--license' "$LICENSE_STRING")
813 if [[ "$DEBUG" != "0" ]]; then
814 COMMAND_ARR+=('--verbose' '--log' 'info')
817 COMMAND_ARR+=('-v' $(echo -n "$PYTHON_VERSION" | sed s/.dev/~dev/g | sed s/rc/~rc/g))
818 COMMAND_ARR+=('--iteration' "$ARVADOS_BUILDING_ITERATION")
819 COMMAND_ARR+=('-n' "$PYTHON_PKG")
820 COMMAND_ARR+=('-C' "build")
822 systemd_unit="$WORKSPACE/$PKG_DIR/$PKG.service"
823 if [[ -e "${systemd_unit}" ]]; then
824 COMMAND_ARR+=('--after-install' "${WORKSPACE}/build/go-python-package-scripts/postinst")
825 COMMAND_ARR+=('--before-remove' "${WORKSPACE}/build/go-python-package-scripts/prerm")
828 COMMAND_ARR+=('--depends' "$PYTHON3_PACKAGE")
829 case "$package_format" in
833 --deb-no-default-config-files
837 # Conflict with older packages we used to publish
838 --conflicts "rh-python36-python-$PKG"
839 # Do not generate /usr/lib/.build-id links on RH8+
840 # (otherwise our packages conflict with platform-python)
841 --rpm-rpmbuild-define "_build_id_links none"
845 # Append --depends X and other arguments specified by fpm-info.sh in
846 # the package source dir. These are added last so they can override
847 # the arguments added by this script.
848 declare -a fpm_args=()
849 declare -a fpm_depends=()
851 fpminfo="$WORKSPACE/$PKG_DIR/fpm-info.sh"
852 if [[ -e "$fpminfo" ]]; then
853 echo "Loading fpm overrides from $fpminfo"
854 if ! source "$fpminfo"; then
855 echo "Error, unable to source $WORKSPACE/$PKG_DIR/fpm-info.sh for $PKG"
860 for i in "${fpm_depends[@]}"; do
861 COMMAND_ARR+=('--depends' "$i")
864 for i in "${fpm_depends[@]}"; do
865 COMMAND_ARR+=('--replaces' "python-$PKG")
868 # make sure the systemd service file ends up in the right place
869 # used by arvados-docker-cleaner
870 if [[ -e "${systemd_unit}" ]]; then
871 COMMAND_ARR+=("usr/share/python$PYTHON3_VERSION/dist/$PKG/share/doc/$PKG/$PKG.service=/lib/systemd/system/$PKG.service")
874 COMMAND_ARR+=("${fpm_args[@]}")
876 # Make sure to install all our package binaries in /usr/bin.
877 # We have to walk $WORKSPACE/$PKG_DIR/bin rather than
878 # $WORKSPACE/build/usr/share/$python/dist/$PYTHON_PKG/bin/ to get the list
879 # because the latter also includes all the python binaries for the virtualenv.
880 # We have to take the copies of our binaries from the latter directory, though,
881 # because those are the ones we rewrote the shebang line of, above.
882 if [[ -e "$WORKSPACE/$PKG_DIR/bin" ]]; then
883 for binary in `ls $WORKSPACE/$PKG_DIR/bin`; do
884 COMMAND_ARR+=("$sys_venv_dir/bin/$binary=/usr/bin/")
888 # the python3-arvados-cwl-runner package comes with cwltool, expose that version
889 if [[ -e "$WORKSPACE/$PKG_DIR/$venv_dir/bin/cwltool" ]]; then
890 COMMAND_ARR+=("$sys_venv_dir/bin/cwltool=/usr/bin/")
895 debug_echo -e "\n${COMMAND_ARR[@]}\n"
897 FPM_RESULTS=$("${COMMAND_ARR[@]}")
900 # if something went wrong and debug is off, print out the fpm command that errored
901 if ! fpm_verify $FPM_EXIT_CODE $FPM_RESULTS && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
902 echo "fpm returned an error executing the command:"
904 echo -e "\n${COMMAND_ARR[@]}\n"
906 echo `ls *$package_format`
907 mv $WORKSPACE/$PKG_DIR/dist/*$package_format $WORKSPACE/packages/$TARGET/
912 # Build packages for everything
914 # Source dir where fpm-info.sh (if any) will be found.
917 # The package source. Depending on the source type, this can be a
918 # path, or the name of the package in an upstream repository (e.g.,
922 # The name of the package to build.
925 # The type of source package. Passed to fpm -s. Default "dir".
926 PACKAGE_TYPE=${1:-dir}
928 # Optional: the package version number. Passed to fpm -v.
932 if [[ -n "$ONLY_BUILD" ]] && [[ "$PACKAGE_NAME" != "$ONLY_BUILD" ]] && [[ "$PACKAGE" != "$ONLY_BUILD" ]] ; then
936 local default_iteration_value="$(default_iteration "$PACKAGE" "$VERSION" "$PACKAGE_TYPE")"
938 declare -a COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
939 if [ python = "$PACKAGE_TYPE" ] && [ deb = "$FORMAT" ]; then
940 # Dependencies are built from setup.py. Since setup.py will never
941 # refer to Debian package iterations, it doesn't make sense to
942 # enforce those in the .deb dependencies.
943 COMMAND_ARR+=(--deb-ignore-iteration-in-dependencies)
946 if [[ "$DEBUG" != "0" ]]; then
947 COMMAND_ARR+=('--verbose' '--log' 'info')
950 if [[ -n "$PACKAGE_NAME" ]]; then
951 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
954 if [[ "$MAINTAINER" != "" ]]; then
955 COMMAND_ARR+=('--maintainer' "$MAINTAINER")
958 if [[ "$VENDOR" != "" ]]; then
959 COMMAND_ARR+=('--vendor' "$VENDOR")
962 if [[ "$VERSION" != "" ]]; then
963 COMMAND_ARR+=('-v' "$VERSION")
965 if [[ -n "$default_iteration_value" ]]; then
966 # We can always add an --iteration here. If another one is specified in $@,
967 # that will take precedence, as desired.
968 COMMAND_ARR+=(--iteration "$default_iteration_value")
971 # Append --depends X and other arguments specified by fpm-info.sh in
972 # the package source dir. These are added last so they can override
973 # the arguments added by this script.
974 declare -a fpm_args=()
975 declare -a build_depends=()
976 declare -a fpm_depends=()
977 declare -a fpm_conflicts=()
978 declare -a fpm_exclude=()
979 if [[ ! -d "$SRC_DIR" ]]; then
980 echo >&2 "BUG: looking in wrong dir for fpm-info.sh: $pkgdir"
983 fpminfo="${SRC_DIR}/fpm-info.sh"
984 if [[ -e "$fpminfo" ]]; then
985 debug_echo "Loading fpm overrides from $fpminfo"
988 for pkg in "${build_depends[@]}"; do
989 if [[ $TARGET =~ debian|ubuntu ]]; then
990 pkg_deb=$(ls "$WORKSPACE/packages/$TARGET/$pkg_"*.deb | sort -rg | awk 'NR==1')
991 if [[ -e $pkg_deb ]]; then
992 echo "Installing build_dep $pkg from $pkg_deb"
995 echo "Attemping to install build_dep $pkg using apt-get"
996 apt-get install -y "$pkg"
998 apt-get -y -f install
1000 pkg_rpm=$(ls "$WORKSPACE/packages/$TARGET/$pkg"-[0-9]*.rpm | sort -rg | awk 'NR==1')
1001 if [[ -e $pkg_rpm ]]; then
1002 echo "Installing build_dep $pkg from $pkg_rpm"
1005 echo "Attemping to install build_dep $pkg"
1010 for i in "${fpm_depends[@]}"; do
1011 COMMAND_ARR+=('--depends' "$i")
1013 for i in "${fpm_conflicts[@]}"; do
1014 COMMAND_ARR+=('--conflicts' "$i")
1016 for i in "${fpm_exclude[@]}"; do
1017 COMMAND_ARR+=('--exclude' "$i")
1020 COMMAND_ARR+=("${fpm_args[@]}")
1022 # Append remaining function arguments directly to fpm's command line.
1027 COMMAND_ARR+=("$PACKAGE")
1029 debug_echo -e "\n${COMMAND_ARR[@]}\n"
1031 FPM_RESULTS=$("${COMMAND_ARR[@]}")
1033 echo "fpm: exit code $FPM_EXIT_CODE" >>$STDOUT_IF_DEBUG
1034 echo "$FPM_RESULTS" >>$STDOUT_IF_DEBUG
1036 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
1038 # if something went wrong and debug is off, print out the fpm command that errored
1039 if [[ 0 -ne $? ]] && [[ "$STDOUT_IF_DEBUG" == "/dev/null" ]]; then
1040 echo -e "\n${COMMAND_ARR[@]}\n"
1044 # verify build results
1051 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.~-]*\.)(deb|rpm) ]]; then
1052 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
1055 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
1058 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
1063 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
1064 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
1066 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
1068 echo "Error building package for $1:\n $FPM_RESULTS"
1075 if [[ "$FORMAT" == "deb" ]]; then
1076 $SUDO apt-get install $PACKAGES --yes
1077 elif [[ "$FORMAT" == "rpm" ]]; then
1078 $SUDO yum -q -y install $PACKAGES
1083 printf '%s %s\n' "=======" "$1"
1087 if [[ "$1" != "0" ]]; then
1088 title "$2 -- FAILED"
1089 failures+=("$2 (`timer`)")
1091 successes+=("$2 (`timer`)")
1100 if [[ -n "$t0" ]]; then
1101 echo -n "$(($SECONDS - $t0))s"
1106 for x in "${successes[@]}"
1111 if [[ ${#failures[@]} == 0 ]]
1113 if [[ ${#successes[@]} != 0 ]]; then
1114 echo "All test suites passed."
1117 echo "Failures (${#failures[@]}):"
1118 for x in "${failures[@]}"