SlackサービスとTrelloサービスの連携でタスク起票を楽に! -デプロイ編-
本章では、前章に引き続き、デプロイ作業について解説していきます。kikki.hatenablog.com
※注意
本章では、AzureのWebAppsサービスにデプロイする前提で作業を進めていきます。
Azureの設定
Azure Cross-Platform Command-Line Interface
CUIでAzureを操作するために、Azureのターミナルツールをインストールします。
sudo npm install -g azure-cli
不要なパッケージの削除
Hubotでは、Herokuにデプロイする前提のパッケージが盛り込まれています。しかし本章では、Azure上にデプロイするため、Azureに不要なパッケージを削除します。
npm uninstall hubot-heroku-keepalive --save npm uninstall hubot-redis-brain --save rm Procfile
また今回は、HerokuやRedisを使用しないため、以下の項目を削除します。
[external-scripts.json]
// 以下の二項目を削除する "hubot-heroku-keepalive", "hubot-redis-brain",
Hubot実行環境の設定
WebAppsで、hubotが実行されるようファイルを追加します。
[server.js]
require('coffee-script/register'); module.exports = require('hubot/bin/hubot.coffee');
Hubotの呼び出し処理を調整します。
[./bin/hubot_child]
var exec = require('child_process').exec; var fs = require('fs'); exec('node_modules/.bin/hubot --name "hubot" "$@"', function(error, stdout, stderr){ if(stdout) fs.writeFile('errorLog.txt', 'stdout: ' + stdout, function(err){}); if(stderr) fs.writeFile('errorLog.txt', 'stderr: ' + stderr, function(err){}); fs.writeFile('errorLog.txt', 'error: ' + error, function(err){}); });
そして以下の記述を「package.json」ファイルに追加します。
[package.json]
"scripts": { "start": "node ./bin/hubot_child" },
以下の処理を「# 3. Install npm packages」ブロックの後に追記します。
[deploy.sh]
# 4. Create Hubot file with coffee extension cp "$DEPLOYMENT_TARGET/node_modules/hubot/bin/hubot" "$DEPLOYMENT_TARGET/node_modules/hubot/bin/hubot.coffee"
gitにpush
git情報を更新します。
git init git add . git commit -m "Initial commit"
Deploy
アカウント情報の設定
Azureのアカウント情報を設定します。
azure account download azure account import 【上記でダウンロードしたpublishsettingsファイルのパス】
Azure上にWebAppsを作成
WebAppsにWebサイトを作成します。
azure site create 【サイト名】 --git
デプロイ先の設定
デプロイ先の設定をします。
git remote add azure https://【ユーザ名】@【サイト名】.scm.azurewebsites.net:443/【サイト名】.git
WebAppsに環境値を設定
HubotをSlackで利用する上で必須なパラメータをWebApps上に設定します。
azure site appsetting add HUBOT_SLACK_TOKEN=【SlackのToken】 azure site appsetting add HUBOT_ADAPTER=slack azure site deploymentscript --node
Deploy
最後にデプロイします。
git push azure master
これで、ローカル環境でHubotを実行しなくとも、HubotとSlackを連携させたサービスを利用できるようになります。
筆休め
本章では、SlackサービスとTrelloサービスを連携させるために、Hubotを用いたBotサーバーを準備しました。次章では、Trelloへの設定を紹介します。
以上、「SlackサービスとTrelloサービスの連携でタスク起票を楽に! -デプロイ編-」でした。