9945: Merge branch 'master' into 9945-make-python-package-dependency-free
[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 # 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=debian8
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 cd "$WORKSPACE/sdk/pam"
252 handle_python_package
253
254 cd "$WORKSPACE/sdk/python"
255 handle_python_package
256
257 cd "$WORKSPACE/sdk/cwl"
258 handle_python_package
259
260 cd "$WORKSPACE/services/fuse"
261 handle_python_package
262
263 cd "$WORKSPACE/services/nodemanager"
264 handle_python_package
265
266 # arvados-src
267 (
268     cd "$WORKSPACE"
269     COMMIT_HASH=$(format_last_commit_here "%H")
270     arvados_src_version="$(version_from_git)"
271
272     cd $WORKSPACE/packages/$TARGET
273     test_package_presence arvados-src $arvados_src_version src ""
274
275     if [[ "$?" == "0" ]]; then
276       cd "$WORKSPACE"
277       SRC_BUILD_DIR=$(mktemp -d)
278       # mktemp creates the directory with 0700 permissions by default
279       chmod 755 $SRC_BUILD_DIR
280       git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
281       cd "$SRC_BUILD_DIR"
282
283       # go into detached-head state
284       git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
285       echo "$COMMIT_HASH" >git-commit.version
286
287       cd "$SRC_BUILD_DIR"
288       PKG_VERSION=$(version_from_git)
289       cd $WORKSPACE/packages/$TARGET
290       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"
291
292       rm -rf "$SRC_BUILD_DIR"
293     fi
294 )
295
296 # Go binaries
297 cd $WORKSPACE/packages/$TARGET
298 export GOPATH=$(mktemp -d)
299 go get github.com/kardianos/govendor
300 package_go_binary cmd/arvados-client arvados-client \
301     "Arvados command line tool (beta)"
302 package_go_binary cmd/arvados-server arvados-server \
303     "Arvados server daemons"
304 package_go_binary cmd/arvados-server arvados-controller \
305     "Arvados cluster controller daemon"
306 # No package until #14325
307 #package_go_binary cmd/arvados-server crunch-dispatch-cloud \
308 #    "Arvados cluster cloud dispatch"
309 package_go_binary sdk/go/crunchrunner crunchrunner \
310     "Crunchrunner executes a command inside a container and uploads the output"
311 package_go_binary services/arv-git-httpd arvados-git-httpd \
312     "Provide authenticated http access to Arvados-hosted git repositories"
313 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
314     "Dispatch Crunch containers on the local system"
315 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
316     "Dispatch Crunch containers to a SLURM cluster"
317 package_go_binary services/crunch-run crunch-run \
318     "Supervise a single Crunch container"
319 package_go_binary services/crunchstat crunchstat \
320     "Gather cpu/memory/network statistics of running Crunch jobs"
321 package_go_binary services/health arvados-health \
322     "Check health of all Arvados cluster services"
323 package_go_binary services/keep-balance keep-balance \
324     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
325 package_go_binary services/keepproxy keepproxy \
326     "Make a Keep cluster accessible to clients that are not on the LAN"
327 package_go_binary services/keepstore keepstore \
328     "Keep storage daemon, accessible to clients on the LAN"
329 package_go_binary services/keep-web keep-web \
330     "Static web hosting service for user data stored in Arvados Keep"
331 package_go_binary services/ws arvados-ws \
332     "Arvados Websocket server"
333 package_go_binary tools/sync-groups arvados-sync-groups \
334     "Synchronize remote groups into Arvados from an external source"
335 package_go_binary tools/keep-block-check keep-block-check \
336     "Verify that all data from one set of Keep servers to another was copied"
337 package_go_binary tools/keep-rsync keep-rsync \
338     "Copy all data from one set of Keep servers to another"
339 package_go_binary tools/keep-exercise keep-exercise \
340     "Performance testing tool for Arvados Keep"
341
342 # The Python SDK
343 fpm_build_virtualenv "arvados-python-client" "sdk/python"
344 fpm_build_virtualenv "arvados-python-client" "sdk/python" "python3"
345
346 # Arvados cwl runner
347 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl"
348
349 # The PAM module
350 fpm_build_virtualenv "libpam-arvados" "sdk/pam"
351
352 # The FUSE driver
353 fpm_build_virtualenv "arvados-fuse" "services/fuse"
354
355 # The node manager
356 fpm_build_virtualenv "arvados-node-manager" "services/nodemanager"
357
358 # The Docker image cleaner
359 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "python3"
360
361 # The Arvados crunchstat-summary tool
362 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary"
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"
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       cd "$WORKSPACE/apps/workbench"
379
380       # We need to bundle to be ready even when we build a package without vendor directory
381       # because asset compilation requires it.
382       bundle install --system >"$STDOUT_IF_DEBUG"
383
384       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
385       # and we want that in the package, so it's easier to not exclude the tmp directory
386       # from the package - empty it instead.
387       rm -rf tmp
388       mkdir tmp
389
390       # Set up application.yml and production.rb so that asset precompilation works
391       \cp config/application.yml.example config/application.yml -f
392       \cp config/environments/production.rb.example config/environments/production.rb -f
393       sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
394       sed -i 's/keep_web_url: false/keep_web_url: exampledotcom/' config/application.yml
395
396       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >/dev/null
397       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
398
399       # Remove generated configuration files so they don't go in the package.
400       rm config/application.yml config/environments/production.rb
401   )
402
403   if [[ "$?" != "0" ]]; then
404     echo "ERROR: Asset precompilation failed"
405     EXITCODE=1
406   else
407     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
408         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
409         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
410         --license="GNU Affero General Public License, version 3.0"
411   fi
412 fi
413
414 # clean up temporary GOPATH
415 rm -rf "$GOPATH"
416
417 exit $EXITCODE