16923: Add peer federation / logincluster federation to architecture
[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 || exit 1
7 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh || exit 1
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 PYTHON3_BACKPORTS
106
107 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
108
109 ## These defaults are suitable for any Debian-based distribution.
110 # You can customize them as needed in distro sections below.
111 PYTHON3_PACKAGE=python$PYTHON3_VERSION
112 PYTHON3_PKG_PREFIX=python3
113 PYTHON3_PREFIX=/usr
114 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
115 ## End Debian Python defaults.
116
117 case "$TARGET" in
118     debian*)
119         FORMAT=deb
120         ;;
121     ubuntu*)
122         FORMAT=deb
123         ;;
124     centos*)
125         FORMAT=rpm
126         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
127         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
128         PYTHON3_PREFIX=/opt/rh/rh-python36/root/usr
129         PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
130         export PYCURL_SSL_LIBRARY=nss
131         ;;
132     *)
133         echo -e "$0: Unknown target '$TARGET'.\n" >&2
134         exit 1
135         ;;
136 esac
137
138
139 if ! [[ -n "$WORKSPACE" ]]; then
140   echo >&2 "$helpmessage"
141   echo >&2
142   echo >&2 "Error: WORKSPACE environment variable not set"
143   echo >&2
144   exit 1
145 fi
146
147 # Test for fpm
148 fpm --version >/dev/null 2>&1
149
150 if [[ "$?" != 0 ]]; then
151   echo >&2 "$helpmessage"
152   echo >&2
153   echo >&2 "Error: fpm not found"
154   echo >&2
155   exit 1
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 "$WORKSPACE/sdk/perl" install/lib/=/usr/share libarvados-perl \
218         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 # arvados-src
242 (
243     cd "$WORKSPACE"
244     COMMIT_HASH=$(format_last_commit_here "%H")
245     arvados_src_version="$(version_from_git)"
246
247     cd $WORKSPACE/packages/$TARGET
248     test_package_presence arvados-src $arvados_src_version src ""
249
250     if [[ "$?" == "0" ]]; then
251       cd "$WORKSPACE"
252       SRC_BUILD_DIR=$(mktemp -d)
253       # mktemp creates the directory with 0700 permissions by default
254       chmod 755 $SRC_BUILD_DIR
255       git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
256       cd "$SRC_BUILD_DIR"
257
258       # go into detached-head state
259       git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
260       echo "$COMMIT_HASH" >git-commit.version
261
262       cd "$SRC_BUILD_DIR"
263       PKG_VERSION=$(version_from_git)
264       cd $WORKSPACE/packages/$TARGET
265       fpm_build "$WORKSPACE" $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"
266
267       rm -rf "$SRC_BUILD_DIR"
268     fi
269 )
270
271 # Go binaries
272 cd $WORKSPACE/packages/$TARGET
273 export GOPATH=$(mktemp -d)
274 package_go_binary cmd/arvados-client arvados-client \
275     "Arvados command line tool (beta)"
276 package_go_binary cmd/arvados-server arvados-server \
277     "Arvados server daemons"
278 package_go_binary cmd/arvados-server arvados-controller \
279     "Arvados cluster controller daemon"
280 package_go_binary cmd/arvados-server arvados-dispatch-cloud \
281     "Arvados cluster cloud dispatch"
282 package_go_binary services/arv-git-httpd arvados-git-httpd \
283     "Provide authenticated http access to Arvados-hosted git repositories"
284 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
285     "Dispatch Crunch containers on the local system"
286 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
287     "Dispatch Crunch containers to a SLURM cluster"
288 package_go_binary cmd/arvados-server crunch-run \
289     "Supervise a single Crunch container"
290 package_go_binary services/crunchstat crunchstat \
291     "Gather cpu/memory/network statistics of running Crunch jobs"
292 package_go_binary services/health arvados-health \
293     "Check health of all Arvados cluster services"
294 package_go_binary services/keep-balance keep-balance \
295     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
296 package_go_binary services/keepproxy keepproxy \
297     "Make a Keep cluster accessible to clients that are not on the LAN"
298 package_go_binary services/keepstore keepstore \
299     "Keep storage daemon, accessible to clients on the LAN"
300 package_go_binary services/keep-web keep-web \
301     "Static web hosting service for user data stored in Arvados Keep"
302 package_go_binary cmd/arvados-server arvados-ws \
303     "Arvados Websocket server"
304 package_go_binary tools/sync-groups arvados-sync-groups \
305     "Synchronize remote groups into Arvados from an external source"
306 package_go_binary tools/keep-block-check keep-block-check \
307     "Verify that all data from one set of Keep servers to another was copied"
308 package_go_binary tools/keep-rsync keep-rsync \
309     "Copy all data from one set of Keep servers to another"
310 package_go_binary tools/keep-exercise keep-exercise \
311     "Performance testing tool for Arvados Keep"
312 package_go_so lib/pam pam_arvados.so libpam-arvados-go \
313     "Arvados PAM authentication module"
314
315 # The Python SDK - Python3 package
316 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
317
318 # Arvados cwl runner - Python3 package
319 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl" "python3"
320
321 # The FUSE driver - Python3 package
322 fpm_build_virtualenv "arvados-fuse" "services/fuse" "python3"
323
324 # The Arvados crunchstat-summary tool
325 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary" "python3"
326
327 # The Docker image cleaner
328 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
329
330 # The cwltest package, which lives out of tree
331 cd "$WORKSPACE"
332 if [[ -e "$WORKSPACE/cwltest" ]]; then
333         rm -rf "$WORKSPACE/cwltest"
334 fi
335 git clone https://github.com/common-workflow-language/cwltest.git
336 # signal to our build script that we want a cwltest executable installed in /usr/bin/
337 mkdir cwltest/bin && touch cwltest/bin/cwltest
338 fpm_build_virtualenv "cwltest" "cwltest" "python3"
339 rm -rf "$WORKSPACE/cwltest"
340
341 calculate_go_package_version arvados_server_version cmd/arvados-server
342 arvados_server_iteration=$(default_iteration "arvados-server" "$arvados_server_version" "go")
343
344 # Build the API server package
345 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
346 if [[ "$?" == "0" ]]; then
347   handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
348       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
349       --description="Arvados API server - Arvados is a free and open source platform for big data science." \
350       --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
351 fi
352
353 # Build the workbench server package
354 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
355 if [[ "$?" == "0" ]] ; then
356   (
357       set -e
358
359       # The workbench package has a build-time dependency on the arvados-server
360       # package for config manipulation, so install it first.
361       cd $WORKSPACE/cmd/arvados-server
362       get_complete_package_name arvados_server_pkgname arvados-server ${arvados_server_version} go
363
364       arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/${arvados_server_pkgname}"
365       if [[ ! -e ${arvados_server_pkg_path} ]]; then
366         arvados_server_pkg_path="$WORKSPACE/packages/$TARGET/processed/${arvados_server_pkgname}"
367       fi
368       if [[ "$FORMAT" == "deb" ]]; then
369         dpkg -i ${arvados_server_pkg_path}
370       else
371         rpm -i ${arvados_server_pkg_path}
372       fi
373
374       cd "$WORKSPACE/apps/workbench"
375
376       # We need to bundle to be ready even when we build a package without vendor directory
377       # because asset compilation requires it.
378       bundle install --system >"$STDOUT_IF_DEBUG"
379
380       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
381       # and we want that in the package, so it's easier to not exclude the tmp directory
382       # from the package - empty it instead.
383       rm -rf tmp
384       mkdir tmp
385
386       # Set up an appropriate config.yml
387       arvados-server config-dump -config <(cat /etc/arvados/config.yml 2>/dev/null || echo  "Clusters: {zzzzz: {}}") > /tmp/x
388       mkdir -p /etc/arvados/
389       mv /tmp/x /etc/arvados/config.yml
390       perl -p -i -e 'BEGIN{undef $/;} s/WebDAV(.*?):\n( *)ExternalURL: ""/WebDAV$1:\n$2ExternalURL: "example.com"/g' /etc/arvados/config.yml
391
392       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >"$STDOUT_IF_DEBUG"
393       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >"$STDOUT_IF_DEBUG"
394
395       # Remove generated configuration files so they don't go in the package.
396       rm -rf /etc/arvados/
397   )
398
399   if [[ "$?" != "0" ]]; then
400     echo "ERROR: Asset precompilation failed"
401     EXITCODE=1
402   else
403     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
404         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
405         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
406         --license="GNU Affero General Public License, version 3.0" --depends "arvados-server = ${arvados_server_version}-${arvados_server_iteration}"
407   fi
408 fi
409
410 # clean up temporary GOPATH
411 rm -rf "$GOPATH"
412
413 exit $EXITCODE