public
Last active

  • Download Gist
glennblock revised this gist . 1 changed file with 25 additions and 15 deletions. View gist @ dea03c5
deploy.sh
40 
... 19 20 21 22 23 24 25 26   27 28 29 ... 19 20 21           22 23 24 25
@@ -19,11 +19,7 @@ exitWithMessageOnError () {
# -------------
# Verify node.js installed
-# gb: incorrect, should be what is below:
-# gb: where node &> /dev/null
-hash node 2>/dev/null
-
-
+hash node 2> /dev/null
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."
# Setup
... 53 54 55                                 56 57     58 59 60 ... 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
@@ -53,8 +49,26 @@ if [[ ! -n "$KUDU_SYNC_COMMAND" ]]; then
KUDU_SYNC_COMMAND="kuduSync"
fi
+# gb: add logic to install mocha
+if [[ ! -n "$MOCHA_COMMAND" ]]; then
+ # Install mocha
+ echo Installing mocha
+ npm install mocha -g --silent
+ exitWithMessageOnError "npm failed"
+
+ MOCHA_COMMAND="$APPDATA\\npm\\node_modules\\mocha\\bin\\mocha"
+fi
+
+# gb: npm install moved to happen BEFORE the deployment step instead of after
+# 2. Install npm packages
+npm install --production --silent
+exitWithMessageOnError "npm failed"
+cd - > /dev/null
+
if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
+ # gb: If running locally just set to call mocha directly
+ MOCHA_COMMAND="mocha"
else
# In case we are running on kudu service this is the correct location of kuduSync
KUDU_SYNC_COMMAND="$APPDATA\\npm\\node_modules\\kuduSync\\bin\\kuduSync"
... 63 64 65 66 67 68 69             70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 ... 77 78 79   80 81   82 83 84 85 86 87 88 89 90 91               92 93 94 95 96  
@@ -63,24 +77,20 @@ fi
##################################################################################################################################
# Deployment
# ----------
-
echo Handling node.js deployment.
-# 1. KuduSync
+# 1. gb: Run the tests!
+echo Running unit tests
+$MOCHA_COMMAND
+exitWithMessageOnError "Unit tests failed"
+
+# 2. KuduSync
echo Kudu Sync from "$DEPLOYMENT_SOURCE" to "$DEPLOYMENT_TARGET"
$KUDU_SYNC_COMMAND -q -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.deployment;deploy.sh" 2> /dev/null
exitWithMessageOnError "Kudu Sync failed"
-# 2. Install npm packages
-if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
- cd "$DEPLOYMENT_TARGET"
- npm install --production --silent
- exitWithMessageOnError "npm failed"
- cd - > /dev/null
-fi
##################################################################################################################################
echo "Finished successfully."
-
glennblock created this gist . View gist @ 65b70ec
deploy.sh
86 
...                                                                                                                                                                             ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
@@ -0,0 +1,86 @@
+#!/bin/bash
+
+# ----------------------
+# KUDU Deployment Script
+# ----------------------
+
+# Helpers
+# -------
+
+exitWithMessageOnError () {
+ if [ ! $? -eq 0 ]; then
+ echo "An error has occured during web site deployment."
+ echo $1
+ exit 1
+ fi
+}
+
+# Prerequisites
+# -------------
+
+# Verify node.js installed
+# gb: incorrect, should be what is below:
+# gb: where node &> /dev/null
+hash node 2>/dev/null
+
+
+exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."
+
+# Setup
+# -----
+
+SCRIPT_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+ARTIFACTS=$SCRIPT_DIR/artifacts
+
+if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
+ DEPLOYMENT_SOURCE=$SCRIPT_DIR
+fi
+
+if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
+ NEXT_MANIFEST_PATH=$ARTIFACTS/manifest
+
+ if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
+ PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
+ fi
+fi
+
+if [[ ! -n "$KUDU_SYNC_COMMAND" ]]; then
+ # Install kudu sync
+ echo Installing Kudu Sync
+ npm install kudusync -g --silent
+ exitWithMessageOnError "npm failed"
+
+ KUDU_SYNC_COMMAND="kuduSync"
+fi
+
+if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
+ DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
+else
+ # In case we are running on kudu service this is the correct location of kuduSync
+ KUDU_SYNC_COMMAND="$APPDATA\\npm\\node_modules\\kuduSync\\bin\\kuduSync"
+fi
+
+##################################################################################################################################
+# Deployment
+# ----------
+
+echo Handling node.js deployment.
+
+# 1. KuduSync
+echo Kudu Sync from "$DEPLOYMENT_SOURCE" to "$DEPLOYMENT_TARGET"
+$KUDU_SYNC_COMMAND -q -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.deployment;deploy.sh" 2> /dev/null
+exitWithMessageOnError "Kudu Sync failed"
+
+# 2. Install npm packages
+if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
+ cd "$DEPLOYMENT_TARGET"
+ npm install --production --silent
+ exitWithMessageOnError "npm failed"
+ cd - > /dev/null
+fi
+
+##################################################################################################################################
+
+echo "Finished successfully."
+
+
Something went wrong with that request. Please try again.