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