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