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