2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 . `dirname "$(readlink -f "$0")"`/run-library.sh
7 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh
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: debian8)
23 --only-build <package>
24 Build only a specific package (or $ONLY_BUILD from environment)
26 Build command to execute (defaults to the run command defined in the
29 WORKSPACE=path Path to the Arvados source tree to build packages from
34 DEBUG=${ARVADOS_DEBUG:-0}
38 PARSEDOPTS=$(getopt --name "$0" --longoptions \
39 help,build-bundle-packages,debug,target:,only-build: \
45 eval set -- "$PARSEDOPTS"
46 while [ $# -gt 0 ]; do
49 echo >&2 "$helpmessage"
57 ONLY_BUILD="$2"; shift
67 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
75 if [[ "$COMMAND" != "" ]]; then
76 COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
79 STDOUT_IF_DEBUG=/dev/null
80 STDERR_IF_DEBUG=/dev/null
82 if [[ "$DEBUG" != 0 ]]; then
83 STDOUT_IF_DEBUG=/dev/stdout
84 STDERR_IF_DEBUG=/dev/stderr
88 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
91 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
93 ## These defaults are suitable for any Debian-based distribution.
94 # You can customize them as needed in distro sections below.
95 PYTHON2_PACKAGE=python$PYTHON2_VERSION
96 PYTHON2_PKG_PREFIX=python
98 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
100 PYTHON3_PACKAGE=python$PYTHON3_VERSION
101 PYTHON3_PKG_PREFIX=python3
103 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
104 ## End Debian Python defaults.
115 PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
116 PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
117 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
118 PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
119 PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
120 PYTHON3_PREFIX=/opt/rh/rh-python35/root/usr
121 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
122 export PYCURL_SSL_LIBRARY=nss
125 echo -e "$0: Unknown target '$TARGET'.\n" >&2
131 if ! [[ -n "$WORKSPACE" ]]; then
132 echo >&2 "$helpmessage"
134 echo >&2 "Error: WORKSPACE environment variable not set"
140 fpm --version >/dev/null 2>&1
142 if [[ "$?" != 0 ]]; then
143 echo >&2 "$helpmessage"
145 echo >&2 "Error: fpm not found"
150 PYTHON2_FPM_INSTALLER=(--python-easyinstall "$(find_python_program easy_install-$PYTHON2_VERSION easy_install)")
151 install3=$(find_python_program easy_install-$PYTHON3_VERSION easy_install3 pip-$PYTHON3_VERSION pip3)
152 if [[ $install3 =~ easy_ ]]; then
153 PYTHON3_FPM_INSTALLER=(--python-easyinstall "$install3")
155 PYTHON3_FPM_INSTALLER=(--python-pip "$install3")
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 install/lib/=/usr/share libarvados-perl \
218 "Curoverse, Inc." 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"
241 cd "$WORKSPACE/sdk/pam"
242 handle_python_package
244 cd "$WORKSPACE/sdk/python"
245 handle_python_package
247 cd "$WORKSPACE/sdk/cwl"
248 handle_python_package
250 cd "$WORKSPACE/services/fuse"
251 handle_python_package
253 cd "$WORKSPACE/services/nodemanager"
254 handle_python_package
259 COMMIT_HASH=$(format_last_commit_here "%H")
260 arvados_src_version="$(version_from_git)"
262 cd $WORKSPACE/packages/$TARGET
263 test_package_presence arvados-src $arvados_src_version src ""
265 if [[ "$?" == "0" ]]; then
267 SRC_BUILD_DIR=$(mktemp -d)
268 # mktemp creates the directory with 0700 permissions by default
269 chmod 755 $SRC_BUILD_DIR
270 git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
273 # go into detached-head state
274 git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
275 echo "$COMMIT_HASH" >git-commit.version
278 PKG_VERSION=$(version_from_git)
279 cd $WORKSPACE/packages/$TARGET
280 fpm_build $SRC_BUILD_DIR/=/usr/local/arvados/src arvados-src 'Curoverse, Inc.' '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"
282 rm -rf "$SRC_BUILD_DIR"
288 cd $WORKSPACE/packages/$TARGET
289 export GOPATH=$(mktemp -d)
290 go get github.com/kardianos/govendor
291 package_go_binary cmd/arvados-client arvados-client \
292 "Arvados command line tool (beta)"
293 package_go_binary cmd/arvados-server arvados-server \
294 "Arvados server daemons"
295 package_go_binary cmd/arvados-server arvados-controller \
296 "Arvados cluster controller daemon"
297 package_go_binary sdk/go/crunchrunner crunchrunner \
298 "Crunchrunner executes a command inside a container and uploads the output"
299 package_go_binary services/arv-git-httpd arvados-git-httpd \
300 "Provide authenticated http access to Arvados-hosted git repositories"
301 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
302 "Dispatch Crunch containers on the local system"
303 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
304 "Dispatch Crunch containers to a SLURM cluster"
305 package_go_binary services/crunch-run crunch-run \
306 "Supervise a single Crunch container"
307 package_go_binary services/crunchstat crunchstat \
308 "Gather cpu/memory/network statistics of running Crunch jobs"
309 package_go_binary services/health arvados-health \
310 "Check health of all Arvados cluster services"
311 package_go_binary services/keep-balance keep-balance \
312 "Rebalance and garbage-collect data blocks stored in Arvados Keep"
313 package_go_binary services/keepproxy keepproxy \
314 "Make a Keep cluster accessible to clients that are not on the LAN"
315 package_go_binary services/keepstore keepstore \
316 "Keep storage daemon, accessible to clients on the LAN"
317 package_go_binary services/keep-web keep-web \
318 "Static web hosting service for user data stored in Arvados Keep"
319 package_go_binary services/ws arvados-ws \
320 "Arvados Websocket server"
321 package_go_binary tools/sync-groups arvados-sync-groups \
322 "Synchronize remote groups into Arvados from an external source"
323 package_go_binary tools/keep-block-check keep-block-check \
324 "Verify that all data from one set of Keep servers to another was copied"
325 package_go_binary tools/keep-rsync keep-rsync \
326 "Copy all data from one set of Keep servers to another"
327 package_go_binary tools/keep-exercise keep-exercise \
328 "Performance testing tool for Arvados Keep"
331 fpm_build_virtualenv "arvados-python-client" "sdk/python"
332 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
335 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl"
338 if [[ $TARGET =~ debian|ubuntu ]]; then
339 cd $WORKSPACE/packages/$TARGET
340 rm -rf "$WORKSPACE/sdk/pam/build"
341 libpam_arvados_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)
342 test_package_presence libpam-arvados "$libpam_arvados_version" python
343 if [[ "$?" == "0" ]]; then
344 fpm_build $WORKSPACE/sdk/pam libpam-arvados 'Curoverse, Inc.' 'python' "$libpam_arvados_version" "--url=https://arvados.org" "--description=PAM module for authenticating shell logins using Arvados API tokens" --depends libpam-python
349 fpm_build_virtualenv "arvados-fuse" "services/fuse"
352 fpm_build_virtualenv "arvados-node-manager" "services/nodemanager"
354 # The Docker image cleaner
355 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
357 # The Arvados crunchstat-summary tool
358 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary"
361 if test_package_presence "$PYTHON2_PKG_PREFIX"-apache-libcloud "$LIBCLOUD_PIN" python 2
363 LIBCLOUD_DIR=$(mktemp -d)
366 git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
367 git checkout $DASHQ_UNLESS_DEBUG apache-libcloud-$LIBCLOUD_PIN
368 # libcloud is absurdly noisy without -q, so force -q here
369 OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
370 DASHQ_UNLESS_DEBUG=-q
371 handle_python_package
372 DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
375 # libcloud >= 2.3.0 now requires python-requests 2.4.3 or higher, otherwise
377 # ImportError: No module named packages.urllib3.poolmanager
378 # when loaded. We only see this problem on ubuntu1404, because that is our
379 # only supported distribution that ships with a python-requests older than
381 fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud "" python "" --iteration 2 --depends 'python-requests >= 2.4.3'
385 # Build the API server package
386 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
387 if [[ "$?" == "0" ]]; then
388 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
389 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
390 --description="Arvados API server - Arvados is a free and open source platform for big data science." \
391 --license="GNU Affero General Public License, version 3.0"
394 # Build the workbench server package
395 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
396 if [[ "$?" == "0" ]] ; then
399 cd "$WORKSPACE/apps/workbench"
401 # We need to bundle to be ready even when we build a package without vendor directory
402 # because asset compilation requires it.
403 bundle install --system >"$STDOUT_IF_DEBUG"
405 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
406 # and we want that in the package, so it's easier to not exclude the tmp directory
407 # from the package - empty it instead.
411 # Set up application.yml and production.rb so that asset precompilation works
412 \cp config/application.yml.example config/application.yml -f
413 \cp config/environments/production.rb.example config/environments/production.rb -f
414 sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
415 sed -i 's/keep_web_url: false/keep_web_url: exampledotcom/' config/application.yml
417 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >/dev/null
418 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
420 # Remove generated configuration files so they don't go in the package.
421 rm config/application.yml config/environments/production.rb
424 if [[ "$?" != "0" ]]; then
425 echo "ERROR: Asset precompilation failed"
428 handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
429 "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
430 --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
431 --license="GNU Affero General Public License, version 3.0"
435 # clean up temporary GOPATH