15516: Merge branch 'master' into 15516-fix-arvados-server-dependencies
[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: debian9)
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 # Begin of user configuration
34
35 # set to --no-cache-dir to disable pip caching
36 CACHE_FLAG=
37
38 MAINTAINER="Ward Vandewege <wvandewege@veritasgenetics.com>"
39 VENDOR="Veritas Genetics, Inc."
40
41 # End of user configuration
42
43 DEBUG=${ARVADOS_DEBUG:-0}
44 EXITCODE=0
45 TARGET=debian9
46 COMMAND=
47
48 PARSEDOPTS=$(getopt --name "$0" --longoptions \
49     help,build-bundle-packages,debug,target:,only-build: \
50     -- "" "$@")
51 if [ $? -ne 0 ]; then
52     exit 1
53 fi
54
55 eval set -- "$PARSEDOPTS"
56 while [ $# -gt 0 ]; do
57     case "$1" in
58         --help)
59             echo >&2 "$helpmessage"
60             echo >&2
61             exit 1
62             ;;
63         --target)
64             TARGET="$2"; shift
65             ;;
66         --only-build)
67             ONLY_BUILD="$2"; shift
68             ;;
69         --debug)
70             DEBUG=1
71             ;;
72         --command)
73             COMMAND="$2"; shift
74             ;;
75         --)
76             if [ $# -gt 1 ]; then
77                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
78                 exit 1
79             fi
80             ;;
81     esac
82     shift
83 done
84
85 if [[ "$COMMAND" != "" ]]; then
86   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
87 fi
88
89 STDOUT_IF_DEBUG=/dev/null
90 STDERR_IF_DEBUG=/dev/null
91 DASHQ_UNLESS_DEBUG=-q
92 if [[ "$DEBUG" != 0 ]]; then
93     STDOUT_IF_DEBUG=/dev/stdout
94     STDERR_IF_DEBUG=/dev/stderr
95     DASHQ_UNLESS_DEBUG=
96 fi
97
98 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
99
100 PYTHON2_VERSION=2.7
101 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
102
103 ## These defaults are suitable for any Debian-based distribution.
104 # You can customize them as needed in distro sections below.
105 PYTHON2_PACKAGE=python$PYTHON2_VERSION
106 PYTHON2_PKG_PREFIX=python
107 PYTHON2_PREFIX=/usr
108 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
109
110 PYTHON3_PACKAGE=python$PYTHON3_VERSION
111 PYTHON3_PKG_PREFIX=python3
112 PYTHON3_PREFIX=/usr
113 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
114 ## End Debian Python defaults.
115
116 case "$TARGET" in
117     debian*)
118         FORMAT=deb
119         ;;
120     ubuntu*)
121         FORMAT=deb
122         ;;
123     centos*)
124         FORMAT=rpm
125         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
126         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
127         PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
128         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
129         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
130         PYTHON3_PREFIX=/opt/rh/rh-python35/root/usr
131         PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
132         export PYCURL_SSL_LIBRARY=nss
133         ;;
134     *)
135         echo -e "$0: Unknown target '$TARGET'.\n" >&2
136         exit 1
137         ;;
138 esac
139
140
141 if ! [[ -n "$WORKSPACE" ]]; then
142   echo >&2 "$helpmessage"
143   echo >&2
144   echo >&2 "Error: WORKSPACE environment variable not set"
145   echo >&2
146   exit 1
147 fi
148
149 # Test for fpm
150 fpm --version >/dev/null 2>&1
151
152 if [[ "$?" != 0 ]]; then
153   echo >&2 "$helpmessage"
154   echo >&2
155   echo >&2 "Error: fpm not found"
156   echo >&2
157   exit 1
158 fi
159
160 PYTHON2_FPM_INSTALLER=(--python-easyinstall "$(find_python_program easy_install-$PYTHON2_VERSION easy_install)")
161 install3=$(find_python_program easy_install-$PYTHON3_VERSION easy_install3 pip-$PYTHON3_VERSION pip3)
162 if [[ $install3 =~ easy_ ]]; then
163     PYTHON3_FPM_INSTALLER=(--python-easyinstall "$install3")
164 else
165     PYTHON3_FPM_INSTALLER=(--python-pip "$install3")
166 fi
167
168 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
169 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
170 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
171   # error; for some reason, the path is not accessible
172   # to the script (e.g. permissions re-evaled after suid)
173   exit 1  # fail
174 fi
175
176 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
177 debug_echo "Workspace is $WORKSPACE"
178
179 if [[ -f /etc/profile.d/rvm.sh ]]; then
180     source /etc/profile.d/rvm.sh
181     GEM="rvm-exec default gem"
182 else
183     GEM=gem
184 fi
185
186 # Make all files world-readable -- jenkins runs with umask 027, and has checked
187 # out our git tree here
188 chmod o+r "$WORKSPACE" -R
189
190 # More cleanup - make sure all executables that we'll package are 755
191 cd "$WORKSPACE"
192 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
193
194 # Now fix our umask to something better suited to building and publishing
195 # gems and packages
196 umask 0022
197
198 debug_echo "umask is" `umask`
199
200 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
201   mkdir -p $WORKSPACE/packages/$TARGET
202   chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
203 fi
204
205 # Perl packages
206 debug_echo -e "\nPerl packages\n"
207
208 if [[ -z "$ONLY_BUILD" ]] || [[ "libarvados-perl" = "$ONLY_BUILD" ]] ; then
209   cd "$WORKSPACE/sdk/perl"
210   libarvados_perl_version="$(version_from_git)"
211
212   cd $WORKSPACE/packages/$TARGET
213   test_package_presence libarvados-perl "$libarvados_perl_version"
214
215   if [[ "$?" == "0" ]]; then
216     cd "$WORKSPACE/sdk/perl"
217
218     if [[ -e Makefile ]]; then
219       make realclean >"$STDOUT_IF_DEBUG"
220     fi
221     find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
222         -delete
223     rm -rf install
224
225     perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
226         make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
227         fpm_build install/lib/=/usr/share libarvados-perl \
228         dir "$(version_from_git)" install/man/=/usr/share/man \
229         "$WORKSPACE/apache-2.0.txt=/usr/share/doc/libarvados-perl/apache-2.0.txt" && \
230         mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
231   fi
232 fi
233
234 # Ruby gems
235 debug_echo -e "\nRuby gems\n"
236
237 FPM_GEM_PREFIX=$($GEM environment gemdir)
238
239 cd "$WORKSPACE/sdk/ruby"
240 handle_ruby_gem arvados
241
242 cd "$WORKSPACE/sdk/cli"
243 handle_ruby_gem arvados-cli
244
245 cd "$WORKSPACE/services/login-sync"
246 handle_ruby_gem arvados-login-sync
247
248 # Python packages
249 debug_echo -e "\nPython packages\n"
250
251 # arvados-src
252 (
253     cd "$WORKSPACE"
254     COMMIT_HASH=$(format_last_commit_here "%H")
255     arvados_src_version="$(version_from_git)"
256
257     cd $WORKSPACE/packages/$TARGET
258     test_package_presence arvados-src $arvados_src_version src ""
259
260     if [[ "$?" == "0" ]]; then
261       cd "$WORKSPACE"
262       SRC_BUILD_DIR=$(mktemp -d)
263       # mktemp creates the directory with 0700 permissions by default
264       chmod 755 $SRC_BUILD_DIR
265       git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
266       cd "$SRC_BUILD_DIR"
267
268       # go into detached-head state
269       git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
270       echo "$COMMIT_HASH" >git-commit.version
271
272       cd "$SRC_BUILD_DIR"
273       PKG_VERSION=$(version_from_git)
274       cd $WORKSPACE/packages/$TARGET
275       fpm_build $SRC_BUILD_DIR/=/usr/local/arvados/src arvados-src '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"
276
277       rm -rf "$SRC_BUILD_DIR"
278     fi
279 )
280
281 # Go binaries
282 cd $WORKSPACE/packages/$TARGET
283 export GOPATH=$(mktemp -d)
284 go get github.com/kardianos/govendor
285 package_go_binary cmd/arvados-client arvados-client \
286     "Arvados command line tool (beta)"
287 package_go_binary cmd/arvados-server arvados-server \
288     "Arvados server daemons"
289 package_go_binary cmd/arvados-server arvados-controller \
290     "Arvados cluster controller daemon"
291 package_go_binary cmd/arvados-server arvados-dispatch-cloud \
292     "Arvados cluster cloud dispatch"
293 package_go_binary services/arv-git-httpd arvados-git-httpd \
294     "Provide authenticated http access to Arvados-hosted git repositories"
295 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
296     "Dispatch Crunch containers on the local system"
297 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
298     "Dispatch Crunch containers to a SLURM cluster"
299 package_go_binary services/crunch-run crunch-run \
300     "Supervise a single Crunch container"
301 package_go_binary services/crunchstat crunchstat \
302     "Gather cpu/memory/network statistics of running Crunch jobs"
303 package_go_binary services/health arvados-health \
304     "Check health of all Arvados cluster services"
305 package_go_binary services/keep-balance keep-balance \
306     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
307 package_go_binary services/keepproxy keepproxy \
308     "Make a Keep cluster accessible to clients that are not on the LAN"
309 package_go_binary services/keepstore keepstore \
310     "Keep storage daemon, accessible to clients on the LAN"
311 package_go_binary services/keep-web keep-web \
312     "Static web hosting service for user data stored in Arvados Keep"
313 package_go_binary services/ws arvados-ws \
314     "Arvados Websocket server"
315 package_go_binary tools/sync-groups arvados-sync-groups \
316     "Synchronize remote groups into Arvados from an external source"
317 package_go_binary tools/keep-block-check keep-block-check \
318     "Verify that all data from one set of Keep servers to another was copied"
319 package_go_binary tools/keep-rsync keep-rsync \
320     "Copy all data from one set of Keep servers to another"
321 package_go_binary tools/keep-exercise keep-exercise \
322     "Performance testing tool for Arvados Keep"
323
324 # The Python SDK - Should be built first because it's needed by others
325 fpm_build_virtualenv "arvados-python-client" "sdk/python"
326
327 # Arvados cwl runner
328 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl"
329
330 # The PAM module
331 fpm_build_virtualenv "libpam-arvados" "sdk/pam"
332
333 # The FUSE driver
334 fpm_build_virtualenv "arvados-fuse" "services/fuse"
335
336 # The node manager
337 fpm_build_virtualenv "arvados-node-manager" "services/nodemanager"
338
339 # The Arvados crunchstat-summary tool
340 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary"
341
342 # The Python SDK - Python3 package
343 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
344
345 # The Docker image cleaner
346 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
347
348 # The cwltest package, which lives out of tree
349 cd "$WORKSPACE"
350 if [[ -e "$WORKSPACE/cwltest" ]]; then
351         rm -rf "$WORKSPACE/cwltest"
352 fi
353 git clone https://github.com/common-workflow-language/cwltest.git
354 # signal to our build script that we want a cwltest executable installed in /usr/bin/
355 mkdir cwltest/bin && touch cwltest/bin/cwltest
356 fpm_build_virtualenv "cwltest" "cwltest"
357 rm -rf "$WORKSPACE/cwltest"
358
359 calculate_go_package_version arvados_server_version cmd/arvados-server
360 arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
361
362 # Build the API server package
363 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
364 if [[ "$?" == "0" ]]; then
365   handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
366       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
367       --description="Arvados API server - Arvados is a free and open source platform for big data science." \
368       --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
369 fi
370
371 # Build the workbench server package
372 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
373 if [[ "$?" == "0" ]] ; then
374   (
375       set -e
376
377       # The workbench package has a build-time dependency on the arvados-server
378       # package for config manipulation, so install it first.
379       cd $WORKSPACE/cmd/arvados-server
380       get_complete_package_name arvados_server_pkgname arvados-server ${arvados_server_version} go
381
382       arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/${arvados_server_pkgname}"
383       if [[ ! -e ${arvados_server_pkg_path} ]]; then
384         arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/processed/${arvados_server_pkgname}"
385       fi
386       if [[ "$FORMAT" == "deb" ]]; then
387         dpkg -i ${arvados_server_pkg_path}
388       else
389         rpm -i ${arvados_server_pkg_path}
390       fi
391
392       cd "$WORKSPACE/apps/workbench"
393
394       # We need to bundle to be ready even when we build a package without vendor directory
395       # because asset compilation requires it.
396       bundle install --system >"$STDOUT_IF_DEBUG"
397
398       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
399       # and we want that in the package, so it's easier to not exclude the tmp directory
400       # from the package - empty it instead.
401       rm -rf tmp
402       mkdir tmp
403
404       # Set up an appropriate config.yml
405       arvados-server config-dump -config <(cat /etc/arvados/config.yml 2>/dev/null || echo  "Clusters: {zzzzz: {}}") > /tmp/x
406       mkdir -p /etc/arvados/
407       mv /tmp/x /etc/arvados/config.yml
408       perl -p -i -e 'BEGIN{undef $/;} s/WebDAV(.*?):\n( *)ExternalURL: ""/WebDAV$1:\n$2ExternalURL: "example.com"/g' /etc/arvados/config.yml
409
410       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >"$STDOUT_IF_DEBUG"
411       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >"$STDOUT_IF_DEBUG"
412
413       # Remove generated configuration files so they don't go in the package.
414       rm -rf /etc/arvados/
415   )
416
417   if [[ "$?" != "0" ]]; then
418     echo "ERROR: Asset precompilation failed"
419     EXITCODE=1
420   else
421     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
422         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
423         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
424         --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
425   fi
426 fi
427
428 # clean up temporary GOPATH
429 rm -rf "$GOPATH"
430
431 exit $EXITCODE