Skip to content

Instantly share code, notes, and snippets.

@hermesespinola
Last active June 30, 2020 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermesespinola/8715e45cd0bb73a89b7cd907692a7afe to your computer and use it in GitHub Desktop.
Save hermesespinola/8715e45cd0bb73a89b7cd907692a7afe to your computer and use it in GitHub Desktop.
Simple script to deploy play application
#!/bin/bash
# Bash Version 3 required (it also works with ksh)
[[ ${BASH_VERSINFO[0]} -lt 3 ]] && exit 1
# Defaults
SECRET=secret
PORT=9000
# Put all arguments in a new array (because BASH_ARGV is read only)
ARGS=( "$@" )
for i in "${!ARGS[@]}"; do
case "${ARGS[i]}" in
'') # Skip if element is empty (happens when it's unsetted before)
continue
;;
-s|--secret) KEY="${ARGS[i+1]}"
unset 'ARGS[i+1]'
;;
-p|--port) PORT="${ARGS[i+1]}"
unset 'ARGS[i+1]'
;;
-c|--config) CONFIG="${ARGS[i+1]}"
unset 'ARGS[i+1]'
;;
--) # End of arguments
unset 'ARGS[i]'
break
;;
*) # Skip unset if our argument has not been matched
continue
;;
esac
unset 'ARGS[i]'
done
echo SECRET=$SECRET PORT=$PORT CONFIG=$CONFIG
# Kill a process in port $PORT
fuser -k $PORT/tcp
# delete previous production version
find ./target/universal/ -type d -name '*-SNAPSHOT' -exec rm -rf {} \;
# create production binary, created in ./target/universal
sbt dist
unzip ./target/universal/*.zip -d ./target/universal
rm -f ./target/universal/*.zip
if [ -z ${CONFIG+x} ]; then
$(find ./target/universal/ -type f -wholename '*-SNAPSHOT/bin/*' ! -name '*.bat') -Dplay.http.secret.key=$SECRET -D$
else
$(find ./target/universal/ -type f -wholename '*-SNAPSHOT/bin/*' ! -name '*.bat') -Dplay.http.secret.key=$SECRET -D$
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment