+# Usage: handle_api_server [amd64|arm64]
+handle_api_server () {
+ local target_arch="${1:-amd64}"; shift
+
+ if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "arvados-api-server" ]] ; then
+ debug_echo -e "Skipping build of arvados-api-server package."
+ return 0
+ fi
+
+ native_arch=$(get_native_arch)
+ if [[ "$target_arch" != "$native_arch" ]]; then
+ echo "Error: no cross compilation support for Rails yet, can not build arvados-api-server for $ARCH"
+ echo
+ exit 1
+ fi
+
+ # Build the API server package
+ test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
+ if [[ "$?" == "0" ]]; then
+ calculate_go_package_version arvados_server_version cmd/arvados-server
+ arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
+ handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
+ "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
+ --description="Arvados API server - Arvados is a free and open source platform for big data science." \
+ --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
+ fi
+}
+
+# Usage: handle_workbench [amd64|arm64]
+handle_workbench () {
+ local target_arch="${1:-amd64}"; shift
+ if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "arvados-workbench" ]] ; then
+ debug_echo -e "Skipping build of arvados-workbench package."
+ return 0
+ fi
+
+ native_arch=$(get_native_arch)
+ if [[ "$target_arch" != "$native_arch" ]]; then
+ echo "Error: no cross compilation support for Rails yet, can not build arvados-workbench for $native_arch"
+ echo
+ exit 1
+ fi
+
+ if [[ "$native_arch" != "amd64" ]]; then
+ echo "Error: building the arvados-workbench package is not yet supported on this architecture ($native_arch)."
+ echo
+ exit 1
+ fi
+
+ # Build the workbench server package
+ test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
+ if [[ "$?" == "0" ]] ; then
+ calculate_go_package_version arvados_server_version cmd/arvados-server
+ arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
+
+ (
+ set -e
+
+ # The workbench package has a build-time dependency on the arvados-server
+ # package for config manipulation, so install it first.
+ cd $WORKSPACE/cmd/arvados-server
+ get_complete_package_name arvados_server_pkgname arvados-server ${arvados_server_version} go
+
+ arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/${arvados_server_pkgname}"
+ if [[ ! -e ${arvados_server_pkg_path} ]]; then
+ arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/processed/${arvados_server_pkgname}"
+ fi
+ if [[ "$FORMAT" == "deb" ]]; then
+ dpkg -i ${arvados_server_pkg_path}
+ else
+ rpm -i ${arvados_server_pkg_path}
+ fi
+
+ cd "$WORKSPACE/apps/workbench"
+
+ # We need to bundle to be ready even when we build a package without vendor directory
+ # because asset compilation requires it.
+ bundle config set --local system 'true' >"$STDOUT_IF_DEBUG"
+ bundle install >"$STDOUT_IF_DEBUG"
+
+ # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
+ # and we want that in the package, so it's easier to not exclude the tmp directory
+ # from the package - empty it instead.
+ rm -rf tmp
+ mkdir tmp
+
+ # Set up an appropriate config.yml
+ arvados-server config-dump -config <(cat /etc/arvados/config.yml 2>/dev/null || echo "Clusters: {zzzzz: {}}") > /tmp/x
+ mkdir -p /etc/arvados/
+ mv /tmp/x /etc/arvados/config.yml
+ perl -p -i -e 'BEGIN{undef $/;} s/WebDAV(.*?):\n( *)ExternalURL: ""/WebDAV$1:\n$2ExternalURL: "example.com"/g' /etc/arvados/config.yml
+
+ ARVADOS_CONFIG=none RAILS_ENV=production RAILS_GROUPS=assets bin/rake npm:install >"$STDOUT_IF_DEBUG"
+ ARVADOS_CONFIG=none RAILS_ENV=production RAILS_GROUPS=assets bin/rake assets:precompile >"$STDOUT_IF_DEBUG"
+
+ # Remove generated configuration files so they don't go in the package.
+ rm -rf /etc/arvados/
+ )
+
+ if [[ "$?" != "0" ]]; then
+ echo "ERROR: Asset precompilation failed"
+ EXITCODE=1
+ else
+ handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
+ "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
+ --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
+ --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
+ fi
+ fi
+}
+
+# Usage: handle_cwltest [deb|rpm] [amd64|arm64]
+handle_cwltest () {
+ local package_format="$1"; shift
+ local target_arch="${1:-amd64}"; shift
+
+ if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "python3-cwltest" ]] ; then
+ debug_echo -e "Skipping build of cwltest package."
+ return 0
+ fi
+ cd "$WORKSPACE"
+ if [[ -e "$WORKSPACE/cwltest" ]]; then
+ rm -rf "$WORKSPACE/cwltest"
+ fi
+ git clone https://github.com/common-workflow-language/cwltest.git
+ # signal to our build script that we want a cwltest executable installed in /usr/bin/
+ mkdir cwltest/bin && touch cwltest/bin/cwltest
+ fpm_build_virtualenv "cwltest" "cwltest" "$package_format" "$target_arch"
+ # The python->python3 metapackage
+ build_metapackage "cwltest" "cwltest"
+ cd "$WORKSPACE"
+ rm -rf "$WORKSPACE/cwltest"
+}
+
+# Usage: handle_arvados_src
+handle_arvados_src () {
+ if [[ -n "$ONLY_BUILD" ]] && [[ "$ONLY_BUILD" != "arvados-src" ]] ; then
+ debug_echo -e "Skipping build of arvados-src package."
+ return 0
+ fi
+ # arvados-src
+ (
+ cd "$WORKSPACE"
+ COMMIT_HASH=$(format_last_commit_here "%H")
+ arvados_src_version="$(version_from_git)"
+
+ cd $WORKSPACE/packages/$TARGET
+ test_package_presence arvados-src "$arvados_src_version" src ""
+
+ if [[ "$?" == "0" ]]; then
+ cd "$WORKSPACE"
+ SRC_BUILD_DIR=$(mktemp -d)
+ # mktemp creates the directory with 0700 permissions by default
+ chmod 755 $SRC_BUILD_DIR
+ git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
+ cd "$SRC_BUILD_DIR"
+
+ # go into detached-head state
+ git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
+ echo "$COMMIT_HASH" >git-commit.version
+
+ cd $WORKSPACE/packages/$TARGET
+ 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"
+
+ rm -rf "$SRC_BUILD_DIR"
+ fi
+ )
+}
+