Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit c451398

Browse files
committed
Add deployment script
1 parent e099ef2 commit c451398

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

.deployment

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[config]
2+
command = bash deploy.sh

deploy.sh

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
3+
# ----------------------
4+
# KUDU Deployment Script
5+
# Version: 1.0.15
6+
# ----------------------
7+
8+
# Helpers
9+
# -------
10+
11+
exitWithMessageOnError () {
12+
if [ ! $? -eq 0 ]; then
13+
echo "An error has occurred during web site deployment."
14+
echo $1
15+
exit 1
16+
fi
17+
}
18+
19+
# Prerequisites
20+
# -------------
21+
22+
# Verify node.js installed
23+
hash node 2>/dev/null
24+
exitWithMessageOnError "Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment."
25+
26+
# Setup
27+
# -----
28+
29+
SCRIPT_DIR="${BASH_SOURCE[0]%\\*}"
30+
SCRIPT_DIR="${SCRIPT_DIR%/*}"
31+
ARTIFACTS=$SCRIPT_DIR/../artifacts
32+
KUDU_SYNC_CMD=${KUDU_SYNC_CMD//\"}
33+
34+
if [[ ! -n "$DEPLOYMENT_SOURCE" ]]; then
35+
DEPLOYMENT_SOURCE=$SCRIPT_DIR
36+
fi
37+
38+
if [[ ! -n "$NEXT_MANIFEST_PATH" ]]; then
39+
NEXT_MANIFEST_PATH=$ARTIFACTS/manifest
40+
41+
if [[ ! -n "$PREVIOUS_MANIFEST_PATH" ]]; then
42+
PREVIOUS_MANIFEST_PATH=$NEXT_MANIFEST_PATH
43+
fi
44+
fi
45+
46+
if [[ ! -n "$DEPLOYMENT_TARGET" ]]; then
47+
DEPLOYMENT_TARGET=$ARTIFACTS/wwwroot
48+
else
49+
KUDU_SERVICE=true
50+
fi
51+
52+
if [[ ! -n "$KUDU_SYNC_CMD" ]]; then
53+
# Install kudu sync
54+
echo Installing Kudu Sync
55+
npm install kudusync -g --silent
56+
exitWithMessageOnError "npm failed"
57+
58+
if [[ ! -n "$KUDU_SERVICE" ]]; then
59+
# In case we are running locally this is the correct location of kuduSync
60+
KUDU_SYNC_CMD=kuduSync
61+
else
62+
# In case we are running on kudu service this is the correct location of kuduSync
63+
KUDU_SYNC_CMD=$APPDATA/npm/node_modules/kuduSync/bin/kuduSync
64+
fi
65+
fi
66+
67+
# Node Helpers
68+
# ------------
69+
70+
selectNodeVersion () {
71+
if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
72+
SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
73+
eval $SELECT_NODE_VERSION
74+
exitWithMessageOnError "select node version failed"
75+
76+
if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
77+
NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
78+
exitWithMessageOnError "getting node version failed"
79+
fi
80+
81+
if [[ -e "$DEPLOYMENT_TEMP/__npmVersion.tmp" ]]; then
82+
NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"`
83+
exitWithMessageOnError "getting npm version failed"
84+
fi
85+
86+
if [[ ! -n "$NODE_EXE" ]]; then
87+
NODE_EXE=node
88+
fi
89+
90+
NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
91+
else
92+
NPM_CMD=npm
93+
NODE_EXE=node
94+
fi
95+
}
96+
97+
##################################################################################################################################
98+
# Deployment
99+
# ----------
100+
101+
echo Handling node.js deployment.
102+
103+
# 1. KuduSync
104+
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
105+
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
106+
exitWithMessageOnError "Kudu Sync failed"
107+
fi
108+
109+
# 2. Select node version
110+
selectNodeVersion
111+
112+
# 3. Install npm packages
113+
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
114+
cd "$DEPLOYMENT_TARGET"
115+
eval $NPM_CMD install --production
116+
exitWithMessageOnError "npm failed"
117+
cd - > /dev/null
118+
fi
119+
120+
# 4. Copy config-sample.js to config.js
121+
if [ -e "$DEPLOYMENT_TARGET/config-sample.js" ]; then
122+
cd "$DEPLOYMENT_TARGET"
123+
echo Creating config file...
124+
cp "config-sample.js" "config.js"
125+
cd - > /dev/null
126+
fi
127+
128+
##################################################################################################################################
129+
echo "Finished successfully."

0 commit comments

Comments
 (0)