8784: Fix test for latest firefox.
[arvados.git] / build / run-build-packages.sh
1 #!/bin/bash
2
3 . `dirname "$(readlink -f "$0")"`/run-library.sh
4 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh
5
6 read -rd "\000" helpmessage <<EOF
7 $(basename $0): Build Arvados packages
8
9 Syntax:
10         WORKSPACE=/path/to/arvados $(basename $0) [options]
11
12 Options:
13
14 --build-bundle-packages  (default: false)
15     Build api server and workbench packages with vendor/bundle included
16 --debug
17     Output debug information (default: false)
18 --target <target>
19     Distribution to build packages for (default: debian8)
20 --only-build <package>
21     Build only a specific package (or $ONLY_BUILD from environment)
22 --command
23     Build command to execute (defaults to the run command defined in the
24     Docker image)
25
26 WORKSPACE=path         Path to the Arvados source tree to build packages from
27
28 EOF
29
30 EXITCODE=0
31 DEBUG=${ARVADOS_DEBUG:-0}
32 TARGET=debian8
33 COMMAND=
34
35 PARSEDOPTS=$(getopt --name "$0" --longoptions \
36     help,build-bundle-packages,debug,target:,only-build: \
37     -- "" "$@")
38 if [ $? -ne 0 ]; then
39     exit 1
40 fi
41
42 eval set -- "$PARSEDOPTS"
43 while [ $# -gt 0 ]; do
44     case "$1" in
45         --help)
46             echo >&2 "$helpmessage"
47             echo >&2
48             exit 1
49             ;;
50         --target)
51             TARGET="$2"; shift
52             ;;
53         --only-build)
54             ONLY_BUILD="$2"; shift
55             ;;
56         --debug)
57             DEBUG=1
58             ;;
59         --command)
60             COMMAND="$2"; shift
61             ;;
62         --)
63             if [ $# -gt 1 ]; then
64                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
65                 exit 1
66             fi
67             ;;
68     esac
69     shift
70 done
71
72 if [[ "$COMMAND" != "" ]]; then
73   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
74 fi
75
76 STDOUT_IF_DEBUG=/dev/null
77 STDERR_IF_DEBUG=/dev/null
78 DASHQ_UNLESS_DEBUG=-q
79 if [[ "$DEBUG" != 0 ]]; then
80     STDOUT_IF_DEBUG=/dev/stdout
81     STDERR_IF_DEBUG=/dev/stderr
82     DASHQ_UNLESS_DEBUG=
83 fi
84
85 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
86
87 PYTHON2_VERSION=2.7
88 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
89
90 ## These defaults are suitable for any Debian-based distribution.
91 # You can customize them as needed in distro sections below.
92 PYTHON2_PACKAGE=python$PYTHON2_VERSION
93 PYTHON2_PKG_PREFIX=python
94 PYTHON2_PREFIX=/usr
95 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
96
97 PYTHON3_PACKAGE=python$PYTHON3_VERSION
98 PYTHON3_PKG_PREFIX=python3
99 PYTHON3_PREFIX=/usr
100 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
101 ## End Debian Python defaults.
102
103 case "$TARGET" in
104     debian8)
105         FORMAT=deb
106         ;;
107     ubuntu1204)
108         FORMAT=deb
109         ;;
110     ubuntu1404)
111         FORMAT=deb
112         ;;
113     ubuntu1604)
114         FORMAT=deb
115         ;;
116     centos7)
117         FORMAT=rpm
118         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
119         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
120         PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
121         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
122         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
123         PYTHON3_PREFIX=/opt/rh/python33/root/usr
124         PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
125         export PYCURL_SSL_LIBRARY=nss
126         ;;
127     *)
128         echo -e "$0: Unknown target '$TARGET'.\n" >&2
129         exit 1
130         ;;
131 esac
132
133
134 if ! [[ -n "$WORKSPACE" ]]; then
135   echo >&2 "$helpmessage"
136   echo >&2
137   echo >&2 "Error: WORKSPACE environment variable not set"
138   echo >&2
139   exit 1
140 fi
141
142 # Test for fpm
143 fpm --version >/dev/null 2>&1
144
145 if [[ "$?" != 0 ]]; then
146   echo >&2 "$helpmessage"
147   echo >&2
148   echo >&2 "Error: fpm not found"
149   echo >&2
150   exit 1
151 fi
152
153 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
154 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
155
156 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
157 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
158 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
159   # error; for some reason, the path is not accessible
160   # to the script (e.g. permissions re-evaled after suid)
161   exit 1  # fail
162 fi
163
164 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
165 debug_echo "Workspace is $WORKSPACE"
166
167 if [[ -f /etc/profile.d/rvm.sh ]]; then
168     source /etc/profile.d/rvm.sh
169     GEM="rvm-exec default gem"
170 else
171     GEM=gem
172 fi
173
174 # Make all files world-readable -- jenkins runs with umask 027, and has checked
175 # out our git tree here
176 chmod o+r "$WORKSPACE" -R
177
178 # More cleanup - make sure all executables that we'll package are 755
179 cd "$WORKSPACE"
180 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
181
182 # Now fix our umask to something better suited to building and publishing
183 # gems and packages
184 umask 0022
185
186 debug_echo "umask is" `umask`
187
188 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
189   mkdir -p $WORKSPACE/packages/$TARGET
190   chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
191 fi
192
193 # Perl packages
194 debug_echo -e "\nPerl packages\n"
195
196 if [[ -z "$ONLY_BUILD" ]] || [[ "libarvados-perl" = "$ONLY_BUILD" ]] ; then
197   cd "$WORKSPACE/sdk/perl"
198   libarvados_perl_version="$(version_from_git)"
199
200   cd $WORKSPACE/packages/$TARGET
201   test_package_presence libarvados-perl "$libarvados_perl_version"
202
203   if [[ "$?" == "0" ]]; then
204     cd "$WORKSPACE/sdk/perl"
205
206     if [[ -e Makefile ]]; then
207       make realclean >"$STDOUT_IF_DEBUG"
208     fi
209     find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
210         -delete
211     rm -rf install
212
213     perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
214         make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
215         fpm_build install/lib/=/usr/share libarvados-perl \
216         "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man \
217         "$WORKSPACE/LICENSE-2.0.txt=/usr/share/doc/libarvados-perl/LICENSE-2.0.txt" && \
218         mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
219   fi
220 fi
221
222 # Ruby gems
223 debug_echo -e "\nRuby gems\n"
224
225 FPM_GEM_PREFIX=$($GEM environment gemdir)
226
227 cd "$WORKSPACE/sdk/ruby"
228 handle_ruby_gem arvados
229
230 cd "$WORKSPACE/sdk/cli"
231 handle_ruby_gem arvados-cli
232
233 cd "$WORKSPACE/services/login-sync"
234 handle_ruby_gem arvados-login-sync
235
236 # Python packages
237 debug_echo -e "\nPython packages\n"
238
239 cd "$WORKSPACE/sdk/pam"
240 handle_python_package
241
242 cd "$WORKSPACE/sdk/python"
243 handle_python_package
244
245 cd "$WORKSPACE/sdk/cwl"
246 handle_python_package
247
248 cd "$WORKSPACE/services/fuse"
249 handle_python_package
250
251 cd "$WORKSPACE/services/nodemanager"
252 handle_python_package
253
254 # arvados-src
255 (
256     cd "$WORKSPACE"
257     COMMIT_HASH=$(format_last_commit_here "%H")
258     arvados_src_version="$(version_from_git)"
259
260     cd $WORKSPACE/packages/$TARGET
261     test_package_presence arvados-src $arvados_src_version src ""
262
263     if [[ "$?" == "0" ]]; then
264       cd "$WORKSPACE"
265       SRC_BUILD_DIR=$(mktemp -d)
266       # mktemp creates the directory with 0700 permissions by default
267       chmod 755 $SRC_BUILD_DIR
268       git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
269       cd "$SRC_BUILD_DIR"
270
271       # go into detached-head state
272       git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
273       echo "$COMMIT_HASH" >git-commit.version
274
275       cd "$SRC_BUILD_DIR"
276       PKG_VERSION=$(version_from_git)
277       cd $WORKSPACE/packages/$TARGET
278       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"
279
280       rm -rf "$SRC_BUILD_DIR"
281
282     fi
283 )
284
285 # On older platforms we need to publish a backport of libfuse >=2.9.2,
286 # and we need to build and install it here in order to even build an
287 # llfuse package.
288 cd $WORKSPACE/packages/$TARGET
289 if [[ $TARGET =~ ubuntu1204 ]]; then
290     # port libfuse 2.9.2 to Ubuntu 12.04
291     LIBFUSE_DIR=$(mktemp -d)
292     (
293         cd $LIBFUSE_DIR
294         # download fuse 2.9.2 ubuntu 14.04 source package
295         file="fuse_2.9.2.orig.tar.xz" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
296         file="fuse_2.9.2-4ubuntu4.14.04.1.debian.tar.xz" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
297         file="fuse_2.9.2-4ubuntu4.14.04.1.dsc" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
298
299         # install dpkg-source and dpkg-buildpackage commands
300         apt-get install -y --no-install-recommends dpkg-dev
301
302         # extract source and apply patches
303         dpkg-source -x fuse_2.9.2-4ubuntu4.14.04.1.dsc
304         rm -f fuse_2.9.2.orig.tar.xz fuse_2.9.2-4ubuntu4.14.04.1.debian.tar.xz fuse_2.9.2-4ubuntu4.14.04.1.dsc
305
306         # add new version to changelog
307         cd fuse-2.9.2
308         (
309             echo "fuse (2.9.2-5) precise; urgency=low"
310             echo
311             echo "  * Backported from trusty-security to precise"
312             echo
313             echo " -- Joshua Randall <jcrandall@alum.mit.edu>  Thu, 4 Feb 2016 11:31:00 -0000"
314             echo
315             cat debian/changelog
316         ) > debian/changelog.new
317         mv debian/changelog.new debian/changelog
318
319         # install build-deps and build
320         apt-get install -y --no-install-recommends debhelper dh-autoreconf libselinux-dev
321         dpkg-buildpackage -rfakeroot -b
322     )
323     fpm_build "$LIBFUSE_DIR/fuse_2.9.2-5_amd64.deb" fuse "Ubuntu Developers" deb "2.9.2" --iteration 5
324     fpm_build "$LIBFUSE_DIR/libfuse2_2.9.2-5_amd64.deb" libfuse2 "Ubuntu Developers" deb "2.9.2" --iteration 5
325     fpm_build "$LIBFUSE_DIR/libfuse-dev_2.9.2-5_amd64.deb" libfuse-dev "Ubuntu Developers" deb "2.9.2" --iteration 5
326     dpkg -i \
327         "$WORKSPACE/packages/$TARGET/fuse_2.9.2-5_amd64.deb" \
328         "$WORKSPACE/packages/$TARGET/libfuse2_2.9.2-5_amd64.deb" \
329         "$WORKSPACE/packages/$TARGET/libfuse-dev_2.9.2-5_amd64.deb"
330     apt-get -y --no-install-recommends -f install
331     rm -rf $LIBFUSE_DIR
332 fi
333
334 # Go binaries
335 cd $WORKSPACE/packages/$TARGET
336 export GOPATH=$(mktemp -d)
337 package_go_binary sdk/go/crunchrunner crunchrunner \
338     "Crunchrunner executes a command inside a container and uploads the output"
339 package_go_binary services/arv-git-httpd arvados-git-httpd \
340     "Provide authenticated http access to Arvados-hosted git repositories"
341 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
342     "Dispatch Crunch containers on the local system"
343 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
344     "Dispatch Crunch containers to a SLURM cluster"
345 package_go_binary services/crunch-run crunch-run \
346     "Supervise a single Crunch container"
347 package_go_binary services/crunchstat crunchstat \
348     "Gather cpu/memory/network statistics of running Crunch jobs"
349 package_go_binary services/keep-balance keep-balance \
350     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
351 package_go_binary services/keepproxy keepproxy \
352     "Make a Keep cluster accessible to clients that are not on the LAN"
353 package_go_binary services/keepstore keepstore \
354     "Keep storage daemon, accessible to clients on the LAN"
355 package_go_binary services/keep-web keep-web \
356     "Static web hosting service for user data stored in Arvados Keep"
357 package_go_binary services/ws arvados-ws \
358     "Arvados Websocket server"
359 package_go_binary tools/keep-block-check keep-block-check \
360     "Verify that all data from one set of Keep servers to another was copied"
361 package_go_binary tools/keep-rsync keep-rsync \
362     "Copy all data from one set of Keep servers to another"
363 package_go_binary tools/keep-exercise keep-exercise \
364     "Performance testing tool for Arvados Keep"
365
366 # The Python SDK
367 # Please resist the temptation to add --no-python-fix-name to the fpm call here
368 # (which would remove the python- prefix from the package name), because this
369 # package is a dependency of arvados-fuse, and fpm can not omit the python-
370 # prefix from only one of the dependencies of a package...  Maybe I could
371 # whip up a patch and send it upstream, but that will be for another day. Ward,
372 # 2014-05-15
373 cd $WORKSPACE/packages/$TARGET
374 rm -rf "$WORKSPACE/sdk/python/build"
375 arvados_python_client_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)
376 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-python-client "$arvados_python_client_version" python
377 if [[ "$?" == "0" ]]; then
378   fpm_build $WORKSPACE/sdk/python "${PYTHON2_PKG_PREFIX}-arvados-python-client" 'Curoverse, Inc.' 'python' "$arvados_python_client_version" "--url=https://arvados.org" "--description=The Arvados Python SDK" --depends "${PYTHON2_PKG_PREFIX}-setuptools" --deb-recommends=git
379 fi
380
381 # cwl-runner
382 cd $WORKSPACE/packages/$TARGET
383 rm -rf "$WORKSPACE/sdk/cwl/build"
384 arvados_cwl_runner_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/cwl/arvados_cwl_runner.egg-info/PKG-INFO)
385 arvados_cwl_runner_iteration=3
386 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-cwl-runner "$arvados_cwl_runner_version" python "$arvados_cwl_runner_iteration"
387 if [[ "$?" == "0" ]]; then
388   fpm_build $WORKSPACE/sdk/cwl "${PYTHON2_PKG_PREFIX}-arvados-cwl-runner" 'Curoverse, Inc.' 'python' "$arvados_cwl_runner_version" "--url=https://arvados.org" "--description=The Arvados CWL runner" --depends "${PYTHON2_PKG_PREFIX}-setuptools" --iteration $arvados_cwl_runner_iteration
389 fi
390
391 # schema_salad. This is a python dependency of arvados-cwl-runner,
392 # but we can't use the usual PYTHONPACKAGES way to build this package due to the
393 # intricacies of how version numbers get generated in setup.py: we need a specific version,
394 # e.g. 1.7.20160316203940. If we don't explicitly list that version with the -v
395 # argument to fpm, and instead specify it as schema_salad==1.7.20160316203940, we get
396 # a package with version 1.7. That's because our gittagger hack is not being
397 # picked up by self.distribution.get_version(), which is called from
398 # https://github.com/jordansissel/fpm/blob/master/lib/fpm/package/pyfpm/get_metadata.py
399 # by means of this command:
400 #
401 # python2.7 setup.py --command-packages=pyfpm get_metadata --output=metadata.json
402 #
403 # So we build this thing separately.
404 #
405 # Ward, 2016-03-17
406 saladversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep schema-salad== | sed "s/.*==\(.*\)'.*/\1/")
407 test_package_presence python-schema-salad "$saladversion" python
408 if [[ "$?" == "0" ]]; then
409   fpm_build schema_salad "" "" python $saladversion --depends "${PYTHON2_PKG_PREFIX}-lockfile >= 1:0.12.2-2"
410 fi
411
412 # And for cwltool we have the same problem as for schema_salad. Ward, 2016-03-17
413 cwltoolversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep cwltool== | sed "s/.*==\(.*\)'.*/\1/")
414 test_package_presence python-cwltool "$cwltoolversion" python
415 if [[ "$?" == "0" ]]; then
416   fpm_build cwltool "" "" python $cwltoolversion
417 fi
418
419 # The PAM module
420 if [[ $TARGET =~ debian|ubuntu ]]; then
421     cd $WORKSPACE/packages/$TARGET
422     rm -rf "$WORKSPACE/sdk/pam/build"
423     libpam_arvados_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)
424     test_package_presence libpam-arvados "$libpam_arvados_version" python
425     if [[ "$?" == "0" ]]; then
426       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
427     fi
428 fi
429
430 # The FUSE driver
431 # Please see comment about --no-python-fix-name above; we stay consistent and do
432 # not omit the python- prefix first.
433 cd $WORKSPACE/packages/$TARGET
434 rm -rf "$WORKSPACE/services/fuse/build"
435 arvados_fuse_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)
436 test_package_presence "${PYTHON2_PKG_PREFIX}-arvados-fuse" "$arvados_fuse_version" python
437 if [[ "$?" == "0" ]]; then
438   fpm_build $WORKSPACE/services/fuse "${PYTHON2_PKG_PREFIX}-arvados-fuse" 'Curoverse, Inc.' 'python' "$arvados_fuse_version" "--url=https://arvados.org" "--description=The Keep FUSE driver" --depends "${PYTHON2_PKG_PREFIX}-setuptools"
439 fi
440
441 # The node manager
442 cd $WORKSPACE/packages/$TARGET
443 rm -rf "$WORKSPACE/services/nodemanager/build"
444 nodemanager_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)
445 test_package_presence arvados-node-manager "$nodemanager_version" python
446 if [[ "$?" == "0" ]]; then
447   fpm_build $WORKSPACE/services/nodemanager arvados-node-manager 'Curoverse, Inc.' 'python' "$nodemanager_version" "--url=https://arvados.org" "--description=The Arvados node manager" --depends "${PYTHON2_PKG_PREFIX}-setuptools"
448 fi
449
450 # The Docker image cleaner
451 cd $WORKSPACE/packages/$TARGET
452 rm -rf "$WORKSPACE/services/dockercleaner/build"
453 dockercleaner_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/dockercleaner/arvados_docker_cleaner.egg-info/PKG-INFO)
454 dockercleaner_iteration=3
455 test_package_presence arvados-docker-cleaner "$dockercleaner_version" python "$dockercleaner_iteration"
456 if [[ "$?" == "0" ]]; then
457   fpm_build $WORKSPACE/services/dockercleaner arvados-docker-cleaner 'Curoverse, Inc.' 'python3' "$dockercleaner_version" "--url=https://arvados.org" "--description=The Arvados Docker image cleaner" --depends "${PYTHON3_PKG_PREFIX}-websocket-client = 0.37.0" --iteration "$dockercleaner_iteration"
458 fi
459
460 # The Arvados crunchstat-summary tool
461 cd $WORKSPACE/packages/$TARGET
462 crunchstat_summary_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/tools/crunchstat-summary/crunchstat_summary.egg-info/PKG-INFO)
463 test_package_presence "$PYTHON2_PKG_PREFIX"-crunchstat-summary "$crunchstat_summary_version" python
464 if [[ "$?" == "0" ]]; then
465   rm -rf "$WORKSPACE/tools/crunchstat-summary/build"
466   fpm_build $WORKSPACE/tools/crunchstat-summary ${PYTHON2_PKG_PREFIX}-crunchstat-summary 'Curoverse, Inc.' 'python' "$crunchstat_summary_version" "--url=https://arvados.org" "--description=Crunchstat-summary reads Arvados Crunch log files and summarize resource usage"
467 fi
468
469 if [[ -z "$ONLY_BUILD" ]] || [[ "${PYTHON2_PKG_PREFIX}-apache-libcloud" == "$ONLY_BUILD" ]] ; then
470   # Forked libcloud
471   LIBCLOUD_DIR=$(mktemp -d)
472   (
473       cd $LIBCLOUD_DIR
474       git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
475       git checkout $DASHQ_UNLESS_DEBUG apache-libcloud-$LIBCLOUD_PIN
476       # libcloud is absurdly noisy without -q, so force -q here
477       OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
478       DASHQ_UNLESS_DEBUG=-q
479       handle_python_package
480       DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
481   )
482   fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud
483   rm -rf $LIBCLOUD_DIR
484 fi
485
486 # Python 2 dependencies
487 declare -a PIP_DOWNLOAD_SWITCHES=(--no-deps)
488 # Add --no-use-wheel if this pip knows it.
489 pip wheel --help >/dev/null 2>&1
490 case "$?" in
491     0) PIP_DOWNLOAD_SWITCHES+=(--no-use-wheel) ;;
492     2) ;;
493     *) echo "WARNING: `pip wheel` test returned unknown exit code $?" ;;
494 esac
495
496 while read -r line || [[ -n "$line" ]]; do
497 #  echo "Text read from file: $line"
498   if [[ "$line" =~ ^# ]]; then
499     continue
500   fi
501   IFS='|'; arr=($line); unset IFS
502
503   dist=${arr[0]}
504
505   IFS=',';dists=($dist); unset IFS
506
507   MATCH=0
508   for d in "${dists[@]}"; do
509     if [[ "$d" == "$TARGET" ]] || [[ "$d" == "all" ]]; then
510       MATCH=1
511     fi
512   done
513
514   if [[ "$MATCH" != "1" ]]; then
515     continue
516   fi
517   name=${arr[1]}
518   version=${arr[2]}
519   iteration=${arr[3]}
520   pkgtype=${arr[4]}
521   arch=${arr[5]}
522   extra=${arr[6]}
523   declare -a 'extra_arr=('"$extra"')'
524
525   if [[ "$FORMAT" == "rpm" ]]; then
526     if [[ "$arch" == "all" ]]; then
527       arch="noarch"
528     fi
529     if [[ "$arch" == "amd64" ]]; then
530       arch="x86_64"
531     fi
532   fi
533
534   if [[ "$pkgtype" == "python" ]]; then
535     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
536   else
537     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
538   fi
539
540   if [[ -n "$ONLY_BUILD" ]] && [[ "$outname" != "$ONLY_BUILD" ]] ; then
541       continue
542   fi
543
544   case "$name" in
545       httplib2|google-api-python-client)
546           test_package_presence $outname $version $pkgtype $iteration $arch
547           if [[ "$?" == "0" ]]; then
548             # Work around 0640 permissions on some package files.
549             # See #7591 and #7991.
550             pyfpm_workdir=$(mktemp --tmpdir -d pyfpm-XXXXXX) && (
551                 set -e
552                 cd "$pyfpm_workdir"
553                 pip install "${PIP_DOWNLOAD_SWITCHES[@]}" --download . "$name==$version"
554                 # Sometimes pip gives us a tarball, sometimes a zip file...
555                 DOWNLOADED=`ls $name-*`
556                 [[ "$DOWNLOADED" =~ ".tar" ]] && tar -xf $DOWNLOADED
557                 [[ "$DOWNLOADED" =~ ".zip" ]] && unzip $DOWNLOADED
558                 cd "$name"-*/
559                 "python$PYTHON2_VERSION" setup.py $DASHQ_UNLESS_DEBUG egg_info build
560                 chmod -R go+rX .
561                 set +e
562                 fpm_build . "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
563                 # The upload step uses the package timestamp to determine
564                 # if it is new.  --no-clobber plays nice with that.
565                 mv --no-clobber "$outname"*.$FORMAT "$WORKSPACE/packages/$TARGET"
566             )
567             if [ 0 != "$?" ]; then
568                 echo "ERROR: $name build process failed"
569                 EXITCODE=1
570             fi
571             if [ -n "$pyfpm_workdir" ]; then
572                 rm -rf "$pyfpm_workdir"
573             fi
574           fi
575           ;;
576       *)
577           test_package_presence $outname $version $pkgtype $iteration $arch
578           if [[ "$?" == "0" ]]; then
579             fpm_build "$name" "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
580           fi
581           ;;
582   esac
583
584 done <`dirname "$(readlink -f "$0")"`"/build.list"
585
586 # Build the API server package
587 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
588 if [[ "$?" == "0" ]]; then
589   handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
590       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
591       --description="Arvados API server - Arvados is a free and open source platform for big data science." \
592       --license="GNU Affero General Public License, version 3.0"
593 fi
594
595 # Build the workbench server package
596 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
597 if [[ "$?" == "0" ]] ; then
598   (
599       set -e
600       cd "$WORKSPACE/apps/workbench"
601
602       # We need to bundle to be ready even when we build a package without vendor directory
603       # because asset compilation requires it.
604       bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
605
606       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
607       # and we want that in the package, so it's easier to not exclude the tmp directory
608       # from the package - empty it instead.
609       rm -rf tmp
610       mkdir tmp
611
612       # Set up application.yml and production.rb so that asset precompilation works
613       \cp config/application.yml.example config/application.yml -f
614       \cp config/environments/production.rb.example config/environments/production.rb -f
615       sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
616
617       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
618
619       # Remove generated configuration files so they don't go in the package.
620       rm config/application.yml config/environments/production.rb
621   )
622
623   if [[ "$?" != "0" ]]; then
624     echo "ERROR: Asset precompilation failed"
625     EXITCODE=1
626   else
627     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
628         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
629         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
630         --license="GNU Affero General Public License, version 3.0"
631   fi
632 fi
633
634 # clean up temporary GOPATH
635 rm -rf "$GOPATH"
636
637 exit $EXITCODE