4 read -rd "\000" helpmessage <<EOF
5 $(basename $0): Build Arvados SSO package
8 WORKSPACE=/path/to/arvados-sso $(basename $0) [options]
12 --build-bundle-packages (default: false)
13 Build package with vendor/bundle included
15 Output debug information (default: false)
17 Distribution to build packages for (default: debian7)
19 WORKSPACE=path Path to the Arvados SSO source tree to build packages from
24 DEBUG=${ARVADOS_DEBUG:-0}
25 BUILD_BUNDLE_PACKAGES=0
28 PARSEDOPTS=$(getopt --name "$0" --longoptions \
29 help,build-bundle-packages,debug,target: \
35 eval set -- "$PARSEDOPTS"
36 while [ $# -gt 0 ]; do
39 echo >&2 "$helpmessage"
49 --build-bundle-packages)
50 BUILD_BUNDLE_PACKAGES=1
54 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
62 STDOUT_IF_DEBUG=/dev/null
63 STDERR_IF_DEBUG=/dev/null
65 if [[ "$DEBUG" != 0 ]]; then
66 STDOUT_IF_DEBUG=/dev/stdout
67 STDERR_IF_DEBUG=/dev/stderr
72 echo "$@" >"$STDOUT_IF_DEBUG"
92 echo -e "$0: Unknown target '$TARGET'.\n" >&2
98 if ! [[ -n "$WORKSPACE" ]]; then
99 echo >&2 "$helpmessage"
101 echo >&2 "Error: WORKSPACE environment variable not set"
106 if ! [[ -d "$WORKSPACE" ]]; then
107 echo >&2 "$helpmessage"
109 echo >&2 "Error: $WORKSPACE is not a directory"
115 fpm --version >/dev/null 2>&1
117 if [[ "$?" != 0 ]]; then
118 echo >&2 "$helpmessage"
120 echo >&2 "Error: fpm not found"
125 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
126 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`" # absolutized and normalized
127 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
128 # error; for some reason, the path is not accessible
129 # to the script (e.g. permissions re-evaled after suid)
133 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
134 debug_echo "Workspace is $WORKSPACE"
136 format_last_commit_here() {
137 local format=$1; shift
138 TZ=UTC git log -n1 --first-parent "--format=format:$format" .
142 # Generates a version number from the git log for the current working
143 # directory, and writes it to stdout.
144 local git_ts git_hash
145 declare $(format_last_commit_here "git_ts=%ct git_hash=%h")
146 echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
149 nohash_version_from_git() {
150 version_from_git | cut -d. -f1-3
153 timestamp_from_git() {
154 format_last_commit_here "%ct"
157 # verify build results
164 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
165 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
168 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
170 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
174 elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
175 echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
176 elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
177 echo "Error building package for $1:\n $FPM_RESULTS"
181 if [[ -f /etc/profile.d/rvm.sh ]]; then
182 source /etc/profile.d/rvm.sh
183 GEM="rvm-exec default gem"
188 # Make all files world-readable -- jenkins runs with umask 027, and has checked
189 # out our git tree here
190 chmod o+r "$WORKSPACE" -R
192 # More cleanup - make sure all executables that we'll package are 755
193 # No executables in the sso server package
194 #find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
196 # Now fix our umask to something better suited to building and publishing
200 debug_echo "umask is" `umask`
202 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
203 mkdir -p $WORKSPACE/packages/$TARGET
206 # Build the SSO server package
210 SSO_VERSION=$(version_from_git)
211 PACKAGE_NAME=arvados-sso
213 if [[ ! -d "$WORKSPACE/tmp" ]]; then
217 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
218 bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
221 /usr/bin/git rev-parse HEAD > git-commit.version
223 cd $WORKSPACE/packages/$TARGET
225 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
226 # we do that in the upgrade script.
227 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
228 # package. Then remove that database.yml file again. It has to be a valid file though.
229 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
231 # Append --depends X and other arguments specified by fpm-info.sh in
232 # the package source dir. These are added last so they can override
233 # the arguments added by this script.
234 declare -a fpm_args=()
235 declare -a fpm_depends=()
236 FPM_INFO="$WORKSPACE/fpm-info.sh"
237 if [[ -e "$FPM_INFO" ]]; then
238 debug_echo "Loading fpm overrides from $FPM_INFO"
242 # This is the complete package with vendor/bundle included.
243 # It's big, so we do not build it by default.
244 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
245 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados SSO server - Arvados is a free and open source platform for big data science.'" "--license='Expat License'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$SSO_VERSION" "-x" "var/www/arvados-sso/current/.git" "-x" "var/www/arvados-sso/current/tmp" "-x" "var/www/arvados-sso/current/log" "-x" "var/www/arvados-sso/current/vendor/cache/*" "-x" "var/www/arvados-sso/current/packages" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/postinst.sh")
247 for i in "${fpm_depends[@]}"; do
248 COMMAND_ARR+=('--depends' "$i")
250 COMMAND_ARR+=("${fpm_args[@]}")
251 COMMAND_ARR+=("$WORKSPACE/=/var/www/arvados-sso/current" "$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server-upgrade.sh=/usr/local/bin/arvados-sso-server-upgrade.sh")
253 debug_echo -e "\n${COMMAND_ARR[@]}\n"
255 FPM_RESULTS=$("${COMMAND_ARR[@]}")
257 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
260 # Build the 'bare' package without vendor/bundle.
261 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados SSO server - Arvados is a free and open source platform for big data science.'" "--license='Expat License'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$SSO_VERSION" "-x" "var/www/arvados-sso/current/.git" "-x" "var/www/arvados-sso/current/tmp" "-x" "var/www/arvados-sso/current/log" "-x" "var/www/arvados-sso/current/vendor/bundle" "-x" "var/www/arvados-sso/current/vendor/cache/*" "-x" "var/www/arvados-sso/current/packages" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/postinst.sh")
264 for i in "${fpm_depends[@]}"; do
265 COMMAND_ARR+=('--depends' "$i")
267 COMMAND_ARR+=("${fpm_args[@]}")
268 COMMAND_ARR+=("$WORKSPACE/=/var/www/arvados-sso/current" "$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/arvados-sso-server-upgrade.sh=/usr/local/bin/arvados-sso-server-upgrade.sh")
269 debug_echo -e "\n${COMMAND_ARR[@]}\n"
271 FPM_RESULTS=$("${COMMAND_ARR[@]}")
273 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
275 # SSO server package build done