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