Fixing deploy.sh so that it works on labs
authorAndrew Otto <acotto@gmail.com>
Wed, 18 Apr 2012 20:03:17 +0000 (16:03 -0400)
committerAndrew Otto <acotto@gmail.com>
Wed, 18 Apr 2012 20:03:17 +0000 (16:03 -0400)
deploy.sh

index 1c626e2..3c014f0 100755 (executable)
--- a/deploy.sh
+++ b/deploy.sh
@@ -9,9 +9,10 @@ set -e
 
 VERBOSE='-v'
 KRAKEN_DEV_HOST="${KRAKEN_DEV_HOST:-localhost:8081}"
-KRAKEN_DEPLOY_HOST="${KRAKEN_DEPLOY_HOST:-wmf@less.ly}"
-KRAKEN_DEPLOY_PATH="${KRAKEN_DEPLOY_PATH:-projects/kraken-ui/}"
-
+KRAKEN_DEPLOY_HOST="${KRAKEN_DEPLOY_HOST:-reportcard2.pmtpa.wmflabs}"
+KRAKEN_DEPLOY_PATH="${KRAKEN_DEPLOY_PATH:-/srv/reportcard/kraken-ui/}"
+KRAKEN_DEPLOY_USER="www-data"
+KRAKEN_DEPLOY_GROUP="www"
 
 # Utilities
 log () { [ "x$VERBOSE" != 'x' ] && echo -e "$*" >&2; }
@@ -21,6 +22,8 @@ count () { echo $#; }
 nth   () { local n="$1"; shift; [ -z "$n" ] && return 1; [[ "$n" < 0 ]] && n=$(( 1 + $# + $n )); echo "${!n}"; }
 join  () { local sep="$1" old="$IFS"; export IFS=\n; read -t1 out; while read -t1 line; do out="$out$sep$line"; done; echo "$out"; export IFS=$old; }
 
+# makes sure everything is owned by 
+fix_permissions () { echo "Fixing permissions on $KRAKEN_DEPLOY_HOST:$KRAKEN_DEPLOY_PATH"; ssh -t $KRAKEN_DEPLOY_HOST "/usr/bin/sudo /bin/chmod --changes -R g+w $KRAKEN_DEPLOY_PATH && /usr/bin/sudo /bin/chown --changes -R $KRAKEN_DEPLOY_USER:$KRAKEN_DEPLOY_GROUP $KRAKEN_DEPLOY_PATH"; }
 
 # Ensure gitrev is up to date
 coke update_version
@@ -59,10 +62,11 @@ log "ok!"
 
 # Build App JS Bundle
 target=tmp/dist/js/kraken/app-bundle
+uglifyjs=$(which uglifyjs || echo "node_modules/uglify-js/bin/uglifyjs")
 log "Building App JS Bundle (${target}.js) ..."
 log "cat \n$(coke source_list | grep -v vendor | sed 's/^/    var/')"
 cat $(coke source_list | grep -v vendor | sed 's/^/var/') > ${target}.js
-uglifyjs < ${target}.js > ${target}.min.js
+$uglifyjs < ${target}.js > ${target}.min.js
 log "ok!"
 
 # TODO: bundle CSS
@@ -70,10 +74,19 @@ log "ok!"
 
 # Finally, deploy the files
 log "Deploying files..."
+# fix ownership and permissions before and after rsync.
+fix_permissions
 log "rsync -Caz $VERBOSE --progress tmp/dist $KRAKEN_DEPLOY_HOST:$KRAKEN_DEPLOY_PATH"
-rsync -Caz $VERBOSE --progress tmp/dist $KRAKEN_DEPLOY_HOST:$KRAKEN_DEPLOY_PATH
+rsync -Crz $VERBOSE --progress tmp/dist $KRAKEN_DEPLOY_HOST:$KRAKEN_DEPLOY_PATH
+fix_permissions
 log "ok!"
 
+echo -n "Restart reportcard server? [y/n] "
+read answer
+if [ $answer == 'y' ]; then
+       ssh -t $KRAKEN_DEPLOY_HOST "sudo supervisorctl restart reportcard"
+fi
+
 log "Done!"