13306: Updating dict keys as a list to ensure py2/3 compatibility
[arvados.git] / build / run-build-packages.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 . `dirname "$(readlink -f "$0")"`/run-library.sh
7 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh
8
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Build Arvados packages
11
12 Syntax:
13         WORKSPACE=/path/to/arvados $(basename $0) [options]
14
15 Options:
16
17 --build-bundle-packages  (default: false)
18     Build api server and workbench packages with vendor/bundle included
19 --debug
20     Output debug information (default: false)
21 --target <target>
22     Distribution to build packages for (default: debian8)
23 --only-build <package>
24     Build only a specific package (or $ONLY_BUILD from environment)
25 --command
26     Build command to execute (defaults to the run command defined in the
27     Docker image)
28
29 WORKSPACE=path         Path to the Arvados source tree to build packages from
30
31 EOF
32
33 EXITCODE=0
34 DEBUG=${ARVADOS_DEBUG:-0}
35 TARGET=debian8
36 COMMAND=
37
38 PARSEDOPTS=$(getopt --name "$0" --longoptions \
39     help,build-bundle-packages,debug,target:,only-build: \
40     -- "" "$@")
41 if [ $? -ne 0 ]; then
42     exit 1
43 fi
44
45 eval set -- "$PARSEDOPTS"
46 while [ $# -gt 0 ]; do
47     case "$1" in
48         --help)
49             echo >&2 "$helpmessage"
50             echo >&2
51             exit 1
52             ;;
53         --target)
54             TARGET="$2"; shift
55             ;;
56         --only-build)
57             ONLY_BUILD="$2"; shift
58             ;;
59         --debug)
60             DEBUG=1
61             ;;
62         --command)
63             COMMAND="$2"; shift
64             ;;
65         --)
66             if [ $# -gt 1 ]; then
67                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
68                 exit 1
69             fi
70             ;;
71     esac
72     shift
73 done
74
75 if [[ "$COMMAND" != "" ]]; then
76   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
77 fi
78
79 STDOUT_IF_DEBUG=/dev/null
80 STDERR_IF_DEBUG=/dev/null
81 DASHQ_UNLESS_DEBUG=-q
82 if [[ "$DEBUG" != 0 ]]; then
83     STDOUT_IF_DEBUG=/dev/stdout
84     STDERR_IF_DEBUG=/dev/stderr
85     DASHQ_UNLESS_DEBUG=
86 fi
87
88 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
89
90 PYTHON2_VERSION=2.7
91 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
92
93 ## These defaults are suitable for any Debian-based distribution.
94 # You can customize them as needed in distro sections below.
95 PYTHON2_PACKAGE=python$PYTHON2_VERSION
96 PYTHON2_PKG_PREFIX=python
97 PYTHON2_PREFIX=/usr
98 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
99
100 PYTHON3_PACKAGE=python$PYTHON3_VERSION
101 PYTHON3_PKG_PREFIX=python3
102 PYTHON3_PREFIX=/usr
103 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
104 ## End Debian Python defaults.
105
106 case "$TARGET" in
107     debian*)
108         FORMAT=deb
109         ;;
110     ubuntu*)
111         FORMAT=deb
112         ;;
113     centos*)
114         FORMAT=rpm
115         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
116         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
117         PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
118         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
119         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
120         PYTHON3_PREFIX=/opt/rh/python33/root/usr
121         PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
122         export PYCURL_SSL_LIBRARY=nss
123         ;;
124     *)
125         echo -e "$0: Unknown target '$TARGET'.\n" >&2
126         exit 1
127         ;;
128 esac
129
130
131 if ! [[ -n "$WORKSPACE" ]]; then
132   echo >&2 "$helpmessage"
133   echo >&2
134   echo >&2 "Error: WORKSPACE environment variable not set"
135   echo >&2
136   exit 1
137 fi
138
139 # Test for fpm
140 fpm --version >/dev/null 2>&1
141
142 if [[ "$?" != 0 ]]; then
143   echo >&2 "$helpmessage"
144   echo >&2
145   echo >&2 "Error: fpm not found"
146   echo >&2
147   exit 1
148 fi
149
150 PYTHON2_FPM_INSTALLER=(--python-easyinstall "$(find_python_program easy_install-$PYTHON2_VERSION easy_install)")
151 install3=$(find_python_program easy_install-$PYTHON3_VERSION easy_install3 pip-$PYTHON3_VERSION pip3)
152 if [[ $install3 =~ easy_ ]]; then
153     PYTHON3_FPM_INSTALLER=(--python-easyinstall "$install3")
154 else
155     PYTHON3_FPM_INSTALLER=(--python-pip "$install3")
156 fi
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/apache-2.0.txt=/usr/share/doc/libarvados-perl/apache-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 # Go binaries
288 cd $WORKSPACE/packages/$TARGET
289 export GOPATH=$(mktemp -d)
290 go get github.com/kardianos/govendor
291 package_go_binary cmd/arvados-client arvados-client \
292     "Arvados command line tool (beta)"
293 package_go_binary cmd/arvados-server arvados-server \
294     "Arvados server daemons"
295 package_go_binary cmd/arvados-server arvados-controller \
296     "Arvados cluster controller daemon"
297 # No package until #14325
298 #package_go_binary cmd/arvados-server crunch-dispatch-cloud \
299 #    "Arvados cluster cloud dispatch"
300 package_go_binary sdk/go/crunchrunner crunchrunner \
301     "Crunchrunner executes a command inside a container and uploads the output"
302 package_go_binary services/arv-git-httpd arvados-git-httpd \
303     "Provide authenticated http access to Arvados-hosted git repositories"
304 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
305     "Dispatch Crunch containers on the local system"
306 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
307     "Dispatch Crunch containers to a SLURM cluster"
308 package_go_binary services/crunch-run crunch-run \
309     "Supervise a single Crunch container"
310 package_go_binary services/crunchstat crunchstat \
311     "Gather cpu/memory/network statistics of running Crunch jobs"
312 package_go_binary services/health arvados-health \
313     "Check health of all Arvados cluster services"
314 package_go_binary services/keep-balance keep-balance \
315     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
316 package_go_binary services/keepproxy keepproxy \
317     "Make a Keep cluster accessible to clients that are not on the LAN"
318 package_go_binary services/keepstore keepstore \
319     "Keep storage daemon, accessible to clients on the LAN"
320 package_go_binary services/keep-web keep-web \
321     "Static web hosting service for user data stored in Arvados Keep"
322 package_go_binary services/ws arvados-ws \
323     "Arvados Websocket server"
324 package_go_binary tools/sync-groups arvados-sync-groups \
325     "Synchronize remote groups into Arvados from an external source"
326 package_go_binary tools/keep-block-check keep-block-check \
327     "Verify that all data from one set of Keep servers to another was copied"
328 package_go_binary tools/keep-rsync keep-rsync \
329     "Copy all data from one set of Keep servers to another"
330 package_go_binary tools/keep-exercise keep-exercise \
331     "Performance testing tool for Arvados Keep"
332
333
334 # we need explicit debian_revision values in the dependencies for ruamel.yaml, because we have a package iteration
335 # greater than zero. So we parse setup.py, get the ruamel.yaml dependencies, tell fpm not to automatically include
336 # them in the package being built, and re-add them manually with an appropriate debian_revision value.
337 # See #14552 for the reason for this (nasty) workaround. We use ${ruamel_depends[@]} in a few places further down
338 # in this script.
339 # Ward, 2018-11-28
340 IFS=', ' read -r -a deps <<< `grep ruamel.yaml $WORKSPACE/sdk/python/setup.py |cut -f 3 -dl |sed -e "s/'//g"`
341 declare -a ruamel_depends=()
342 for i in ${deps[@]}; do
343   i=`echo "$i" | sed -e 's!\([0-9]\)! \1!'`
344   if [[ $i =~ .*\>.* ]]; then
345     ruamel_depends+=(--depends "python-ruamel.yaml $i-1")
346   elif [[ $i =~ .*\<.* ]]; then
347     ruamel_depends+=(--depends "python-ruamel.yaml $i-9")
348   else
349     echo "Encountered ruamel dependency that I can't parse. Aborting..."
350     exit 1
351   fi
352 done
353
354
355 # The Python SDK
356 # Please resist the temptation to add --no-python-fix-name to the fpm call here
357 # (which would remove the python- prefix from the package name), because this
358 # package is a dependency of arvados-fuse, and fpm can not omit the python-
359 # prefix from only one of the dependencies of a package...  Maybe I could
360 # whip up a patch and send it upstream, but that will be for another day. Ward,
361 # 2014-05-15
362 cd $WORKSPACE/packages/$TARGET
363 rm -rf "$WORKSPACE/sdk/python/build"
364 arvados_python_client_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)}
365 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-python-client "$arvados_python_client_version" python
366 if [[ "$?" == "0" ]]; then
367
368   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  --python-disable-dependency ruamel.yaml "${ruamel_depends[@]}"
369 fi
370
371 # cwl-runner
372 cd $WORKSPACE/packages/$TARGET
373 rm -rf "$WORKSPACE/sdk/cwl/build"
374 arvados_cwl_runner_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/cwl/arvados_cwl_runner.egg-info/PKG-INFO)}
375 declare -a iterargs=()
376 if [[ -z "$ARVADOS_BUILDING_VERSION" ]]; then
377     arvados_cwl_runner_iteration=4
378     iterargs+=(--iteration $arvados_cwl_runner_iteration)
379 else
380     arvados_cwl_runner_iteration=
381 fi
382 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-cwl-runner "$arvados_cwl_runner_version" python "$arvados_cwl_runner_iteration"
383 if [[ "$?" == "0" ]]; then
384   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" --depends "${PYTHON2_PKG_PREFIX}-subprocess32 >= 3.5.0" --depends "${PYTHON2_PKG_PREFIX}-pathlib2" --depends "${PYTHON2_PKG_PREFIX}-scandir" --python-disable-dependency ruamel.yaml "${ruamel_depends[@]}" "${iterargs[@]}"
385 fi
386
387 # schema_salad. This is a python dependency of arvados-cwl-runner,
388 # but we can't use the usual PYTHONPACKAGES way to build this package due to the
389 # intricacies of how version numbers get generated in setup.py: we need a specific version,
390 # e.g. 1.7.20160316203940. If we don't explicitly list that version with the -v
391 # argument to fpm, and instead specify it as schema_salad==1.7.20160316203940, we get
392 # a package with version 1.7. That's because our gittagger hack is not being
393 # picked up by self.distribution.get_version(), which is called from
394 # https://github.com/jordansissel/fpm/blob/master/lib/fpm/package/pyfpm/get_metadata.py
395 # by means of this command:
396 #
397 # python2.7 setup.py --command-packages=pyfpm get_metadata --output=metadata.json
398 #
399 # So we build this thing separately.
400 #
401 # Ward, 2016-03-17
402 saladversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep schema-salad== | sed "s/.*==\(.*\)'.*/\1/")
403 test_package_presence python-schema-salad "$saladversion" python 2
404 if [[ "$?" == "0" ]]; then
405   fpm_build schema_salad "" "" python $saladversion --depends "${PYTHON2_PKG_PREFIX}-lockfile >= 1:0.12.2-2" --depends "${PYTHON2_PKG_PREFIX}-avro = 1.8.1-2" --iteration 2
406 fi
407
408 # And for cwltool we have the same problem as for schema_salad. Ward, 2016-03-17
409 cwltoolversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep cwltool== | sed "s/.*==\(.*\)'.*/\1/")
410 test_package_presence python-cwltool "$cwltoolversion" python 3
411 if [[ "$?" == "0" ]]; then
412   fpm_build cwltool "" "" python $cwltoolversion --iteration 3 --python-disable-dependency ruamel.yaml "${ruamel_depends[@]}"
413 fi
414
415 # The PAM module
416 if [[ $TARGET =~ debian|ubuntu ]]; then
417     cd $WORKSPACE/packages/$TARGET
418     rm -rf "$WORKSPACE/sdk/pam/build"
419     libpam_arvados_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)
420     test_package_presence libpam-arvados "$libpam_arvados_version" python
421     if [[ "$?" == "0" ]]; then
422       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
423     fi
424 fi
425
426 # The FUSE driver
427 # Please see comment about --no-python-fix-name above; we stay consistent and do
428 # not omit the python- prefix first.
429 cd $WORKSPACE/packages/$TARGET
430 rm -rf "$WORKSPACE/services/fuse/build"
431 arvados_fuse_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)}
432 test_package_presence "${PYTHON2_PKG_PREFIX}-arvados-fuse" "$arvados_fuse_version" python
433 if [[ "$?" == "0" ]]; then
434   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"
435 fi
436
437 # The node manager
438 cd $WORKSPACE/packages/$TARGET
439 rm -rf "$WORKSPACE/services/nodemanager/build"
440 nodemanager_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)}
441 iteration="${ARVADOS_BUILDING_ITERATION:-1}"
442 test_package_presence arvados-node-manager "$nodemanager_version" python "$iteration"
443 if [[ "$?" == "0" ]]; then
444   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" --iteration "$iteration"
445 fi
446
447 # The Docker image cleaner
448 cd $WORKSPACE/packages/$TARGET
449 rm -rf "$WORKSPACE/services/dockercleaner/build"
450 dockercleaner_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/dockercleaner/arvados_docker_cleaner.egg-info/PKG-INFO)}
451 iteration="${ARVADOS_BUILDING_ITERATION:-4}"
452 test_package_presence arvados-docker-cleaner "$dockercleaner_version" python "$iteration"
453 if [[ "$?" == "0" ]]; then
454   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 "$iteration"
455 fi
456
457 # The Arvados crunchstat-summary tool
458 cd $WORKSPACE/packages/$TARGET
459 crunchstat_summary_version=${ARVADOS_BUILDING_VERSION:-$(awk '($1 == "Version:"){print $2}' $WORKSPACE/tools/crunchstat-summary/crunchstat_summary.egg-info/PKG-INFO)}
460 iteration="${ARVADOS_BUILDING_ITERATION:-2}"
461 test_package_presence "$PYTHON2_PKG_PREFIX"-crunchstat-summary "$crunchstat_summary_version" python "$iteration"
462 if [[ "$?" == "0" ]]; then
463   rm -rf "$WORKSPACE/tools/crunchstat-summary/build"
464   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" --iteration "$iteration"
465 fi
466
467 # Forked libcloud
468 if test_package_presence "$PYTHON2_PKG_PREFIX"-apache-libcloud "$LIBCLOUD_PIN" python 2
469 then
470   LIBCLOUD_DIR=$(mktemp -d)
471   (
472       cd $LIBCLOUD_DIR
473       git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
474       git checkout $DASHQ_UNLESS_DEBUG apache-libcloud-$LIBCLOUD_PIN
475       # libcloud is absurdly noisy without -q, so force -q here
476       OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
477       DASHQ_UNLESS_DEBUG=-q
478       handle_python_package
479       DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
480   )
481
482   # libcloud >= 2.3.0 now requires python-requests 2.4.3 or higher, otherwise
483   # it throws
484   #   ImportError: No module named packages.urllib3.poolmanager
485   # when loaded. We only see this problem on ubuntu1404, because that is our
486   # only supported distribution that ships with a python-requests older than
487   # 2.4.3.
488   fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud "" python "" --iteration 2 --depends 'python-requests >= 2.4.3'
489   rm -rf $LIBCLOUD_DIR
490 fi
491
492 # Python 2 dependencies
493 declare -a PIP_DOWNLOAD_SWITCHES=(--no-deps)
494 # Add --no-use-wheel if this pip knows it.
495 pip install --no-use-wheel >/dev/null 2>&1
496 case "$?" in
497     0) PIP_DOWNLOAD_SWITCHES+=(--no-use-wheel) ;;
498     1) ;;
499     2) ;;
500     *) echo "WARNING: 'pip install --no-use-wheel' test returned unknown exit code $?" ;;
501 esac
502
503 while read -r line || [[ -n "$line" ]]; do
504 #  echo "Text read from file: $line"
505   if [[ "$line" =~ ^# ]]; then
506     continue
507   fi
508   IFS='|'; arr=($line); unset IFS
509
510   dist=${arr[0]}
511
512   IFS=',';dists=($dist); unset IFS
513
514   MATCH=0
515   for d in "${dists[@]}"; do
516     if [[ "$d" == "$TARGET" ]] || [[ "$d" == "all" ]]; then
517       MATCH=1
518     fi
519   done
520
521   if [[ "$MATCH" != "1" ]]; then
522     continue
523   fi
524   name=${arr[1]}
525   version=${arr[2]}
526   iteration=${arr[3]}
527   pkgtype=${arr[4]}
528   arch=${arr[5]}
529   extra=${arr[6]}
530   declare -a 'extra_arr=('"$extra"')'
531
532   if [[ "$FORMAT" == "rpm" ]]; then
533     if [[ "$arch" == "all" ]]; then
534       arch="noarch"
535     fi
536     if [[ "$arch" == "amd64" ]]; then
537       arch="x86_64"
538     fi
539   fi
540
541   if [[ "$pkgtype" == "python" ]]; then
542     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
543   else
544     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
545   fi
546
547   if [[ -n "$ONLY_BUILD" ]] && [[ "$outname" != "$ONLY_BUILD" ]] ; then
548       continue
549   fi
550
551   case "$name" in
552       httplib2|google-api-python-client)
553           test_package_presence $outname $version $pkgtype $iteration $arch
554           if [[ "$?" == "0" ]]; then
555             # Work around 0640 permissions on some package files.
556             # See #7591 and #7991.
557             pyfpm_workdir=$(mktemp --tmpdir -d pyfpm-XXXXXX) && (
558                 set -e
559                 cd "$pyfpm_workdir"
560                 PIP_VERSION=`python$PYTHON2_VERSION -c "import pip; print(pip.__version__)" |cut -f1 -d.`
561                 if (( $PIP_VERSION < 8 )); then
562                   pip install "${PIP_DOWNLOAD_SWITCHES[@]}" --download . "$name==$version"
563                 else
564                   pip download --no-deps --no-binary :all: "$name==$version"
565                 fi
566                 # Sometimes pip gives us a tarball, sometimes a zip file...
567                 DOWNLOADED=`ls $name-*`
568                 [[ "$DOWNLOADED" =~ ".tar" ]] && tar -xf $DOWNLOADED
569                 [[ "$DOWNLOADED" =~ ".zip" ]] && unzip $DOWNLOADED
570                 cd "$name"-*/
571                 "python$PYTHON2_VERSION" setup.py $DASHQ_UNLESS_DEBUG egg_info build
572                 chmod -R go+rX .
573                 set +e
574                 fpm_build . "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
575                 # The upload step uses the package timestamp to determine
576                 # if it is new.  --no-clobber plays nice with that.
577                 mv --no-clobber "$outname"*.$FORMAT "$WORKSPACE/packages/$TARGET"
578             )
579             if [ 0 != "$?" ]; then
580                 echo "ERROR: $name build process failed"
581                 EXITCODE=1
582             fi
583             if [ -n "$pyfpm_workdir" ]; then
584                 rm -rf "$pyfpm_workdir"
585             fi
586           fi
587           ;;
588       *)
589           test_package_presence $outname $version $pkgtype $iteration $arch
590           if [[ "$?" == "0" ]]; then
591             fpm_build "$name" "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
592           fi
593           ;;
594   esac
595
596 done <`dirname "$(readlink -f "$0")"`"/build.list"
597
598 # Build the API server package
599 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
600 if [[ "$?" == "0" ]]; then
601   handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
602       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
603       --description="Arvados API server - Arvados is a free and open source platform for big data science." \
604       --license="GNU Affero General Public License, version 3.0"
605 fi
606
607 # Build the workbench server package
608 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
609 if [[ "$?" == "0" ]] ; then
610   (
611       set -e
612       cd "$WORKSPACE/apps/workbench"
613
614       # We need to bundle to be ready even when we build a package without vendor directory
615       # because asset compilation requires it.
616       bundle install --system >"$STDOUT_IF_DEBUG"
617
618       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
619       # and we want that in the package, so it's easier to not exclude the tmp directory
620       # from the package - empty it instead.
621       rm -rf tmp
622       mkdir tmp
623
624       # Set up application.yml and production.rb so that asset precompilation works
625       \cp config/application.yml.example config/application.yml -f
626       \cp config/environments/production.rb.example config/environments/production.rb -f
627       sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
628       sed -i 's/keep_web_url: false/keep_web_url: exampledotcom/' config/application.yml
629
630       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >/dev/null
631       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
632
633       # Remove generated configuration files so they don't go in the package.
634       rm config/application.yml config/environments/production.rb
635   )
636
637   if [[ "$?" != "0" ]]; then
638     echo "ERROR: Asset precompilation failed"
639     EXITCODE=1
640   else
641     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
642         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
643         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
644         --license="GNU Affero General Public License, version 3.0"
645   fi
646 fi
647
648 # clean up temporary GOPATH
649 rm -rf "$GOPATH"
650
651 exit $EXITCODE