2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 . `dirname "$(readlink -f "$0")"`/run-library.sh || exit 1
7 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh || exit 1
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Build Arvados packages
13 WORKSPACE=/path/to/arvados $(basename $0) [options]
17 --build-bundle-packages (default: false)
18 Build api server and workbench packages with vendor/bundle included
20 Output debug information (default: false)
22 Distribution to build packages for (default: debian10)
23 --only-build <package>
24 Build only a specific package (or $ONLY_BUILD from environment)
26 Build even if the package exists upstream or if it has already been
29 Build command to execute (defaults to the run command defined in the
32 WORKSPACE=path Path to the Arvados source tree to build packages from
36 # Begin of user configuration
38 # set to --no-cache-dir to disable pip caching
41 MAINTAINER="Arvados Package Maintainers <packaging@arvados.org>"
42 VENDOR="The Arvados Project"
44 # End of user configuration
46 DEBUG=${ARVADOS_DEBUG:-0}
47 FORCE_BUILD=${FORCE_BUILD:-0}
52 PARSEDOPTS=$(getopt --name "$0" --longoptions \
53 help,build-bundle-packages,debug,target:,only-build:,force-build \
59 eval set -- "$PARSEDOPTS"
60 while [ $# -gt 0 ]; do
63 echo >&2 "$helpmessage"
71 ONLY_BUILD="$2"; shift
84 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
92 if [[ "$COMMAND" != "" ]]; then
93 COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
96 STDOUT_IF_DEBUG=/dev/null
97 STDERR_IF_DEBUG=/dev/null
99 if [[ "$DEBUG" != 0 ]]; then
100 STDOUT_IF_DEBUG=/dev/stdout
101 STDERR_IF_DEBUG=/dev/stderr
105 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
108 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
110 ## These defaults are suitable for any Debian-based distribution.
111 # You can customize them as needed in distro sections below.
112 PYTHON2_PACKAGE=python$PYTHON2_VERSION
113 PYTHON2_PKG_PREFIX=python
115 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
117 PYTHON3_PACKAGE=python$PYTHON3_VERSION
118 PYTHON3_PKG_PREFIX=python3
120 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
121 ## End Debian Python defaults.
132 PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
133 PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
134 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
135 PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
136 PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
137 PYTHON3_PREFIX=/opt/rh/rh-python36/root/usr
138 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
139 export PYCURL_SSL_LIBRARY=nss
142 echo -e "$0: Unknown target '$TARGET'.\n" >&2
148 if ! [[ -n "$WORKSPACE" ]]; then
149 echo >&2 "$helpmessage"
151 echo >&2 "Error: WORKSPACE environment variable not set"
157 fpm --version >/dev/null 2>&1
159 if [[ "$?" != 0 ]]; then
160 echo >&2 "$helpmessage"
162 echo >&2 "Error: fpm not found"
167 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
168 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`" # absolutized and normalized
169 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
170 # error; for some reason, the path is not accessible
171 # to the script (e.g. permissions re-evaled after suid)
175 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
176 debug_echo "Workspace is $WORKSPACE"
178 if [[ -f /etc/profile.d/rvm.sh ]]; then
179 source /etc/profile.d/rvm.sh
180 GEM="rvm-exec default gem"
185 # Make all files world-readable -- jenkins runs with umask 027, and has checked
186 # out our git tree here
187 chmod o+r "$WORKSPACE" -R
189 # More cleanup - make sure all executables that we'll package are 755
191 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
193 # Now fix our umask to something better suited to building and publishing
197 debug_echo "umask is" `umask`
199 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
200 mkdir -p $WORKSPACE/packages/$TARGET
201 chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
205 debug_echo -e "\nPerl packages\n"
207 if [[ -z "$ONLY_BUILD" ]] || [[ "libarvados-perl" = "$ONLY_BUILD" ]] ; then
208 cd "$WORKSPACE/sdk/perl"
209 libarvados_perl_version="$(version_from_git)"
211 cd $WORKSPACE/packages/$TARGET
212 test_package_presence libarvados-perl "$libarvados_perl_version"
214 if [[ "$?" == "0" ]]; then
215 cd "$WORKSPACE/sdk/perl"
217 if [[ -e Makefile ]]; then
218 make realclean >"$STDOUT_IF_DEBUG"
220 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
224 perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
225 make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
226 fpm_build "$WORKSPACE/sdk/perl" install/lib/=/usr/share libarvados-perl \
227 dir "$(version_from_git)" install/man/=/usr/share/man \
228 "$WORKSPACE/apache-2.0.txt=/usr/share/doc/libarvados-perl/apache-2.0.txt" && \
229 mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
234 debug_echo -e "\nRuby gems\n"
236 FPM_GEM_PREFIX=$($GEM environment gemdir)
238 cd "$WORKSPACE/sdk/ruby"
239 handle_ruby_gem arvados
241 cd "$WORKSPACE/sdk/cli"
242 handle_ruby_gem arvados-cli
244 cd "$WORKSPACE/services/login-sync"
245 handle_ruby_gem arvados-login-sync
248 debug_echo -e "\nPython packages\n"
253 COMMIT_HASH=$(format_last_commit_here "%H")
254 arvados_src_version="$(version_from_git)"
256 cd $WORKSPACE/packages/$TARGET
257 test_package_presence arvados-src $arvados_src_version src ""
259 if [[ "$?" == "0" ]]; then
261 SRC_BUILD_DIR=$(mktemp -d)
262 # mktemp creates the directory with 0700 permissions by default
263 chmod 755 $SRC_BUILD_DIR
264 git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
267 # go into detached-head state
268 git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
269 echo "$COMMIT_HASH" >git-commit.version
272 PKG_VERSION=$(version_from_git)
273 cd $WORKSPACE/packages/$TARGET
274 fpm_build "$WORKSPACE" $SRC_BUILD_DIR/=/usr/local/arvados/src arvados-src 'dir' "$PKG_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"
276 rm -rf "$SRC_BUILD_DIR"
281 cd $WORKSPACE/packages/$TARGET
282 export GOPATH=$(mktemp -d)
283 package_go_binary cmd/arvados-client arvados-client \
284 "Arvados command line tool (beta)"
285 package_go_binary cmd/arvados-server arvados-server \
286 "Arvados server daemons"
287 package_go_binary cmd/arvados-server arvados-controller \
288 "Arvados cluster controller daemon"
289 package_go_binary cmd/arvados-server arvados-dispatch-cloud \
290 "Arvados cluster cloud dispatch"
291 package_go_binary services/arv-git-httpd arvados-git-httpd \
292 "Provide authenticated http access to Arvados-hosted git repositories"
293 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
294 "Dispatch Crunch containers on the local system"
295 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
296 "Dispatch Crunch containers to a SLURM cluster"
297 package_go_binary cmd/arvados-server crunch-run \
298 "Supervise a single Crunch container"
299 package_go_binary services/crunchstat crunchstat \
300 "Gather cpu/memory/network statistics of running Crunch jobs"
301 package_go_binary services/health arvados-health \
302 "Check health of all Arvados cluster services"
303 package_go_binary services/keep-balance keep-balance \
304 "Rebalance and garbage-collect data blocks stored in Arvados Keep"
305 package_go_binary services/keepproxy keepproxy \
306 "Make a Keep cluster accessible to clients that are not on the LAN"
307 package_go_binary services/keepstore keepstore \
308 "Keep storage daemon, accessible to clients on the LAN"
309 package_go_binary services/keep-web keep-web \
310 "Static web hosting service for user data stored in Arvados Keep"
311 package_go_binary cmd/arvados-server arvados-ws \
312 "Arvados Websocket server"
313 package_go_binary tools/sync-groups arvados-sync-groups \
314 "Synchronize remote groups into Arvados from an external source"
315 package_go_binary tools/keep-block-check keep-block-check \
316 "Verify that all data from one set of Keep servers to another was copied"
317 package_go_binary tools/keep-rsync keep-rsync \
318 "Copy all data from one set of Keep servers to another"
319 package_go_binary tools/keep-exercise keep-exercise \
320 "Performance testing tool for Arvados Keep"
321 package_go_so lib/pam pam_arvados.so libpam-arvados-go \
322 "Arvados PAM authentication module"
324 # The Python SDK - Should be built first because it's needed by others
325 fpm_build_virtualenv "arvados-python-client" "sdk/python"
327 # The Python SDK - Python3 package
328 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
330 # Arvados cwl runner - Only supports Python3 now
331 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl" "python3"
334 fpm_build_virtualenv "libpam-arvados" "sdk/pam"
337 fpm_build_virtualenv "arvados-fuse" "services/fuse"
339 # The FUSE driver - Python3 package
340 fpm_build_virtualenv "arvados-fuse" "services/fuse" "python3"
343 fpm_build_virtualenv "arvados-node-manager" "services/nodemanager"
345 # The Arvados crunchstat-summary tool
346 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary"
348 # The Docker image cleaner
349 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
351 # The cwltest package, which lives out of tree
353 if [[ -e "$WORKSPACE/cwltest" ]]; then
354 rm -rf "$WORKSPACE/cwltest"
356 git clone https://github.com/common-workflow-language/cwltest.git
357 # last release to support python 2.7
358 (cd cwltest && git checkout 1.0.20190906212748)
359 # signal to our build script that we want a cwltest executable installed in /usr/bin/
360 mkdir cwltest/bin && touch cwltest/bin/cwltest
361 fpm_build_virtualenv "cwltest" "cwltest"
362 rm -rf "$WORKSPACE/cwltest"
364 calculate_go_package_version arvados_server_version cmd/arvados-server
365 arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
367 # Build the API server package
368 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
369 if [[ "$?" == "0" ]]; then
370 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
371 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
372 --description="Arvados API server - Arvados is a free and open source platform for big data science." \
373 --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
376 # Build the workbench server package
377 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
378 if [[ "$?" == "0" ]] ; then
382 # The workbench package has a build-time dependency on the arvados-server
383 # package for config manipulation, so install it first.
384 cd $WORKSPACE/cmd/arvados-server
385 get_complete_package_name arvados_server_pkgname arvados-server ${arvados_server_version} go
387 arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/${arvados_server_pkgname}"
388 if [[ ! -e ${arvados_server_pkg_path} ]]; then
389 arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/processed/${arvados_server_pkgname}"
391 if [[ "$FORMAT" == "deb" ]]; then
392 dpkg -i ${arvados_server_pkg_path}
394 rpm -i ${arvados_server_pkg_path}
397 cd "$WORKSPACE/apps/workbench"
399 # We need to bundle to be ready even when we build a package without vendor directory
400 # because asset compilation requires it.
401 bundle install --system >"$STDOUT_IF_DEBUG"
403 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
404 # and we want that in the package, so it's easier to not exclude the tmp directory
405 # from the package - empty it instead.
409 # Set up an appropriate config.yml
410 arvados-server config-dump -config <(cat /etc/arvados/config.yml 2>/dev/null || echo "Clusters: {zzzzz: {}}") > /tmp/x
411 mkdir -p /etc/arvados/
412 mv /tmp/x /etc/arvados/config.yml
413 perl -p -i -e 'BEGIN{undef $/;} s/WebDAV(.*?):\n( *)ExternalURL: ""/WebDAV$1:\n$2ExternalURL: "example.com"/g' /etc/arvados/config.yml
415 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >"$STDOUT_IF_DEBUG"
416 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >"$STDOUT_IF_DEBUG"
418 # Remove generated configuration files so they don't go in the package.
422 if [[ "$?" != "0" ]]; then
423 echo "ERROR: Asset precompilation failed"
426 handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
427 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
428 --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
429 --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
433 # clean up temporary GOPATH