Merge branch '6939-package-sso-server'
[arvados-dev.git] / jenkins / run-build-packages.sh
1 #!/bin/bash
2
3 . ./run-library.sh
4
5 read -rd "\000" helpmessage <<EOF
6 $(basename $0): Build Arvados packages
7
8 Syntax:
9         WORKSPACE=/path/to/arvados $(basename $0) [options]
10
11 Options:
12
13 --build-bundle-packages  (default: false)
14     Build api server and workbench packages with vendor/bundle included
15 --debug
16     Output debug information (default: false)
17 --target
18     Distribution to build packages for (default: debian7)
19 --command
20     Build command to execute (defaults to the run command defined in the
21     Docker image)
22
23 WORKSPACE=path         Path to the Arvados source tree to build packages from
24
25 EOF
26
27 EXITCODE=0
28 DEBUG=${ARVADOS_DEBUG:-0}
29 BUILD_BUNDLE_PACKAGES=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         --build-bundle-packages)
55             BUILD_BUNDLE_PACKAGES=1
56             ;;
57         --command)
58             COMMAND="$2"; shift
59             ;;
60         --)
61             if [ $# -gt 1 ]; then
62                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
63                 exit 1
64             fi
65             ;;
66     esac
67     shift
68 done
69
70 if [[ "$COMMAND" != "" ]]; then
71   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
72 fi
73
74 STDOUT_IF_DEBUG=/dev/null
75 STDERR_IF_DEBUG=/dev/null
76 DASHQ_UNLESS_DEBUG=-q
77 if [[ "$DEBUG" != 0 ]]; then
78     STDOUT_IF_DEBUG=/dev/stdout
79     STDERR_IF_DEBUG=/dev/stderr
80     DASHQ_UNLESS_DEBUG=
81 fi
82
83 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
84
85 PYTHON2_VERSION=2.7
86 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
87
88 case "$TARGET" in
89     debian7)
90         FORMAT=deb
91         PYTHON2_PACKAGE=python$PYTHON2_VERSION
92         PYTHON2_PKG_PREFIX=python
93         PYTHON3_PACKAGE=python$PYTHON3_VERSION
94         PYTHON3_PKG_PREFIX=python3
95         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
96             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
97             rsa uritemplate httplib2 ws4py \
98             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
99             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
100         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
101         ;;
102     debian8)
103         FORMAT=deb
104         PYTHON2_PACKAGE=python$PYTHON2_VERSION
105         PYTHON2_PKG_PREFIX=python
106         PYTHON3_PACKAGE=python$PYTHON3_VERSION
107         PYTHON3_PKG_PREFIX=python3
108         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
109             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
110             rsa uritemplate httplib2 ws4py \
111             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
112             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
113         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
114         ;;
115     ubuntu1204)
116         FORMAT=deb
117         PYTHON2_PACKAGE=python$PYTHON2_VERSION
118         PYTHON2_PKG_PREFIX=python
119         PYTHON3_PACKAGE=python$PYTHON3_VERSION
120         PYTHON3_PKG_PREFIX=python3
121         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
122             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
123             rsa uritemplate httplib2 ws4py \
124             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
125             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
126         PYTHON3_BACKPORTS=(docker-py 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 pyvcf pyasn1-modules==0.0.5 llfuse ciso8601 \
135             google-api-python-client six uritemplate oauth2client httplib2 \
136             rsa apache-libcloud pycurl backports.ssl_match_hostname)
137         PYTHON3_BACKPORTS=(docker-py requests websocket-client)
138         ;;
139     centos6)
140         FORMAT=rpm
141         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
142         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
143         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
144         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
145         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
146             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
147             rsa uritemplate httplib2 ws4py \
148             pykka apache-libcloud requests six pyexecjs jsonschema \
149             ciso8601 pycrypto backports.ssl_match_hostname pycurl
150             python-daemon lockfile llfuse)
151         PYTHON3_BACKPORTS=(docker-py six requests)
152         export PYCURL_SSL_LIBRARY=nss
153         ;;
154     *)
155         echo -e "$0: Unknown target '$TARGET'.\n" >&2
156         exit 1
157         ;;
158 esac
159
160
161 if ! [[ -n "$WORKSPACE" ]]; then
162   echo >&2 "$helpmessage"
163   echo >&2
164   echo >&2 "Error: WORKSPACE environment variable not set"
165   echo >&2
166   exit 1
167 fi
168
169 # Test for fpm
170 fpm --version >/dev/null 2>&1
171
172 if [[ "$?" != 0 ]]; then
173   echo >&2 "$helpmessage"
174   echo >&2
175   echo >&2 "Error: fpm not found"
176   echo >&2
177   exit 1
178 fi
179
180 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
181 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
182
183 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
184 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
185 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
186   # error; for some reason, the path is not accessible
187   # to the script (e.g. permissions re-evaled after suid)
188   exit 1  # fail
189 fi
190
191 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
192 debug_echo "Workspace is $WORKSPACE"
193
194 if [[ -f /etc/profile.d/rvm.sh ]]; then
195     source /etc/profile.d/rvm.sh
196     GEM="rvm-exec default gem"
197 else
198     GEM=gem
199 fi
200
201 # Make all files world-readable -- jenkins runs with umask 027, and has checked
202 # out our git tree here
203 chmod o+r "$WORKSPACE" -R
204
205 # More cleanup - make sure all executables that we'll package are 755
206 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
207
208 # Now fix our umask to something better suited to building and publishing
209 # gems and packages
210 umask 0022
211
212 debug_echo "umask is" `umask`
213
214 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
215   mkdir -p $WORKSPACE/packages/$TARGET
216 fi
217
218 # Perl packages
219 debug_echo -e "\nPerl packages\n"
220
221 cd "$WORKSPACE/sdk/perl"
222
223 if [[ -e Makefile ]]; then
224   make realclean >"$STDOUT_IF_DEBUG"
225 fi
226 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
227     -delete
228 rm -rf install
229
230 perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
231     make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
232     fpm_build install/lib/=/usr/share libarvados-perl \
233     "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man && \
234     mv libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
235
236 # Ruby gems
237 debug_echo -e "\nRuby gems\n"
238
239 FPM_GEM_PREFIX=$($GEM environment gemdir)
240
241 cd "$WORKSPACE/sdk/ruby"
242 handle_ruby_gem arvados
243
244 cd "$WORKSPACE/sdk/cli"
245 handle_ruby_gem arvados-cli
246
247 cd "$WORKSPACE/services/login-sync"
248 handle_ruby_gem arvados-login-sync
249
250 # Python packages
251 debug_echo -e "\nPython packages\n"
252
253 cd "$WORKSPACE/sdk/pam"
254 handle_python_package
255
256 cd "$WORKSPACE/sdk/python"
257 handle_python_package
258
259 cd "$WORKSPACE/services/fuse"
260 handle_python_package
261
262 cd "$WORKSPACE/services/nodemanager"
263 handle_python_package
264
265 # arvados-src
266 (
267     set -e
268
269     cd "$WORKSPACE"
270     COMMIT_HASH=$(format_last_commit_here "%H")
271
272     SRC_BUILD_DIR=$(mktemp -d)
273     git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
274     cd "$SRC_BUILD_DIR"
275
276     # go into detached-head state
277     git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
278     echo "$COMMIT_HASH" >git-commit.version
279
280     cd "$SRC_BUILD_DIR"
281     PKG_VERSION=$(version_from_git)
282     cd $WORKSPACE/packages/$TARGET
283     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"
284
285     rm -r "$SRC_BUILD_DIR"
286 )
287
288 # Keep
289 export GOPATH=$(mktemp -d)
290 mkdir -p "$GOPATH/src/git.curoverse.com"
291 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
292
293 # keepstore
294 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
295 PKG_VERSION=$(version_from_git)
296 go get "git.curoverse.com/arvados.git/services/keepstore"
297 cd $WORKSPACE/packages/$TARGET
298 fpm_build $GOPATH/bin/keepstore=/usr/bin/keepstore keepstore 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Keepstore is the Keep storage daemon, accessible to clients on the LAN"
299
300 # Get GO SDK version
301 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
302 GO_SDK_VERSION=$(version_from_git)
303 GO_SDK_TIMESTAMP=$(timestamp_from_git)
304
305 # keepproxy
306 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
307 KEEPPROXY_VERSION=$(version_from_git)
308 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
309
310 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
311   PKG_VERSION=$GO_SDK_VERSION
312 else
313   PKG_VERSION=$KEEPPROXY_VERSION
314 fi
315
316 go get "git.curoverse.com/arvados.git/services/keepproxy"
317 cd $WORKSPACE/packages/$TARGET
318 fpm_build $GOPATH/bin/keepproxy=/usr/bin/keepproxy keepproxy 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Keepproxy makes a Keep cluster accessible to clients that are not on the LAN"
319
320 # datamanager
321 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
322 DATAMANAGER_VERSION=$(version_from_git)
323 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
324
325 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
326   PKG_VERSION=$GO_SDK_VERSION
327 else
328   PKG_VERSION=$DATAMANAGER_VERSION
329 fi
330
331 go get "git.curoverse.com/arvados.git/services/datamanager"
332 cd $WORKSPACE/packages/$TARGET
333 fpm_build $GOPATH/bin/datamanager=/usr/bin/arvados-data-manager arvados-data-manager 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Datamanager ensures block replication levels, reports on disk usage and determines which blocks should be deleted when space is needed."
334
335 # arv-git-httpd
336 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
337 ARVGITHTTPD_VERSION=$(version_from_git)
338 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
339
340 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
341   PKG_VERSION=$GO_SDK_VERSION
342 else
343   PKG_VERSION=$ARVGITHTTPD_VERSION
344 fi
345
346 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
347 cd $WORKSPACE/packages/$TARGET
348 fpm_build $GOPATH/bin/arv-git-httpd=/usr/bin/arvados-git-httpd arvados-git-httpd 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Provides authenticated http access to Arvados-hosted git repositories."
349
350 # crunchstat
351 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
352 PKG_VERSION=$(version_from_git)
353 go get "git.curoverse.com/arvados.git/services/crunchstat"
354 cd $WORKSPACE/packages/$TARGET
355 fpm_build $GOPATH/bin/crunchstat=/usr/bin/crunchstat crunchstat 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Crunchstat gathers cpu/memory/network statistics of running Crunch jobs"
356
357 # The Python SDK
358 # Please resist the temptation to add --no-python-fix-name to the fpm call here
359 # (which would remove the python- prefix from the package name), because this
360 # package is a dependency of arvados-fuse, and fpm can not omit the python-
361 # prefix from only one of the dependencies of a package...  Maybe I could
362 # whip up a patch and send it upstream, but that will be for another day. Ward,
363 # 2014-05-15
364 cd $WORKSPACE/packages/$TARGET
365 rm -rf "$WORKSPACE/sdk/python/build"
366 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
367
368 # The PAM module
369 if [[ $TARGET =~ debian|ubuntu ]]; then
370     cd $WORKSPACE/packages/$TARGET
371     rm -rf "$WORKSPACE/sdk/pam/build"
372     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
373 fi
374
375 # The FUSE driver
376 # Please see comment about --no-python-fix-name above; we stay consistent and do
377 # not omit the python- prefix first.
378 cd $WORKSPACE/packages/$TARGET
379 rm -rf "$WORKSPACE/services/fuse/build"
380 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"
381
382 # The node manager
383 cd $WORKSPACE/packages/$TARGET
384 rm -rf "$WORKSPACE/services/nodemanager/build"
385 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"
386
387 # The Docker image cleaner
388 cd $WORKSPACE/packages/$TARGET
389 rm -rf "$WORKSPACE/services/dockercleaner/build"
390 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"
391
392 # A few dependencies
393 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
394     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
395     fpm_build "$deppkg" "$outname"
396 done
397
398 # Python 3 dependencies
399 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
400     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
401     # The empty string is the vendor argument: these aren't Curoverse software.
402     fpm_build "$deppkg" "$outname" "" python3
403 done
404
405 # Build the API server package
406
407 cd "$WORKSPACE/services/api"
408
409 API_VERSION=$(version_from_git)
410 PACKAGE_NAME=arvados-api-server
411
412 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
413   mkdir $WORKSPACE/services/api/tmp
414 fi
415
416
417 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
418   bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
419 fi
420
421 /usr/bin/git rev-parse HEAD > git-commit.version
422
423 cd $WORKSPACE/packages/$TARGET
424
425 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
426 # we do that in the upgrade script.
427 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
428 # package. Then remove that database.yml file again. It has to be a valid file though.
429 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
430
431 # This is the complete package with vendor/bundle included.
432 # It's big, so we do not build it by default.
433 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
434   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$API_VERSION" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh")
435
436   debug_echo -e "\n${COMMAND_ARR[@]}\n"
437
438   FPM_RESULTS=$("${COMMAND_ARR[@]}")
439   FPM_EXIT_CODE=$?
440   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
441 fi
442
443 # Build the 'bare' package without vendor/bundle.
444 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$API_VERSION" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/bundle" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh")
445
446 debug_echo -e "\n${COMMAND_ARR[@]}\n"
447
448 FPM_RESULTS=$("${COMMAND_ARR[@]}")
449 FPM_EXIT_CODE=$?
450 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
451
452 # API server package build done
453
454 # Build the workbench server package
455
456 cd "$WORKSPACE/apps/workbench"
457
458 WORKBENCH_VERSION=$(version_from_git)
459 PACKAGE_NAME=arvados-workbench
460
461 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
462   mkdir $WORKSPACE/apps/workbench/tmp
463 fi
464
465 # We need to bundle to be ready even when we build a package without vendor directory
466 # because asset compilation requires it.
467 bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
468
469 /usr/bin/git rev-parse HEAD > git-commit.version
470
471 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
472 # and we want that in the package, so it's easier to not exclude the tmp directory
473 # from the package - empty it instead.
474 rm -rf $WORKSPACE/apps/workbench/tmp/*
475
476 # Set up application.yml and production.rb so that asset precompilation works
477 \cp config/application.yml.example config/application.yml -f
478 \cp config/environments/production.rb.example config/environments/production.rb -f
479 sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
480
481 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
482
483 if [[ "$?" != "0" ]]; then
484   echo "ERROR: Asset precompilation failed"
485   EXITCODE=1
486 fi
487
488 cd $WORKSPACE/packages/$TARGET
489
490 # This is the complete package with vendor/bundle included.
491 # It's big, so we do not build it by default.
492 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
493
494   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$WORKBENCH_VERSION" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh")
495
496   debug_echo -e "\n${COMMAND_ARR[@]}\n"
497
498   FPM_RESULTS=$("${COMMAND_ARR[@]}")
499   FPM_EXIT_CODE=$?
500   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
501 fi
502
503 # Build the 'bare' package without vendor/bundle.
504
505 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$WORKBENCH_VERSION" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/bundle" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh")
506
507 debug_echo -e "\n${COMMAND_ARR[@]}\n"
508
509 FPM_RESULTS=$("${COMMAND_ARR[@]}")
510 FPM_EXIT_CODE=$?
511 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
512
513 # Workbench package build done
514 # clean up temporary GOPATH
515 rm -rf "$GOPATH"
516
517 exit $EXITCODE