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