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 PYTHON3_BACKPORTS
107 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
109 ## These defaults are suitable for any Debian-based distribution.
110 # You can customize them as needed in distro sections below.
111 PYTHON3_PACKAGE=python$PYTHON3_VERSION
112 PYTHON3_PKG_PREFIX=python3
114 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
115 ## End Debian Python defaults.
126 PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
127 PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
128 PYTHON3_PREFIX=/opt/rh/rh-python36/root/usr
129 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
130 export PYCURL_SSL_LIBRARY=nss
133 echo -e "$0: Unknown target '$TARGET'.\n" >&2
139 if ! [[ -n "$WORKSPACE" ]]; then
140 echo >&2 "$helpmessage"
142 echo >&2 "Error: WORKSPACE environment variable not set"
148 fpm --version >/dev/null 2>&1
150 if [[ "$?" != 0 ]]; then
151 echo >&2 "$helpmessage"
153 echo >&2 "Error: fpm not found"
158 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
159 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`" # absolutized and normalized
160 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
161 # error; for some reason, the path is not accessible
162 # to the script (e.g. permissions re-evaled after suid)
166 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
167 debug_echo "Workspace is $WORKSPACE"
169 if [[ -f /etc/profile.d/rvm.sh ]]; then
170 source /etc/profile.d/rvm.sh
171 GEM="rvm-exec default gem"
176 # Make all files world-readable -- jenkins runs with umask 027, and has checked
177 # out our git tree here
178 chmod o+r "$WORKSPACE" -R
180 # More cleanup - make sure all executables that we'll package are 755
182 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
184 # Now fix our umask to something better suited to building and publishing
188 debug_echo "umask is" `umask`
190 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
191 mkdir -p $WORKSPACE/packages/$TARGET
192 chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
196 debug_echo -e "\nPerl packages\n"
198 if [[ -z "$ONLY_BUILD" ]] || [[ "libarvados-perl" = "$ONLY_BUILD" ]] ; then
199 cd "$WORKSPACE/sdk/perl"
200 libarvados_perl_version="$(version_from_git)"
202 cd $WORKSPACE/packages/$TARGET
203 test_package_presence libarvados-perl "$libarvados_perl_version"
205 if [[ "$?" == "0" ]]; then
206 cd "$WORKSPACE/sdk/perl"
208 if [[ -e Makefile ]]; then
209 make realclean >"$STDOUT_IF_DEBUG"
211 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
215 perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
216 make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
217 fpm_build "$WORKSPACE/sdk/perl" install/lib/=/usr/share libarvados-perl \
218 dir "$(version_from_git)" install/man/=/usr/share/man \
219 "$WORKSPACE/apache-2.0.txt=/usr/share/doc/libarvados-perl/apache-2.0.txt" && \
220 mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
225 debug_echo -e "\nRuby gems\n"
227 FPM_GEM_PREFIX=$($GEM environment gemdir)
229 cd "$WORKSPACE/sdk/ruby"
230 handle_ruby_gem arvados
232 cd "$WORKSPACE/sdk/cli"
233 handle_ruby_gem arvados-cli
235 cd "$WORKSPACE/services/login-sync"
236 handle_ruby_gem arvados-login-sync
239 debug_echo -e "\nPython packages\n"
244 COMMIT_HASH=$(format_last_commit_here "%H")
245 arvados_src_version="$(version_from_git)"
247 cd $WORKSPACE/packages/$TARGET
248 test_package_presence arvados-src $arvados_src_version src ""
250 if [[ "$?" == "0" ]]; then
252 SRC_BUILD_DIR=$(mktemp -d)
253 # mktemp creates the directory with 0700 permissions by default
254 chmod 755 $SRC_BUILD_DIR
255 git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
258 # go into detached-head state
259 git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
260 echo "$COMMIT_HASH" >git-commit.version
263 PKG_VERSION=$(version_from_git)
264 cd $WORKSPACE/packages/$TARGET
265 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"
267 rm -rf "$SRC_BUILD_DIR"
272 cd $WORKSPACE/packages/$TARGET
273 export GOPATH=$(mktemp -d)
274 package_go_binary cmd/arvados-client arvados-client \
275 "Arvados command line tool (beta)"
276 package_go_binary cmd/arvados-server arvados-server \
277 "Arvados server daemons"
278 package_go_binary cmd/arvados-server arvados-controller \
279 "Arvados cluster controller daemon"
280 package_go_binary cmd/arvados-server arvados-dispatch-cloud \
281 "Arvados cluster cloud dispatch"
282 package_go_binary services/arv-git-httpd arvados-git-httpd \
283 "Provide authenticated http access to Arvados-hosted git repositories"
284 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
285 "Dispatch Crunch containers on the local system"
286 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
287 "Dispatch Crunch containers to a SLURM cluster"
288 package_go_binary cmd/arvados-server crunch-run \
289 "Supervise a single Crunch container"
290 package_go_binary services/crunchstat crunchstat \
291 "Gather cpu/memory/network statistics of running Crunch jobs"
292 package_go_binary services/health arvados-health \
293 "Check health of all Arvados cluster services"
294 package_go_binary services/keep-balance keep-balance \
295 "Rebalance and garbage-collect data blocks stored in Arvados Keep"
296 package_go_binary services/keepproxy keepproxy \
297 "Make a Keep cluster accessible to clients that are not on the LAN"
298 package_go_binary services/keepstore keepstore \
299 "Keep storage daemon, accessible to clients on the LAN"
300 package_go_binary services/keep-web keep-web \
301 "Static web hosting service for user data stored in Arvados Keep"
302 package_go_binary cmd/arvados-server arvados-ws \
303 "Arvados Websocket server"
304 package_go_binary tools/sync-groups arvados-sync-groups \
305 "Synchronize remote groups into Arvados from an external source"
306 package_go_binary tools/keep-block-check keep-block-check \
307 "Verify that all data from one set of Keep servers to another was copied"
308 package_go_binary tools/keep-rsync keep-rsync \
309 "Copy all data from one set of Keep servers to another"
310 package_go_binary tools/keep-exercise keep-exercise \
311 "Performance testing tool for Arvados Keep"
312 package_go_so lib/pam pam_arvados.so libpam-arvados-go \
313 "Arvados PAM authentication module"
315 # The Python SDK - Python3 package
316 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
318 # Arvados cwl runner - Python3 package
319 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl" "python3"
321 # The FUSE driver - Python3 package
322 fpm_build_virtualenv "arvados-fuse" "services/fuse" "python3"
324 # The Arvados crunchstat-summary tool
325 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary" "python3"
327 # The Docker image cleaner
328 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
330 # The cwltest package, which lives out of tree
332 if [[ -e "$WORKSPACE/cwltest" ]]; then
333 rm -rf "$WORKSPACE/cwltest"
335 git clone https://github.com/common-workflow-language/cwltest.git
336 # signal to our build script that we want a cwltest executable installed in /usr/bin/
337 mkdir cwltest/bin && touch cwltest/bin/cwltest
338 fpm_build_virtualenv "cwltest" "cwltest" "python3"
339 rm -rf "$WORKSPACE/cwltest"
341 calculate_go_package_version arvados_server_version cmd/arvados-server
342 arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
344 # Build the API server package
345 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
346 if [[ "$?" == "0" ]]; then
347 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
348 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
349 --description="Arvados API server - Arvados is a free and open source platform for big data science." \
350 --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
353 # Build the workbench server package
354 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
355 if [[ "$?" == "0" ]] ; then
359 # The workbench package has a build-time dependency on the arvados-server
360 # package for config manipulation, so install it first.
361 cd $WORKSPACE/cmd/arvados-server
362 get_complete_package_name arvados_server_pkgname arvados-server ${arvados_server_version} go
364 arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/${arvados_server_pkgname}"
365 if [[ ! -e ${arvados_server_pkg_path} ]]; then
366 arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/processed/${arvados_server_pkgname}"
368 if [[ "$FORMAT" == "deb" ]]; then
369 dpkg -i ${arvados_server_pkg_path}
371 rpm -i ${arvados_server_pkg_path}
374 cd "$WORKSPACE/apps/workbench"
376 # We need to bundle to be ready even when we build a package without vendor directory
377 # because asset compilation requires it.
378 bundle install --system >"$STDOUT_IF_DEBUG"
380 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
381 # and we want that in the package, so it's easier to not exclude the tmp directory
382 # from the package - empty it instead.
386 # Set up an appropriate config.yml
387 arvados-server config-dump -config <(cat /etc/arvados/config.yml 2>/dev/null || echo "Clusters: {zzzzz: {}}") > /tmp/x
388 mkdir -p /etc/arvados/
389 mv /tmp/x /etc/arvados/config.yml
390 perl -p -i -e 'BEGIN{undef $/;} s/WebDAV(.*?):\n( *)ExternalURL: ""/WebDAV$1:\n$2ExternalURL: "example.com"/g' /etc/arvados/config.yml
392 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >"$STDOUT_IF_DEBUG"
393 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >"$STDOUT_IF_DEBUG"
395 # Remove generated configuration files so they don't go in the package.
399 if [[ "$?" != "0" ]]; then
400 echo "ERROR: Asset precompilation failed"
403 handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
404 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
405 --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
406 --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
410 # clean up temporary GOPATH