Skip to content

Commit 51887b2

Browse files
committed
Deploy to Azure Button
* Uses ARM template to create a Web App (Free Tier) * When deploying, choose between `Latest` (deploys code from git repo) or `Stable` (deploy from latest published npm package). * Server will be accessible at `<sitename>.azurewebsites.net`
1 parent 6dac818 commit 51887b2

File tree

7 files changed

+377
-16
lines changed

7 files changed

+377
-16
lines changed

Readme.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Read more about the [motivations and history](http://rauchg.com/slackin) behind
2323

2424
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/rauchg/slackin/tree/0.7.3)
2525

26+
#### Azure
27+
28+
[![Deploy to Azure](http://azuredeploy.net/deploybutton.svg)](https://azuredeploy.net/)
29+
2630
#### OpenShift
2731

2832
[Follow these instructions.](https://github.com/rauchg/slackin/wiki/OpenShift)
@@ -133,8 +137,8 @@ install the prerequisite node libraries with npm:
133137
$ npm install
134138
```
135139

136-
After the libraries install, the postinstall script will run make to invoke
137-
babel on the source. It is important to run make manually after updating any
140+
After the libraries install, the postinstall script will run `gulp` to invoke
141+
babel on the source. It is important to run `gulp` manually after updating any
138142
files in lib/ to update the versions in node/.
139143

140144
## Credits

azuredeploy.json

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"siteName": {
6+
"type": "string",
7+
"metadata": {
8+
"description": "The name of the web app that you wish to create."
9+
}
10+
},
11+
"hostingPlanName": {
12+
"type": "string",
13+
"metadata": {
14+
"description": "The name of the App Service plan to use for hosting the web app."
15+
}
16+
},
17+
"siteLocation": {
18+
"type": "string",
19+
"defaultValue": "West US",
20+
"metadata": {
21+
"description": "The location to use for creating the web app and hosting plan. It must be one of the Azure locations that support web apps."
22+
}
23+
},
24+
"repoURL": {
25+
"type": "string"
26+
},
27+
"branch": {
28+
"type": "string"
29+
},
30+
"slackTeamId" : {
31+
"type": "string",
32+
"metadata": {
33+
"description": "Slack Team ID. (e.g. https://{this}.slack.com)"
34+
}
35+
},
36+
"slackApiToken" : {
37+
"type": "string",
38+
"metadata": {
39+
"description": "Slack API token (find it on https://api.slack.com/web)"
40+
}
41+
},
42+
"slackinRelease" : {
43+
"type": "string",
44+
"allowedValues": [
45+
"stable",
46+
"latest"
47+
],
48+
"defaultValue": "stable",
49+
"metadata": {
50+
"description": "Slackin Release to Deploy (stable/latest)"
51+
}
52+
}
53+
},
54+
"resources": [
55+
{
56+
"apiVersion": "2015-08-01",
57+
"name": "[parameters('hostingPlanName')]",
58+
"type": "Microsoft.Web/serverfarms",
59+
"location": "[parameters('siteLocation')]",
60+
"properties": {
61+
},
62+
"sku": {
63+
"name": "F1"
64+
}
65+
},
66+
{
67+
"apiVersion": "2015-08-01",
68+
"name": "[parameters('siteName')]",
69+
"type": "Microsoft.Web/sites",
70+
"location": "[parameters('siteLocation')]",
71+
"dependsOn": [
72+
"[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
73+
],
74+
"properties": {
75+
"serverFarmId": "[parameters('hostingPlanName')]"
76+
},
77+
"resources": [
78+
{
79+
"apiVersion": "2015-08-01",
80+
"name": "web",
81+
"type": "config",
82+
"dependsOn": [
83+
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
84+
],
85+
"properties": {
86+
"siteProperties": {
87+
"webSocketsEnabled": true
88+
}
89+
}
90+
},
91+
{
92+
"apiVersion": "2015-08-01",
93+
"name": "appsettings",
94+
"type": "config",
95+
"dependsOn": [
96+
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
97+
],
98+
"properties": {
99+
"SLACK_SUBDOMAIN": "[parameters('slackTeamId')]",
100+
"SLACK_API_TOKEN": "[parameters('slackApiToken')]",
101+
"SLACKIN_RELEASE": "[parameters('slackinRelease')]",
102+
"WEBSITE_NPM_DEFAULT_VERSION": "3.3.12",
103+
"WEBSITE_NODE_DEFAULT_VERSION": "5.1.1",
104+
"command": "bash scripts/azuredeploy.sh"
105+
}
106+
},
107+
{
108+
"apiVersion": "2015-08-01",
109+
"name": "web",
110+
"type": "sourcecontrols",
111+
"dependsOn": [
112+
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
113+
"[concat('Microsoft.Web/Sites/', parameters('siteName'), '/config/web')]"
114+
],
115+
"properties": {
116+
"RepoUrl": "[parameters('repoURL')]",
117+
"branch": "[parameters('branch')]",
118+
"IsManualIntegration": true
119+
}
120+
}
121+
]
122+
}
123+
],
124+
"outputs": {
125+
"siteUri": {
126+
"type": "string",
127+
"value": "[concat('https://',reference(resourceId('Microsoft.Web/sites', parameters('siteName'))).hostNames[0])]"
128+
}
129+
}
130+
}

bin/slackin

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
22

3-
var pkg = require('../package');
3+
var pkg = require('./../package');
44
var program = require('commander');
5-
var slackin = require('../node').default;
5+
var slackin = require('./../node').default;
66

77
program
88
.version(pkg.version)
99
.usage('[options] <team-id> <api-token>')
10-
.option('-p, --port <port>', 'Port to listen on [$PORT or 3000]', require('hostenv').PORT || 3000)
11-
.option('-h, --hostname <hostname>', 'Hostname to listen on [$HOSTNAME or 0.0.0.0]', require('hostenv').HOSTNAME || '0.0.0.0')
10+
.option('-p, --port <port>', 'Port to listen on [$PORT or 3000]', require('hostenv').PORT || process.env.PORT || 3000)
11+
.option('-h, --hostname <hostname>', 'Hostname to listen on [$HOSTNAME or 0.0.0.0]', require('hostenv').HOSTNAME || process.env.WEBSITE_HOSTNAME || '0.0.0.0')
1212
.option('-c, --channels [<chan>]', 'One or more comma-separated channel names to allow single-channel guests [$SLACK_CHANNELS]', process.env.SLACK_CHANNELS)
1313
.option('-c, --channel <chan>', 'Single channel guest invite (deprecated) [$SLACK_CHANNEL]', process.env.SLACK_CHANNEL)
1414
.option('-i, --interval <int>', 'How frequently (ms) to poll Slack [$SLACK_INTERVAL or 5000]', process.env.SLACK_INTERVAL || 5000)
@@ -18,11 +18,14 @@ program
1818
.option('-c, --css <file>', 'Full URL to a custom CSS file to use on the main page')
1919
.parse(process.argv);
2020

21-
if (program.args.length != 2) {
21+
var org = program.args[0] || process.env.SLACK_SUBDOMAIN;
22+
var token = program.args[1] || process.env.SLACK_API_TOKEN;
23+
24+
if (!org || !token) {
2225
program.help();
2326
} else {
24-
program.org = program.args[0];
25-
program.token = program.args[1];
27+
program.org = org;
28+
program.token = token;
2629
}
2730

2831
// support deprecated option

lib/log.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ export default function log(slack, silent){
3838
}
3939

4040
function out(...args){
41+
if (args) {
42+
args[0] = `${new Date}${args[0]}`;
43+
}
44+
4145
if (silent) return debug(...args);
42-
args[0] = `${new Date}${args[0]}`;
4346
console.log(...args);
4447
}
4548
}

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.7.3",
44
"description": "",
55
"dependencies": {
6-
"babel-core": "6.3.15",
6+
"babel-core": "6.3.26",
77
"babel-preset-es2015": "6.3.13",
88
"babel-polyfill": "6.3.14",
99
"body-parser": "1.10.2",
@@ -21,11 +21,6 @@
2121
"vd": "0.1.0"
2222
},
2323
"devDependencies": {
24-
"babel-core": "^6.3.15",
25-
"babel-preset-es2015": "^6.3.13",
26-
"gulp": "^3.9.0",
27-
"gulp-babel": "^6.1.1",
28-
"gulp-rimraf": "^0.2.0",
2924
"mocha": "2.2.4",
3025
"nock": "2.17.0",
3126
"supertest": "0.15.0"

scripts/azuredeploy.sh

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/bin/bash
2+
3+
# ----------------------
4+
# Azure KUDU Deployment Script
5+
# Version: 1.0.2
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+
# Node/NPM versions
71+
#NODE_EXE="$PROGRAMFILES\\nodejs\\5.1.1\\node.exe"
72+
#NPM_CMD="\"$NODE_EXE\" \"$PROGRAMFILES\\npm\\3.3.12\\node_modules\\npm\\bin\\npm-cli.js\""
73+
74+
selectNodeVersion () {
75+
if [[ -n "$KUDU_SELECT_NODE_VERSION_CMD" ]]; then
76+
SELECT_NODE_VERSION="$KUDU_SELECT_NODE_VERSION_CMD \"$DEPLOYMENT_SOURCE\" \"$DEPLOYMENT_TARGET\" \"$DEPLOYMENT_TEMP\""
77+
eval $SELECT_NODE_VERSION
78+
exitWithMessageOnError "select node version failed"
79+
80+
if [[ -e "$DEPLOYMENT_TEMP/__nodeVersion.tmp" ]]; then
81+
NODE_EXE=`cat "$DEPLOYMENT_TEMP/__nodeVersion.tmp"`
82+
exitWithMessageOnError "getting node version failed"
83+
fi
84+
85+
if [[ -e "$DEPLOYMENT_TEMP/.tmp" ]]; then
86+
NPM_JS_PATH=`cat "$DEPLOYMENT_TEMP/__npmVersion.tmp"`
87+
exitWithMessageOnError "getting npm version failed"
88+
fi
89+
90+
if [[ ! -n "$NODE_EXE" ]]; then
91+
NODE_EXE=node
92+
fi
93+
94+
NPM_CMD="\"$NODE_EXE\" \"$NPM_JS_PATH\""
95+
else
96+
NPM_CMD=npm
97+
NODE_EXE=node
98+
fi
99+
}
100+
101+
# Deployment
102+
# ----------
103+
104+
# Select node version
105+
selectNodeVersion
106+
107+
echo -n "Using Node: "
108+
"${NODE_EXE}" -v
109+
110+
echo -n "Using npm: "
111+
"${NPM_CMD}" -v
112+
113+
echo Deploying Slackin: $SLACKIN_RELEASE
114+
115+
if [[ "$SLACKIN_RELEASE" == "stable" ]]; then
116+
# Stable
117+
echo Installing from npm
118+
119+
cd "$DEPLOYMENT_TARGET"
120+
121+
# 1. Install latest release of slackin from npm
122+
eval $NPM_CMD install slackin
123+
124+
# 2. Copy to root folder
125+
cp -rv node_modules/slackin/* .
126+
127+
cd - > /dev/null
128+
129+
else
130+
# Latest (from git repo)
131+
echo Installing from git repo
132+
133+
# 1. KuduSync
134+
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
135+
"$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"
136+
exitWithMessageOnError "Kudu Sync failed"
137+
fi
138+
139+
# 2. Install npm packages
140+
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
141+
echo npm install
142+
cd "$DEPLOYMENT_TARGET"
143+
eval $NPM_CMD install --production
144+
cd - > /dev/null
145+
fi
146+
fi
147+
148+
149+
# Post deployment stub
150+
if [[ -n "$POST_DEPLOYMENT_ACTION" ]]; then
151+
POST_DEPLOYMENT_ACTION=${POST_DEPLOYMENT_ACTION//\"}
152+
cd "${POST_DEPLOYMENT_ACTION_DIR%\\*}"
153+
"$POST_DEPLOYMENT_ACTION"
154+
exitWithMessageOnError "post deployment action failed"
155+
fi
156+
157+
echo "Finished successfully."

0 commit comments

Comments
 (0)