Merge branch '9162-keep-balance'
[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 ## These defaults are suitable for any Debian-based distribution.
86 # You can customize them as needed in distro sections below.
87 PYTHON2_PACKAGE=python$PYTHON2_VERSION
88 PYTHON2_PKG_PREFIX=python
89 PYTHON2_PREFIX=/usr
90 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
91
92 PYTHON3_PACKAGE=python$PYTHON3_VERSION
93 PYTHON3_PKG_PREFIX=python3
94 PYTHON3_PREFIX=/usr
95 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
96 ## End Debian Python defaults.
97
98 case "$TARGET" in
99     debian7)
100         FORMAT=deb
101         PYTHON_BACKPORTS=(python-gflags==2.0 google-api-python-client==1.4.2 \
102             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
103             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
104             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
105             'pycurl<7.21.5' contextlib2 pyyaml 'rdflib>=4.2.0' \
106             shellescape mistune typing avro ruamel.ordereddict)
107         PYTHON3_BACKPORTS=(docker-py==1.7.2 six requests websocket-client)
108         ;;
109     debian8)
110         FORMAT=deb
111         PYTHON_BACKPORTS=(python-gflags==2.0 google-api-python-client==1.4.2 \
112             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
113             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
114             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
115             'pycurl<7.21.5' pyyaml 'rdflib>=4.2.0' \
116             shellescape mistune typing avro ruamel.ordereddict)
117         PYTHON3_BACKPORTS=(docker-py==1.7.2 six requests websocket-client)
118         ;;
119     ubuntu1204)
120         FORMAT=deb
121         PYTHON_BACKPORTS=(python-gflags==2.0 google-api-python-client==1.4.2 \
122             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
123             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
124             ciso8601 pycrypto backports.ssl_match_hostname llfuse==0.41.1 \
125             contextlib2 'pycurl<7.21.5' pyyaml 'rdflib>=4.2.0' \
126             shellescape mistune typing avro isodate ruamel.ordereddict)
127         PYTHON3_BACKPORTS=(docker-py==1.7.2 six requests websocket-client)
128         ;;
129     ubuntu1404)
130         FORMAT=deb
131         PYTHON_BACKPORTS=(pyasn1==0.1.7 pyasn1-modules==0.0.5 llfuse==0.41.1 ciso8601 \
132             google-api-python-client==1.4.2 six uritemplate oauth2client==1.5.2 httplib2 \
133             rsa 'pycurl<7.21.5' backports.ssl_match_hostname pyyaml 'rdflib>=4.2.0' \
134             shellescape mistune typing avro ruamel.ordereddict)
135         PYTHON3_BACKPORTS=(docker-py==1.7.2 requests websocket-client)
136         ;;
137     centos6)
138         FORMAT=rpm
139         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
140         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
141         PYTHON2_PREFIX=/opt/rh/python27/root/usr
142         PYTHON2_INSTALL_LIB=lib64/python$PYTHON2_VERSION
143         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
144         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
145         PYTHON3_PREFIX=/opt/rh/python33/root/usr
146         PYTHON3_INSTALL_LIB=lib64/python$PYTHON3_VERSION
147         PYTHON_BACKPORTS=(python-gflags==2.0 google-api-python-client==1.4.2 \
148             oauth2client==1.5.2 pyasn1==0.1.7 pyasn1-modules==0.0.5 \
149             rsa uritemplate httplib2 ws4py pykka six pyexecjs jsonschema \
150             ciso8601 pycrypto backports.ssl_match_hostname 'pycurl<7.21.5' \
151             python-daemon lockfile llfuse==0.41.1 'pbr<1.0' pyyaml \
152             'rdflib>=4.2.0' shellescape mistune typing avro requests \
153             isodate pyparsing sparqlwrapper html5lib keepalive \
154             ruamel.ordereddict)
155         PYTHON3_BACKPORTS=(docker-py==1.7.2 six requests websocket-client)
156         export PYCURL_SSL_LIBRARY=nss
157         ;;
158     *)
159         echo -e "$0: Unknown target '$TARGET'.\n" >&2
160         exit 1
161         ;;
162 esac
163
164
165 if ! [[ -n "$WORKSPACE" ]]; then
166   echo >&2 "$helpmessage"
167   echo >&2
168   echo >&2 "Error: WORKSPACE environment variable not set"
169   echo >&2
170   exit 1
171 fi
172
173 # Test for fpm
174 fpm --version >/dev/null 2>&1
175
176 if [[ "$?" != 0 ]]; then
177   echo >&2 "$helpmessage"
178   echo >&2
179   echo >&2 "Error: fpm not found"
180   echo >&2
181   exit 1
182 fi
183
184 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
185 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
186
187 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
188 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
189 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
190   # error; for some reason, the path is not accessible
191   # to the script (e.g. permissions re-evaled after suid)
192   exit 1  # fail
193 fi
194
195 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
196 debug_echo "Workspace is $WORKSPACE"
197
198 if [[ -f /etc/profile.d/rvm.sh ]]; then
199     source /etc/profile.d/rvm.sh
200     GEM="rvm-exec default gem"
201 else
202     GEM=gem
203 fi
204
205 # Make all files world-readable -- jenkins runs with umask 027, and has checked
206 # out our git tree here
207 chmod o+r "$WORKSPACE" -R
208
209 # More cleanup - make sure all executables that we'll package are 755
210 cd "$WORKSPACE"
211 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
212
213 # Now fix our umask to something better suited to building and publishing
214 # gems and packages
215 umask 0022
216
217 debug_echo "umask is" `umask`
218
219 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
220   mkdir -p $WORKSPACE/packages/$TARGET
221 fi
222
223 # Perl packages
224 debug_echo -e "\nPerl packages\n"
225
226 cd "$WORKSPACE/sdk/perl"
227
228 if [[ -e Makefile ]]; then
229   make realclean >"$STDOUT_IF_DEBUG"
230 fi
231 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
232     -delete
233 rm -rf install
234
235 perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
236     make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
237     fpm_build install/lib/=/usr/share libarvados-perl \
238     "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man \
239     "$WORKSPACE/LICENSE-2.0.txt=/usr/share/doc/libarvados-perl/LICENSE-2.0.txt" && \
240     mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
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 elif [[ $TARGET =~ centos6 ]]; then
347     # port fuse 2.9.2 to centos 6
348     # install tools to build rpm from source
349     yum install -y rpm-build redhat-rpm-config
350     LIBFUSE_DIR=$(mktemp -d)
351     (
352         cd "$LIBFUSE_DIR"
353         # download fuse 2.9.2 centos 7 source rpm
354         file="fuse-2.9.2-6.el7.src.rpm" && curl -L -o "${file}" "http://vault.centos.org/7.2.1511/os/Source/SPackages/${file}"
355         (
356             # modify source rpm spec to remove conflict on filesystem version
357             mkdir -p /root/rpmbuild/SOURCES
358             cd /root/rpmbuild/SOURCES
359             rpm2cpio ${LIBFUSE_DIR}/fuse-2.9.2-6.el7.src.rpm | cpio -i
360             perl -pi -e 's/Conflicts:\s*filesystem.*//g' fuse.spec
361         )
362         # build rpms from source
363         rpmbuild -bb /root/rpmbuild/SOURCES/fuse.spec
364         rm -f fuse-2.9.2-6.el7.src.rpm
365         # move built RPMs to LIBFUSE_DIR
366         mv "/root/rpmbuild/RPMS/x86_64/fuse-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
367         mv "/root/rpmbuild/RPMS/x86_64/fuse-libs-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
368         mv "/root/rpmbuild/RPMS/x86_64/fuse-devel-2.9.2-6.el6.x86_64.rpm" ${LIBFUSE_DIR}/
369         rm -rf /root/rpmbuild
370     )
371     fpm_build "$LIBFUSE_DIR/fuse-libs-2.9.2-6.el6.x86_64.rpm" fuse-libs "Centos Developers" rpm "2.9.2" --iteration 5
372     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
373     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
374     yum install -y \
375         "$WORKSPACE/packages/$TARGET/fuse-libs-2.9.2-5.x86_64.rpm" \
376         "$WORKSPACE/packages/$TARGET/fuse-2.9.2-5.x86_64.rpm" \
377         "$WORKSPACE/packages/$TARGET/fuse-devel-2.9.2-5.x86_64.rpm"
378 fi
379
380 # Go binaries
381 cd $WORKSPACE/packages/$TARGET
382 export GOPATH=$(mktemp -d)
383 package_go_binary services/keepstore keepstore \
384     "Keep storage daemon, accessible to clients on the LAN"
385 package_go_binary services/keepproxy keepproxy \
386     "Make a Keep cluster accessible to clients that are not on the LAN"
387 package_go_binary services/keep-balance keep-balance \
388     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
389 package_go_binary services/keep-web keep-web \
390     "Static web hosting service for user data stored in Arvados Keep"
391 package_go_binary services/datamanager arvados-data-manager \
392     "Ensure block replication levels, report disk usage, and determine which blocks should be deleted when space is needed"
393 package_go_binary services/arv-git-httpd arvados-git-httpd \
394     "Provide authenticated http access to Arvados-hosted git repositories"
395 package_go_binary services/crunchstat crunchstat \
396     "Gather cpu/memory/network statistics of running Crunch jobs"
397 package_go_binary tools/keep-rsync keep-rsync \
398     "Copy all data from one set of Keep servers to another"
399 package_go_binary tools/keep-block-check keep-block-check \
400     "Verify that all data from one set of Keep servers to another was copied"
401 package_go_binary sdk/go/crunchrunner crunchrunner \
402     "Crunchrunner executes a command inside a container and uploads the output"
403
404 # The Python SDK
405 # Please resist the temptation to add --no-python-fix-name to the fpm call here
406 # (which would remove the python- prefix from the package name), because this
407 # package is a dependency of arvados-fuse, and fpm can not omit the python-
408 # prefix from only one of the dependencies of a package...  Maybe I could
409 # whip up a patch and send it upstream, but that will be for another day. Ward,
410 # 2014-05-15
411 cd $WORKSPACE/packages/$TARGET
412 rm -rf "$WORKSPACE/sdk/python/build"
413 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
414
415 # cwl-runner
416 cd $WORKSPACE/packages/$TARGET
417 rm -rf "$WORKSPACE/sdk/cwl/build"
418 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 3
419
420 # schema_salad. This is a python dependency of arvados-cwl-runner,
421 # but we can't use the usual PYTHONPACKAGES way to build this package due to the
422 # intricacies of how version numbers get generated in setup.py: we need version
423 # 1.7.20160316203940. If we don't explicitly list that version with the -v
424 # argument to fpm, and instead specify it as schema_salad==1.7.20160316203940, we get
425 # a package with version 1.7. That's because our gittagger hack is not being
426 # picked up by self.distribution.get_version(), which is called from
427 # https://github.com/jordansissel/fpm/blob/master/lib/fpm/package/pyfpm/get_metadata.py
428 # by means of this command:
429 #
430 # python2.7 setup.py --command-packages=pyfpm get_metadata --output=metadata.json
431 #
432 # So we build this thing separately.
433 #
434 # Ward, 2016-03-17
435 fpm_build schema_salad schema_salad "" python 1.7.20160316203940
436
437 # 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.
438 # Ward, 2016-05-26
439 fpm_build ruamel.yaml ruamel.yaml "" python "" --python-setup-py-arguments "--single-version-externally-managed"
440
441 # And for cwltool we have the same problem as for schema_salad. Ward, 2016-03-17
442 fpm_build cwltool cwltool "" python 1.0.20160427142240
443
444 # 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
445 fpm_build rdflib-jsonld rdflib-jsonld "" python 0.3.0
446
447 # The PAM module
448 if [[ $TARGET =~ debian|ubuntu ]]; then
449     cd $WORKSPACE/packages/$TARGET
450     rm -rf "$WORKSPACE/sdk/pam/build"
451     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
452 fi
453
454 # The FUSE driver
455 # Please see comment about --no-python-fix-name above; we stay consistent and do
456 # not omit the python- prefix first.
457 cd $WORKSPACE/packages/$TARGET
458 rm -rf "$WORKSPACE/services/fuse/build"
459 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"
460
461 # The node manager
462 cd $WORKSPACE/packages/$TARGET
463 rm -rf "$WORKSPACE/services/nodemanager/build"
464 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"
465
466 # The Docker image cleaner
467 cd $WORKSPACE/packages/$TARGET
468 rm -rf "$WORKSPACE/services/dockercleaner/build"
469 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"
470
471 # The Arvados crunchstat-summary tool
472 cd $WORKSPACE/packages/$TARGET
473 rm -rf "$WORKSPACE/tools/crunchstat-summary/build"
474 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"
475
476 # Forked libcloud
477 LIBCLOUD_DIR=$(mktemp -d)
478 (
479     cd $LIBCLOUD_DIR
480     git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
481     git checkout apache-libcloud-$LIBCLOUD_PIN
482     # libcloud is absurdly noisy without -q, so force -q here
483     OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
484     DASHQ_UNLESS_DEBUG=-q
485     handle_python_package
486     DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
487 )
488 fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud
489 rm -rf $LIBCLOUD_DIR
490
491 # Python 2 dependencies
492 declare -a PIP_DOWNLOAD_SWITCHES=(--no-deps)
493 # Add --no-use-wheel if this pip knows it.
494 pip wheel --help >/dev/null 2>&1
495 case "$?" in
496     0) PIP_DOWNLOAD_SWITCHES+=(--no-use-wheel) ;;
497     2) ;;
498     *) echo "WARNING: `pip wheel` test returned unknown exit code $?" ;;
499 esac
500
501 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
502     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
503     case "$deppkg" in
504         httplib2|google-api-python-client)
505             # Work around 0640 permissions on some package files.
506             # See #7591 and #7991.
507             pyfpm_workdir=$(mktemp --tmpdir -d pyfpm-XXXXXX) && (
508                 set -e
509                 cd "$pyfpm_workdir"
510                 pip install "${PIP_DOWNLOAD_SWITCHES[@]}" --download . "$deppkg"
511                 # Sometimes pip gives us a tarball, sometimes a zip file...
512                 DOWNLOADED=`ls $deppkg-*`
513                 [[ "$DOWNLOADED" =~ ".tar" ]] && tar -xf $DOWNLOADED
514                 [[ "$DOWNLOADED" =~ ".zip" ]] && unzip $DOWNLOADED
515                 cd "$deppkg"-*/
516                 "python$PYTHON2_VERSION" setup.py $DASHQ_UNLESS_DEBUG egg_info build
517                 chmod -R go+rX .
518                 set +e
519                 fpm_build . "$outname" "" python "" --iteration 3
520                 # The upload step uses the package timestamp to determine
521                 # whether it's new.  --no-clobber plays nice with that.
522                 mv --no-clobber "$outname"*.$FORMAT "$WORKSPACE/packages/$TARGET"
523             )
524             if [ 0 != "$?" ]; then
525                 echo "ERROR: $deppkg build process failed"
526                 EXITCODE=1
527             fi
528             if [ -n "$pyfpm_workdir" ]; then
529                 rm -rf "$pyfpm_workdir"
530             fi
531             ;;
532         *)
533             fpm_build "$deppkg" "$outname"
534             ;;
535     esac
536 done
537
538 # Python 3 dependencies
539 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
540     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
541     # The empty string is the vendor argument: these aren't Curoverse software.
542     fpm_build "$deppkg" "$outname" "" python3
543 done
544
545 # Build the API server package
546 handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
547     "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
548     --description="Arvados API server - Arvados is a free and open source platform for big data science." \
549     --license="GNU Affero General Public License, version 3.0"
550
551 # Build the workbench server package
552 (
553     set -e
554     cd "$WORKSPACE/apps/workbench"
555
556     # We need to bundle to be ready even when we build a package without vendor directory
557     # because asset compilation requires it.
558     bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
559
560     # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
561     # and we want that in the package, so it's easier to not exclude the tmp directory
562     # from the package - empty it instead.
563     rm -rf tmp
564     mkdir tmp
565
566     # Set up application.yml and production.rb so that asset precompilation works
567     \cp config/application.yml.example config/application.yml -f
568     \cp config/environments/production.rb.example config/environments/production.rb -f
569     sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
570
571     RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
572
573     # Remove generated configuration files so they don't go in the package.
574     rm config/application.yml config/environments/production.rb
575 )
576
577 if [[ "$?" != "0" ]]; then
578   echo "ERROR: Asset precompilation failed"
579   EXITCODE=1
580 else
581   handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
582       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
583       --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
584       --license="GNU Affero General Public License, version 3.0"
585 fi
586
587 # clean up temporary GOPATH
588 rm -rf "$GOPATH"
589
590 exit $EXITCODE