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; }
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
# 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
# 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!"