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