5 read -rd "\000" helpmessage <<EOF
6 $(basename $0): Build Arvados SSO package
9 WORKSPACE=/path/to/arvados-sso $(basename $0) [options]
13 --build-bundle-packages (default: false)
14 Build package with vendor/bundle included
16 Output debug information (default: false)
18 Distribution to build packages for (default: debian7)
20 WORKSPACE=path Path to the Arvados SSO source tree to build packages from
25 DEBUG=${ARVADOS_DEBUG:-0}
26 BUILD_BUNDLE_PACKAGES=0
29 PARSEDOPTS=$(getopt --name "$0" --longoptions \
30 help,build-bundle-packages,debug,target: \
36 eval set -- "$PARSEDOPTS"
37 while [ $# -gt 0 ]; do
40 echo >&2 "$helpmessage"
50 --build-bundle-packages)
51 BUILD_BUNDLE_PACKAGES=1
55 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
63 STDOUT_IF_DEBUG=/dev/null
64 STDERR_IF_DEBUG=/dev/null
66 if [[ "$DEBUG" != 0 ]]; then
67 STDOUT_IF_DEBUG=/dev/stdout
68 STDERR_IF_DEBUG=/dev/stderr
89 echo -e "$0: Unknown target '$TARGET'.\n" >&2
94 if ! [[ -n "$WORKSPACE" ]]; then
95 echo >&2 "$helpmessage"
97 echo >&2 "Error: WORKSPACE environment variable not set"
102 if ! [[ -d "$WORKSPACE" ]]; then
103 echo >&2 "$helpmessage"
105 echo >&2 "Error: $WORKSPACE is not a directory"
111 fpm --version >/dev/null 2>&1
113 if [[ "$?" != 0 ]]; then
114 echo >&2 "$helpmessage"
116 echo >&2 "Error: fpm not found"
121 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
122 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`" # absolutized and normalized
123 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
124 # error; for some reason, the path is not accessible
125 # to the script (e.g. permissions re-evaled after suid)
129 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
130 debug_echo "Workspace is $WORKSPACE"
132 if [[ -f /etc/profile.d/rvm.sh ]]; then
133 source /etc/profile.d/rvm.sh
134 GEM="rvm-exec default gem"
139 # Make all files world-readable -- jenkins runs with umask 027, and has checked
140 # out our git tree here
141 chmod o+r "$WORKSPACE" -R
143 # More cleanup - make sure all executables that we'll package are 755
144 # No executables in the sso server package
145 #find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
147 # Now fix our umask to something better suited to building and publishing
151 debug_echo "umask is" `umask`
153 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
154 mkdir -p $WORKSPACE/packages/$TARGET
157 # Build the SSO server package
161 SSO_VERSION=$(version_from_git)
162 PACKAGE_NAME=arvados-sso
164 if [[ ! -d "$WORKSPACE/tmp" ]]; then
168 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
169 bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
172 /usr/bin/git rev-parse HEAD > git-commit.version
174 cd $WORKSPACE/packages/$TARGET
176 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
177 # we do that in the upgrade script.
178 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
179 # package. Then remove that database.yml file again. It has to be a valid file though.
180 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
182 # There are just 2 excludes left here, all the others are pulled in via fpm-info.sh.
183 # The .git directory is excluded by git implicitly, so we can't pick it up from .gitignore.
184 # The packages directory needs to be explictly excluded here because it will only be listed
185 # if it exists at the time fpm-info.sh runs. If it does not exist at that time, this script
186 # will create it and when fpm runs, it will include the directory. So we add it to the exclude
187 # list explicitly here, just in case.
188 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" "-v" "$SSO_VERSION" "-x" "var/www/arvados-sso/current/.git" "-x" "var/www/arvados-sso/current/packages" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-sso-server-extras/postinst.sh")
190 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
191 # This is the complete package with vendor/bundle included.
192 # It's big, so we do not build it by default.
193 COMMAND_ARR+=("-n" "${PACKAGE_NAME}-with-bundle")
195 # The default package excludes vendor/bundle
196 COMMAND_ARR+=("-n" "${PACKAGE_NAME}" "-x" "var/www/arvados-sso/current/vendor/bundle")
199 # Append --depends X and other arguments specified by fpm-info.sh in
200 # the package source dir. These are added last so they can override
201 # the arguments added by this script.
202 declare -a fpm_args=()
203 declare -a fpm_depends=()
204 FPM_INFO="$WORKSPACE/fpm-info.sh"
205 if [[ -e "$FPM_INFO" ]]; then
206 debug_echo "Loading fpm overrides from $FPM_INFO"
210 for i in "${fpm_depends[@]}"; do
211 COMMAND_ARR+=('--depends' "$i")
213 COMMAND_ARR+=("${fpm_args[@]}")
214 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")
215 debug_echo -e "\n${COMMAND_ARR[@]}\n"
217 FPM_RESULTS=$("${COMMAND_ARR[@]}")
219 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
221 # SSO server package build done