herokuでhubotをhipchatに
hipchatのユーザー制限がなくなったので、チャットをhipchatに移行した。hubotをherokuにて動かす作業をしていたら、思いのほか時間がかかってしまったのでそのとき対処した内容をメモに残しておきたいと思います。
※詳細な手順は以下記載しておりませんが、コマンド履歴はhttps://gist.github.com/honbin/64af90e4a5684c221deeに書いておきました。
! Push rejected, no Cedar-supported app detected
herokuへデプロイ時に上記エラーがでてあげられず、当該環境(Node.js)にて必要なファイルがない時に本エラーが起きるとのことだったので、https://devcenter.heroku.com/articles/getting-started-with-nodejsのマニュアルを確認。Node.jsのアプリとして認識するために、package.jsonが必要とのことなのでnpm install --save hubot-hipchatとせずに、package.jsonからライブラリをインストール。そして、node_modulesを.gitignoreに設定した。
$ npm init
$ vi package.json
{
"name": "hemhem",
"version": "0.0.1",
"private": true,
"description": "hemhem is my company's hubot",
"dependencies": {
"hubot": "*",
"hubot-scripts": "*",
"hubot-hipchat": "*"
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "honbin",
"license": "MIT"
}
$ npm install
$ vi .gitignore
node_modules
デプロイ完了後にheroku psにてプロセスを確認したところ、crashしてしまい動いていなかったのでheroku logsにてログを確認。
bash: bin/hubot: No such file or directory
PATH=vendor/node/bin:bin:node_modules/.bin:$PATHとheroku側でパスを通してくれているとのことだったので、Procfileを以下に修正。
vi Procfile bot: hubot -a hipchat -n hemhem
修正後にプロセスを確認したところ、またcrashしていたので再度ログを確認。
/usr/bin/env: coffee: No such file or directory
coffee-scriptを入れていなかったので、dependenciesに追加。
$ vi package.json
{
"name": "hemhem",
"version": "0.0.1",
"description": "hemhem is my company's hubot",
"dependencies": {
"hubot": "*",
"hubot-scripts": "*",
"hubot-hipchat": "*",
"coffee-script": "*"
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"author": "honbin",
"license": "MIT"
}
$ git push heroku master
$ heroku ps:scale bot=1
再度プロセスを確認し問題ないことを確認。hipchatにてhubot用に作成したアカウントからhttps://hipchat.com/account/xmppの情報を環境変数へセット。
$ heroku config:add HEROKU_URL=http://example.herokuapp.com $ heroku config:add HUBOT_HIPCHAT_JID="12345_12345@chat.hipchat.com" $ heroku config:add HUBOT_HIPCHAT_PASSWORD="password" $ heroku config:add HUBOT_HIPCHAT_ROOM="12345_hogehoge@conf.hipchat.com" $ heroku config:add TZ=Asia/Tokyo
※最後のタイムゾーン設定はhttps://github.com/miyagawa/hubot-cronを使いたかったため
$ mkdir scripts
$ vi scripts/ping.coffee
module.exports = (robot) ->
robot.respond /PING$/i, (msg) ->
msg.send 'PONG'

参考にさせて頂いたサイトm(_ _)m