8491: move files from arvados-dev into their new places
[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
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
19     Distribution to build packages for (default: debian7)
20 --command
21     Build command to execute (defaults to the run command defined in the
22     Docker image)
23
24 WORKSPACE=path         Path to the Arvados source tree to build packages from
25
26 EOF
27
28 EXITCODE=0
29 DEBUG=${ARVADOS_DEBUG:-0}
30 TARGET=debian7
31 COMMAND=
32
33 PARSEDOPTS=$(getopt --name "$0" --longoptions \
34     help,build-bundle-packages,debug,target: \
35     -- "" "$@")
36 if [ $? -ne 0 ]; then
37     exit 1
38 fi
39
40 eval set -- "$PARSEDOPTS"
41 while [ $# -gt 0 ]; do
42     case "$1" in
43         --help)
44             echo >&2 "$helpmessage"
45             echo >&2
46             exit 1
47             ;;
48         --target)
49             TARGET="$2"; shift
50             ;;
51         --debug)
52             DEBUG=1
53             ;;
54         --command)
55             COMMAND="$2"; shift
56             ;;
57         --)
58             if [ $# -gt 1 ]; then
59                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
60                 exit 1
61             fi
62             ;;
63     esac
64     shift
65 done
66
67 if [[ "$COMMAND" != "" ]]; then
68   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
69 fi
70
71 STDOUT_IF_DEBUG=/dev/null
72 STDERR_IF_DEBUG=/dev/null
73 DASHQ_UNLESS_DEBUG=-q
74 if [[ "$DEBUG" != 0 ]]; then
75     STDOUT_IF_DEBUG=/dev/stdout
76     STDERR_IF_DEBUG=/dev/stderr
77     DASHQ_UNLESS_DEBUG=
78 fi
79
80 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
81
82 PYTHON2_VERSION=2.7
83 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
84
85 case "$TARGET" in
86     debian7)
87         FORMAT=deb
88         PYTHON2_PACKAGE=python$PYTHON2_VERSION
89         PYTHON2_PKG_PREFIX=python
90         PYTHON3_PACKAGE=python$PYTHON3_VERSION
91         PYTHON3_PKG_PREFIX=python3
92         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client==1.4.2 \
93             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
94             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
95             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
96             'pycurl<7.21.5' contextlib2)
97         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
98         ;;
99     debian8)
100         FORMAT=deb
101         PYTHON2_PACKAGE=python$PYTHON2_VERSION
102         PYTHON2_PKG_PREFIX=python
103         PYTHON3_PACKAGE=python$PYTHON3_VERSION
104         PYTHON3_PKG_PREFIX=python3
105         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client==1.4.2 \
106             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
107             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
108             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
109             'pycurl<7.21.5')
110         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
111         ;;
112     ubuntu1204)
113         FORMAT=deb
114         PYTHON2_PACKAGE=python$PYTHON2_VERSION
115         PYTHON2_PKG_PREFIX=python
116         PYTHON3_PACKAGE=python$PYTHON3_VERSION
117         PYTHON3_PKG_PREFIX=python3
118         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client==1.4.2 \
119             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
120             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
121             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
122             contextlib2 \
123             'pycurl<7.21.5')
124         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
125         ;;
126     ubuntu1404)
127         FORMAT=deb
128         PYTHON2_PACKAGE=python$PYTHON2_VERSION
129         PYTHON2_PKG_PREFIX=python
130         PYTHON3_PACKAGE=python$PYTHON3_VERSION
131         PYTHON3_PKG_PREFIX=python3
132         PYTHON_BACKPORTS=(pyasn1==0.1.7 pyvcf pyasn1-modules==0.0.5 llfuse==0.41.1 ciso8601 \
133             google-api-python-client==1.4.2 six uritemplate oauth2client==1.5.2 httplib2 \
134             rsa 'pycurl<7.21.5' backports.ssl_match_hostname)
135         PYTHON3_BACKPORTS=(docker-py requests websocket-client)
136         ;;
137     centos6)
138         FORMAT=rpm
139         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
140         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
141         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
142         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
143         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client==1.4.2 \
144             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
145             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
146             ciso8601 pycrypto backports.ssl_match_hostname 'pycurl<7.21.5' \
147             python-daemon lockfile llfuse==0.41.1 'pbr<1.0')
148         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
149         export PYCURL_SSL_LIBRARY=nss
150         ;;
151     *)
152         echo -e "$0: Unknown target '$TARGET'.\n" >&2
153         exit 1
154         ;;
155 esac
156
157
158 if ! [[ -n "$WORKSPACE" ]]; then
159   echo >&2 "$helpmessage"
160   echo >&2
161   echo >&2 "Error: WORKSPACE environment variable not set"
162   echo >&2
163   exit 1
164 fi
165
166 # Test for fpm
167 fpm --version >/dev/null 2>&1
168
169 if [[ "$?" != 0 ]]; then
170   echo >&2 "$helpmessage"
171   echo >&2
172   echo >&2 "Error: fpm not found"
173   echo >&2
174   exit 1
175 fi
176
177 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
178 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
179
180 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
181 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
182 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
183   # error; for some reason, the path is not accessible
184   # to the script (e.g. permissions re-evaled after suid)
185   exit 1  # fail
186 fi
187
188 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
189 debug_echo "Workspace is $WORKSPACE"
190
191 if [[ -f /etc/profile.d/rvm.sh ]]; then
192     source /etc/profile.d/rvm.sh
193     GEM="rvm-exec default gem"
194 else
195     GEM=gem
196 fi
197
198 # Make all files world-readable -- jenkins runs with umask 027, and has checked
199 # out our git tree here
200 chmod o+r "$WORKSPACE" -R
201
202 # More cleanup - make sure all executables that we'll package are 755
203 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
204
205 # Now fix our umask to something better suited to building and publishing
206 # gems and packages
207 umask 0022
208
209 debug_echo "umask is" `umask`
210
211 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
212   mkdir -p $WORKSPACE/packages/$TARGET
213 fi
214
215 # Perl packages
216 debug_echo -e "\nPerl packages\n"
217
218 cd "$WORKSPACE/sdk/perl"
219
220 if [[ -e Makefile ]]; then
221   make realclean >"$STDOUT_IF_DEBUG"
222 fi
223 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
224     -delete
225 rm -rf install
226
227 perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
228     make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
229     fpm_build install/lib/=/usr/share libarvados-perl \
230     "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man \
231     "$WORKSPACE/LICENSE-2.0.txt=/usr/share/doc/libarvados-perl/LICENSE-2.0.txt" && \
232     mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
233
234 # Ruby gems
235 debug_echo -e "\nRuby gems\n"
236
237 FPM_GEM_PREFIX=$($GEM environment gemdir)
238
239 cd "$WORKSPACE/sdk/ruby"
240 handle_ruby_gem arvados
241
242 cd "$WORKSPACE/sdk/cli"
243 handle_ruby_gem arvados-cli
244
245 cd "$WORKSPACE/services/login-sync"
246 handle_ruby_gem arvados-login-sync
247
248 # Python packages
249 debug_echo -e "\nPython packages\n"
250
251 cd "$WORKSPACE/sdk/pam"
252 handle_python_package
253
254 cd "$WORKSPACE/sdk/python"
255 handle_python_package
256
257 cd "$WORKSPACE/sdk/cwl"
258 handle_python_package
259
260 cd "$WORKSPACE/services/fuse"
261 handle_python_package
262
263 cd "$WORKSPACE/services/nodemanager"
264 handle_python_package
265
266 # arvados-src
267 (
268     set -e
269
270     cd "$WORKSPACE"
271     COMMIT_HASH=$(format_last_commit_here "%H")
272
273     SRC_BUILD_DIR=$(mktemp -d)
274     # mktemp creates the directory with 0700 permissions by default
275     chmod 755 $SRC_BUILD_DIR
276     git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
277     cd "$SRC_BUILD_DIR"
278
279     # go into detached-head state
280     git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
281     echo "$COMMIT_HASH" >git-commit.version
282
283     cd "$SRC_BUILD_DIR"
284     PKG_VERSION=$(version_from_git)
285     cd $WORKSPACE/packages/$TARGET
286     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"
287
288     rm -rf "$SRC_BUILD_DIR"
289 )
290
291 # On older platforms we need to publish a backport of libfuse >=2.9.2,
292 # and we need to build and install it here in order to even build an
293 # llfuse package.
294 cd $WORKSPACE/packages/$TARGET
295 if [[ $TARGET =~ ubuntu1204 ]]; then
296     # port libfuse 2.9.2 to Ubuntu 12.04
297     LIBFUSE_DIR=$(mktemp -d)
298     (
299         cd $LIBFUSE_DIR
300         # download fuse 2.9.2 ubuntu 14.04 source package
301         file="fuse_2.9.2.orig.tar.xz" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
302         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}"
303         file="fuse_2.9.2-4ubuntu4.14.04.1.dsc" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
304
305         # install dpkg-source and dpkg-buildpackage commands
306         apt-get install -y --no-install-recommends dpkg-dev
307
308         # extract source and apply patches
309         dpkg-source -x fuse_2.9.2-4ubuntu4.14.04.1.dsc
310         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
311
312         # add new version to changelog
313         cd fuse-2.9.2
314         (
315             echo "fuse (2.9.2-5) precise; urgency=low"
316             echo
317             echo "  * Backported from trusty-security to precise"
318             echo
319             echo " -- Joshua Randall <jcrandall@alum.mit.edu>  Thu, 4 Feb 2016 11:31:00 -0000"
320             echo
321             cat debian/changelog
322         ) > debian/changelog.new
323         mv debian/changelog.new debian/changelog
324
325         # install build-deps and build
326         apt-get install -y --no-install-recommends debhelper dh-autoreconf libselinux-dev
327         dpkg-buildpackage -rfakeroot -b
328     )
329     fpm_build "$LIBFUSE_DIR/fuse_2.9.2-5_amd64.deb" fuse "Ubuntu Developers" deb "2.9.2" --iteration 5
330     fpm_build "$LIBFUSE_DIR/libfuse2_2.9.2-5_amd64.deb" libfuse2 "Ubuntu Developers" deb "2.9.2" --iteration 5
331     fpm_build "$LIBFUSE_DIR/libfuse-dev_2.9.2-5_amd64.deb" libfuse-dev "Ubuntu Developers" deb "2.9.2" --iteration 5
332     dpkg -i \
333         "$WORKSPACE/packages/$TARGET/fuse_2.9.2-5_amd64.deb" \
334         "$WORKSPACE/packages/$TARGET/libfuse2_2.9.2-5_amd64.deb" \
335         "$WORKSPACE/packages/$TARGET/libfuse-dev_2.9.2-5_amd64.deb"
336     apt-get -y --no-install-recommends -f install
337     rm -rf $LIBFUSE_DIR
338 elif [[ $TARGET =~ centos6 ]]; then
339     # port fuse 2.9.2 to centos 6
340     # install tools to build rpm from source
341     yum install -y rpm-build redhat-rpm-config
342     LIBFUSE_DIR=$(mktemp -d)
343     (
344         cd "$LIBFUSE_DIR"
345         # download fuse 2.9.2 centos 7 source rpm
346         file="fuse-2.9.2-6.el7.src.rpm" && curl -L -o "${file}" "http://vault.centos.org/7.2.1511/os/Source/SPackages/${file}"
347         (
348             # modify source rpm spec to remove conflict on filesystem version
349             mkdir -p /root/rpmbuild/SOURCES
350             cd /root/rpmbuild/SOURCES
351             rpm2cpio ${LIBFUSE_DIR}/fuse-2.9.2-6.el7.src.rpm | cpio -i
352             perl -pi -e 's/Conflicts:\s*filesystem.*//g' fuse.spec
353         )
354         # build rpms from source 
355         rpmbuild -bb /root/rpmbuild/SOURCES/fuse.spec
356         rm -f fuse-2.9.2-6.el7.src.rpm
357         # move built RPMs to LIBFUSE_DIR
358         mv "/root/rpmbuild/RPMS/x86_64/fuse-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
359         mv "/root/rpmbuild/RPMS/x86_64/fuse-libs-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
360         mv "/root/rpmbuild/RPMS/x86_64/fuse-devel-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
361         rm -rf /root/rpmbuild
362     )
363     fpm_build "$LIBFUSE_DIR/fuse-libs-2.9.2-6.el6.x86_64.rpm" fuse-libs "Centos Developers" rpm "2.9.2" --iteration 5
364     fpm_build "$LIBFUSE_DIR/fuse-2.9.2-6.el6.x86_64.rpm" fuse "Centos Developers" rpm "2.9.2" --iteration 5 --no-auto-depends
365     fpm_build "$LIBFUSE_DIR/fuse-devel-2.9.2-6.el6.x86_64.rpm" fuse-devel "Centos Developers" rpm "2.9.2" --iteration 5 --no-auto-depends
366     yum install -y \
367         "$WORKSPACE/packages/$TARGET/fuse-libs-2.9.2-5.x86_64.rpm" \
368         "$WORKSPACE/packages/$TARGET/fuse-2.9.2-5.x86_64.rpm" \
369         "$WORKSPACE/packages/$TARGET/fuse-devel-2.9.2-5.x86_64.rpm"
370 fi
371
372 # Go binaries
373 cd $WORKSPACE/packages/$TARGET
374 export GOPATH=$(mktemp -d)
375 package_go_binary services/keepstore keepstore \
376     "Keep storage daemon, accessible to clients on the LAN"
377 package_go_binary services/keepproxy keepproxy \
378     "Make a Keep cluster accessible to clients that are not on the LAN"
379 package_go_binary services/keep-web keep-web \
380     "Static web hosting service for user data stored in Arvados Keep"
381 package_go_binary services/datamanager arvados-data-manager \
382     "Ensure block replication levels, report disk usage, and determine which blocks should be deleted when space is needed"
383 package_go_binary services/arv-git-httpd arvados-git-httpd \
384     "Provide authenticated http access to Arvados-hosted git repositories"
385 package_go_binary services/crunchstat crunchstat \
386     "Gather cpu/memory/network statistics of running Crunch jobs"
387 package_go_binary tools/keep-rsync keep-rsync \
388     "Copy all data from one set of Keep servers to another"
389
390 # The Python SDK
391 # Please resist the temptation to add --no-python-fix-name to the fpm call here
392 # (which would remove the python- prefix from the package name), because this
393 # package is a dependency of arvados-fuse, and fpm can not omit the python-
394 # prefix from only one of the dependencies of a package...  Maybe I could
395 # whip up a patch and send it upstream, but that will be for another day. Ward,
396 # 2014-05-15
397 cd $WORKSPACE/packages/$TARGET
398 rm -rf "$WORKSPACE/sdk/python/build"
399 fpm_build $WORKSPACE/sdk/python "${PYTHON2_PKG_PREFIX}-arvados-python-client" 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados Python SDK" --deb-recommends=git
400
401 # cwl-runner
402 cd $WORKSPACE/packages/$TARGET
403 rm -rf "$WORKSPACE/sdk/cwl/build"
404 fpm_build $WORKSPACE/sdk/cwl "${PYTHON2_PKG_PREFIX}-arvados-cwl-runner" 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/cwl/arvados_cwl_runner.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados CWL runner"
405
406 # The PAM module
407 if [[ $TARGET =~ debian|ubuntu ]]; then
408     cd $WORKSPACE/packages/$TARGET
409     rm -rf "$WORKSPACE/sdk/pam/build"
410     fpm_build $WORKSPACE/sdk/pam libpam-arvados 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=PAM module for authenticating shell logins using Arvados API tokens" --depends libpam-python
411 fi
412
413 # The FUSE driver
414 # Please see comment about --no-python-fix-name above; we stay consistent and do
415 # not omit the python- prefix first.
416 cd $WORKSPACE/packages/$TARGET
417 rm -rf "$WORKSPACE/services/fuse/build"
418 fpm_build $WORKSPACE/services/fuse "${PYTHON2_PKG_PREFIX}-arvados-fuse" 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Keep FUSE driver"
419
420 # The node manager
421 cd $WORKSPACE/packages/$TARGET
422 rm -rf "$WORKSPACE/services/nodemanager/build"
423 fpm_build $WORKSPACE/services/nodemanager arvados-node-manager 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados node manager"
424
425 # The Docker image cleaner
426 cd $WORKSPACE/packages/$TARGET
427 rm -rf "$WORKSPACE/services/dockercleaner/build"
428 fpm_build $WORKSPACE/services/dockercleaner arvados-docker-cleaner 'Curoverse, Inc.' 'python3' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/dockercleaner/arvados_docker_cleaner.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados Docker image cleaner"
429
430 # Forked libcloud
431 LIBCLOUD_DIR=$(mktemp -d)
432 (
433     cd $LIBCLOUD_DIR
434     git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
435     git checkout apache-libcloud-$LIBCLOUD_PIN
436     # libcloud is absurdly noisy without -q, so force -q here
437     OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
438     DASHQ_UNLESS_DEBUG=-q
439     handle_python_package
440     DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
441 )
442 fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud
443 rm -rf $LIBCLOUD_DIR
444
445 # Python 2 dependencies
446 declare -a PIP_DOWNLOAD_SWITCHES=(--no-deps)
447 # Add --no-use-wheel if this pip knows it.
448 pip wheel --help >/dev/null 2>&1
449 case "$?" in
450     0) PIP_DOWNLOAD_SWITCHES+=(--no-use-wheel) ;;
451     2) ;;
452     *) echo "WARNING: `pip wheel` test returned unknown exit code $?" ;;
453 esac
454
455 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
456     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
457     case "$deppkg" in
458         httplib2|google-api-python-client)
459             # Work around 0640 permissions on some package files.
460             # See #7591 and #7991.
461             pyfpm_workdir=$(mktemp --tmpdir -d pyfpm-XXXXXX) && (
462                 set -e
463                 cd "$pyfpm_workdir"
464                 pip install "${PIP_DOWNLOAD_SWITCHES[@]}" --download . "$deppkg"
465                 tar -xf "$deppkg"-*.tar*
466                 cd "$deppkg"-*/
467                 "python$PYTHON2_VERSION" setup.py $DASHQ_UNLESS_DEBUG egg_info build
468                 chmod -R go+rX .
469                 set +e
470                 # --iteration 2 provides an upgrade for previously built
471                 # buggy packages.
472                 fpm_build . "$outname" "" python "" --iteration 2
473                 # The upload step uses the package timestamp to determine
474                 # whether it's new.  --no-clobber plays nice with that.
475                 mv --no-clobber "$outname"*.$FORMAT "$WORKSPACE/packages/$TARGET"
476             )
477             if [ 0 != "$?" ]; then
478                 echo "ERROR: $deppkg build process failed"
479                 EXITCODE=1
480             fi
481             if [ -n "$pyfpm_workdir" ]; then
482                 rm -rf "$pyfpm_workdir"
483             fi
484             ;;
485         *)
486             fpm_build "$deppkg" "$outname"
487             ;;
488     esac
489 done
490
491 # Python 3 dependencies
492 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
493     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
494     # The empty string is the vendor argument: these aren't Curoverse software.
495     fpm_build "$deppkg" "$outname" "" python3
496 done
497
498 # Build the API server package
499 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
500     "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
501     --description="Arvados API server - Arvados is a free and open source platform for big data science." \
502     --license="GNU Affero General Public License, version 3.0"
503
504 # Build the workbench server package
505 (
506     set -e
507     cd "$WORKSPACE/apps/workbench"
508
509     # We need to bundle to be ready even when we build a package without vendor directory
510     # because asset compilation requires it.
511     bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
512
513     # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
514     # and we want that in the package, so it's easier to not exclude the tmp directory
515     # from the package - empty it instead.
516     rm -rf tmp
517     mkdir tmp
518
519     # Set up application.yml and production.rb so that asset precompilation works
520     \cp config/application.yml.example config/application.yml -f
521     \cp config/environments/production.rb.example config/environments/production.rb -f
522     sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
523
524     RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
525
526     # Remove generated configuration files so they don't go in the package.
527     rm config/application.yml config/environments/production.rb
528 )
529
530 if [[ "$?" != "0" ]]; then
531   echo "ERROR: Asset precompilation failed"
532   EXITCODE=1
533 else
534   handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
535       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
536       --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
537       --license="GNU Affero General Public License, version 3.0"
538 fi
539
540 # clean up temporary GOPATH
541 rm -rf "$GOPATH"
542
543 exit $EXITCODE