]> git.arvados.org - arvados.git/blob - build/run-build-packages.sh
23044: Add integration test for ContainerWebServices.
[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
8 read -rd "\000" helpmessage <<EOF
9 $(basename "$0"): Build Arvados packages
10
11 Syntax:
12         WORKSPACE=/path/to/arvados $(basename "$0") --target <target> [options]
13
14 Options:
15
16 --build-bundle-packages  (default: false)
17     Build api server package with vendor/bundle included
18 --debug
19     Output debug information (default: false)
20 --target <target>
21     Distribution to build packages for
22 --only-build <package>
23     Build only a specific package (or ONLY_BUILD from environment)
24 --force-build
25     Build even if the package exists upstream or if it has already been
26     built locally
27 --command
28     Build command to execute (defaults to the run command defined in the
29     Docker image)
30
31 WORKSPACE=path         Path to the Arvados source tree to build packages from
32
33 EOF
34
35 # Begin of user configuration
36
37 # set to --no-cache-dir to disable pip caching
38 CACHE_FLAG=
39
40 MAINTAINER="Arvados Package Maintainers <packaging@arvados.org>"
41 VENDOR="The Arvados Project"
42
43 # End of user configuration
44
45 DEBUG=${ARVADOS_DEBUG:-0}
46 FORCE_BUILD=${FORCE_BUILD:-0}
47 EXITCODE=0
48 COMMAND=
49 TARGET=
50
51 PARSEDOPTS=$(getopt --name "$0" --longoptions \
52     help,build-bundle-packages,debug,target:,only-build:,arch:,force-build \
53     -- "" "$@")
54 if [ $? -ne 0 ]; then
55     exit 1
56 fi
57
58 eval set -- "$PARSEDOPTS"
59 while [ $# -gt 0 ]; do
60     case "$1" in
61         --help)
62             echo >&2 "$helpmessage"
63             echo >&2
64             exit 1
65             ;;
66         --target)
67             TARGET="$2"; shift
68             ;;
69         --only-build)
70             ONLY_BUILD="$2"; shift
71             ;;
72         --force-build)
73             FORCE_BUILD=1
74             ;;
75         --arch)
76             case "$2" in
77                 amd64) ;;
78                 *)
79                     printf "FATAL: --arch '%s' is not supported" "$2" >&2
80                     exit 2
81                     ;;
82             esac
83             ARCH="$2"; shift
84             ;;
85         --debug)
86             DEBUG=1
87             ;;
88         --command)
89             COMMAND="$2"; shift
90             ;;
91         --)
92             if [ $# -gt 1 ]; then
93                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
94                 exit 1
95             fi
96             ;;
97     esac
98     shift
99 done
100
101 if [[ -z "$TARGET" ]]; then
102     echo "FATAL: --target must be specified" >&2
103     exit 2
104 elif [[ ! -e "$WORKSPACE/build/package-testing/test-packages-$TARGET.sh" ]]; then
105     echo "FATAL: unknown build target '$TARGET'" >&2
106     exit 2
107 fi
108
109 if [[ "$COMMAND" != "" ]]; then
110   COMMAND="bash /jenkins/$COMMAND --target $TARGET"
111 fi
112
113 STDOUT_IF_DEBUG=/dev/null
114 STDERR_IF_DEBUG=/dev/null
115 DASHQ_UNLESS_DEBUG=-q
116 if [[ "$DEBUG" != 0 ]]; then
117     STDOUT_IF_DEBUG=/dev/stdout
118     STDERR_IF_DEBUG=/dev/stderr
119     DASHQ_UNLESS_DEBUG=
120 fi
121
122 # The next section defines a bunch of constants used to build distro packages
123 # for our Python tools. Because those packages include C extensions, they need
124 # to depend on and refer to a specific minor version of Python 3. The logic
125 # below should Just Work for most cases, but you can override variables for a
126 # specific distro if you need to to do something weird.
127 # * PYTHON3_VERSION: The major+minor version of Python we build against
128 #   (e.g., "3.11")
129 # * PYTHON3_EXECUTABLE: The command to run that version of Python,
130 #   either a full path or something in $PATH (e.g., "python3.11")
131 # * PYTHON3_PACKAGE: The name of the distro package that provides
132 #   $PYTHON3_EXECUTABLE. Our Python packages will all depend on this.
133 # * PYTHON3_PKG_PREFIX: The prefix used in the names of all of our Python
134 #   packages. This should match distro convention.
135 PYTHON3_PKG_PREFIX=python3
136 case "$TARGET" in
137     rocky9)
138         FORMAT=rpm
139         PYTHON3_VERSION=3.11
140         ;;
141     centos*|rocky*)
142         FORMAT=rpm
143         ;;
144     debian*|ubuntu*)
145         FORMAT=deb
146         ;;
147     *)
148         echo -e "$0: Unknown target '$TARGET'.\n" >&2
149         exit 1
150         ;;
151 esac
152 : "${PYTHON3_VERSION:=$("${PYTHON3_EXECUTABLE:-python3}" -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')}"
153 : "${PYTHON3_EXECUTABLE:=python$PYTHON3_VERSION}"
154 case "$FORMAT" in
155     deb)
156         : "${PYTHON3_PACKAGE:=python$PYTHON3_VERSION}"
157         ;;
158     rpm)
159         : "${PYTHON3_PACKAGE:=$(rpm -qf "$(command -v "$PYTHON3_EXECUTABLE")" --queryformat '%{NAME}\n')}"
160         ;;
161 esac
162
163 if [[ -z "$WORKSPACE" ]]; then
164   echo >&2 "$helpmessage"
165   echo >&2
166   echo >&2 "Error: WORKSPACE environment variable not set"
167   echo >&2
168   exit 1
169 fi
170
171 # Test for fpm
172 fpm --version >/dev/null 2>&1
173
174 if [[ $? -ne 0 ]]; then
175   echo >&2 "$helpmessage"
176   echo >&2
177   echo >&2 "Error: fpm not found"
178   echo >&2
179   exit 1
180 fi
181
182 RUN_BUILD_PACKAGES_PATH="$(dirname "$0")"
183 RUN_BUILD_PACKAGES_PATH="$(cd "$RUN_BUILD_PACKAGES_PATH" && pwd)"  # absolutized and normalized
184 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
185   # error; for some reason, the path is not accessible
186   # to the script (e.g. permissions re-evaled after suid)
187   exit 1  # fail
188 fi
189
190 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
191 debug_echo "Workspace is $WORKSPACE"
192
193 # Make all files world-readable -- jenkins runs with umask 027, and has checked
194 # out our git tree here
195 chmod o+r "$WORKSPACE" -R
196
197 # More cleanup - make sure all executables that we'll package are 755
198 cd "$WORKSPACE" || exit 1
199 find . -type d -name 'bin' -print0 |xargs -0 -I {} find {} -type f -print0 |xargs -0 -I {} chmod 755 {}
200
201 # Now fix our umask to something better suited to building and publishing
202 # gems and packages
203 umask 0022
204
205 debug_echo "umask is" "$(umask)"
206
207 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
208   mkdir -p "$WORKSPACE/packages/$TARGET"
209   chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
210 fi
211
212 # Required due to CVE-2022-24765
213 git config --global --add safe.directory /arvados
214
215 # Ruby gems
216 debug_echo -e "\nRuby gems\n"
217
218 FPM_GEM_PREFIX=$(gem environment gemdir)
219
220 cd "$WORKSPACE/sdk/ruby" || exit 1
221 handle_ruby_gem arvados
222
223 cd "$WORKSPACE/sdk/cli" || exit 1
224 handle_ruby_gem arvados-cli
225
226 cd "$WORKSPACE/services/login-sync" || exit 1
227 handle_ruby_gem arvados-login-sync
228
229 # arvados-src
230 handle_arvados_src
231
232 # Go packages
233 debug_echo -e "\nGo packages\n"
234
235 # Go binaries
236 export GOPATH=~/go
237 package_go_binary cmd/arvados-client arvados-client "$FORMAT" "$ARCH" \
238     "Arvados command line tool (beta)"
239 package_go_binary cmd/arvados-server arvados-server "$FORMAT" "$ARCH" \
240     "Arvados server daemons"
241 package_go_binary cmd/arvados-server arvados-controller "$FORMAT" "$ARCH" \
242     "Arvados cluster controller daemon"
243 package_go_binary cmd/arvados-server arvados-dispatch-cloud "$FORMAT" "$ARCH" \
244     "Arvados cluster cloud dispatch"
245 package_go_binary cmd/arvados-server arvados-dispatch-lsf "$FORMAT" "$ARCH" \
246     "Dispatch Arvados containers to an LSF cluster"
247 package_go_binary services/crunch-dispatch-local crunch-dispatch-local "$FORMAT" "$ARCH" \
248     "Dispatch Crunch containers on the local system"
249 package_go_binary cmd/arvados-server crunch-dispatch-slurm "$FORMAT" "$ARCH" \
250     "Dispatch Crunch containers to a SLURM cluster"
251 package_go_binary cmd/arvados-server crunch-run "$FORMAT" "$ARCH" \
252     "Supervise a single Crunch container"
253 package_go_binary cmd/arvados-server arvados-health "$FORMAT" "$ARCH" \
254     "Check health of all Arvados cluster services"
255 package_go_binary cmd/arvados-server keep-balance "$FORMAT" "$ARCH" \
256     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
257 package_go_binary cmd/arvados-server keepproxy "$FORMAT" "$ARCH" \
258     "Make a Keep cluster accessible to clients that are not on the LAN"
259 package_go_binary cmd/arvados-server keepstore "$FORMAT" "$ARCH" \
260     "Keep storage daemon, accessible to clients on the LAN"
261 package_go_binary cmd/arvados-server keep-web "$FORMAT" "$ARCH" \
262     "Static web hosting service for user data stored in Arvados Keep"
263 package_go_binary cmd/arvados-server arvados-ws "$FORMAT" "$ARCH" \
264     "Arvados Websocket server"
265 package_go_binary tools/sync-groups arvados-sync-groups "$FORMAT" "$ARCH" \
266     "Synchronize remote groups into Arvados from an external source"
267 package_go_binary tools/sync-users arvados-sync-users "$FORMAT" "$ARCH" \
268     "Synchronize remote users into Arvados from an external source"
269 package_go_binary tools/keep-block-check keep-block-check "$FORMAT" "$ARCH" \
270     "Verify that all data from one set of Keep servers to another was copied"
271 package_go_binary tools/keep-rsync keep-rsync "$FORMAT" "$ARCH" \
272     "Copy all data from one set of Keep servers to another"
273 package_go_binary tools/keep-exercise keep-exercise "$FORMAT" "$ARCH" \
274     "Performance testing tool for Arvados Keep"
275 package_go_so lib/pam pam_arvados.so libpam-arvados-go "$FORMAT" "$ARCH" \
276     "Arvados PAM authentication module"
277
278 # Python packages
279 debug_echo -e "\nPython packages\n"
280
281 # Before a Python package can be built, its dependencies must already be built.
282 # This list is ordered accordingly.
283 setup_build_virtualenv
284 fpm_build_virtualenv "arvados-python-client" "sdk/python" "$FORMAT" "$ARCH"
285 fpm_build_virtualenv "crunchstat-summary" "tools/crunchstat-summary" "$FORMAT" "$ARCH"
286 fpm_build_virtualenv "arvados-cwl-runner" "sdk/cwl" "$FORMAT" "$ARCH"
287 fpm_build_virtualenv "arvados-docker-cleaner" "services/dockercleaner" "$FORMAT" "$ARCH"
288 fpm_build_virtualenv "arvados-fuse" "services/fuse" "$FORMAT" "$ARCH"
289 fpm_build_virtualenv "arvados-user-activity" "tools/user-activity" "$FORMAT" "$ARCH"
290 fpm_build_virtualenv "arvados-cluster-activity" "tools/cluster-activity" "$FORMAT" "$ARCH"
291
292 # Workbench2
293 package_workbench2
294
295 # Rails packages
296 debug_echo -e "\nRails packages\n"
297
298 # The rails api server package
299 handle_api_server "$ARCH"
300
301 # clean up temporary GOPATH
302 rm -rf "$GOPATH"
303
304 exit $EXITCODE