105
104

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

社内でHipChatクローンのKandanとHubotを動かす

Posted at

企業内でチャットを使いたい、Hubotと連携させたい!けど、外のサービスを使っちゃダメ!ってことよくあるじゃないですか…

ってことで、サービスを利用せずにチャット環境を整える方法を調べてみました。

Kandan

kandan

KandanはOSSのHipChatクローンなチャットサービスです。Hubotと簡単に連携出来そうで、デザインもわりと良かったので採用してみました。

Cloud FoundryやHeorkuなどにデプロイすることも可能ですが、今回は自分でサーバを立ち上げます。(社内のそこらへんに転がってるサーバに入れましょう!)

Kandanのclone, checkout

最新のKandanだとdeviseなどのGemのバージョンが上がってしまい、うまく認証が機能しなかったので v1.2 時点のタグをチェックアウトし、進めていきます。

$ git clone https://github.com/kandanapp/kandan.git 
$ cd kandan
$ git checkout v1.2

依存ライブラリのインストール

$ sudo apt-get install ruby1.9.1-dev ruby-bundler libxslt-dev libxml2-dev libpq-dev libsqlite3-dev gcc g++ make nodejs
$ gem install execjs

手順簡略化の為、Database adapterをPostgreSQLからSQLiteに変更し、bundlerでGemをインストールします。
developmentとtestのGemは今回は不要なので、除いてインストールしました。

$ vim Gemfile
Gemfile
# Database adapters
-gem 'pg'
+# gem 'pg'
+gem 'sqlite3'
$ bundle install --without development test

DBはSQLiteを使うことにしたので、database.ymlに以下を追加します。

$ vim config/database.yml
database.yml
production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

DB作成

$ RAILS_ENV=production bundle exec rake db:create db:migrate kandan:bootstrap

プリコンパイル

特に手を加えていかないので true にしておきます。一度プリコンパイルしておくと動作が軽快です。(しないと重い…)

$ vim config/environments/production.rb
production.rb
# Disable Rails's static asset server (Apache or nginx will already do this)
-  config.serve_static_assets = false
+  config.serve_static_assets = true

プリコンパイル実施

$ RAILS_ENV=production bundle exec rake assets:precompile

Webサーバ起動

$ bundle exec thin start -e production

起動後、ユーザサインアップすると以下のように表示されます。ここまでで、チャットサービスは起動することができました。
ちなみに、管理者アカウントはデフォルトでAdmin、パスワードはkandanappadminです。

kandan.jpg

Hubotアカウント作成

KandanにHubotアカウントを作成し、Hubotと繋ぐためのアクセスキーを取得しておきます。

# Hubotアカウント作成
$ RAILS_ENV=production bundle exec rake kandan:boot_hubot
# アクセスキー取得
$ RAILS_ENV=production bundle exec rake kandan:hubot_access_key
Your hubot access key is YOUR_KANDAN_ACCESS_KEY

Hubot

HubotとKandanを繋げるのにhubot-kandanというKandan用アダプターを利用します。
手順はhubot-kandanのREADME.mdを参考に進めていきます。

Kandan用Hubot環境作成

Kandanと同様、最新のHubotではうまく動作しなかったので、v2.4.7のHubotを取得し環境を構築します。

$ wget https://github.com/github/hubot/archive/v2.4.7.zip
$ unzip v2.4.7.zip
$ cd hubot-2.4.7
$ npm install
$ make package

Kandan adapter

$ cd hubot
$ git clone https://github.com/kandanapp/hubot-kandan.git node_modules/hubot-kandan
$ npm install faye
$ npm install ntwitter

node_modules/hubot-kandan/package.json で Invalid version: "1.0" と怒られるので、1.0.0 に修正しておきましょう。

package.json
 {
   "name":        "hubot-kandan",
-  "version":     "1.0",
+  "version":     "1.0.0",
   "author":      "kandan",![hubot_connected.jpg](https://qiita-image-store.s3.amazonaws.com/0/6092/8725b8fd-9f25-08ec-9276-f7b6ae9c75dd.jpeg)

hubot-kandan用環境変数設定

export HUBOT_KANDAN_HOST=YOUR_KANDAN_HOST
# Portが80以外なら
export HUBOT_KANDAN_PORT=YOUR_KANDAN_PORT
# 上で取得したアクセスキー
export HUBOT_KANDAN_TOKEN=YOUR_KANDAN_ACCESS_KEY
# info以外に設定するなら
export HUBOT_LOG_LEVEL=debug

Hubot実行

adapterを指定して実行します。

$ ./bin/hubot -a kandan

先ほど起動したKandanにアクセスすると、Hubotがチャットに参加しているのが確認できます。
@hubot ping や、 hear が使われている ship it などを投稿し、Hubotが反応するか確認してみましょう。

hubot_connected.jpg

まとめ

外部サービスを利用せず、チャットサービスの立ち上げからHubotと連携するところまでをやってみました。最新バージョンだとうまく動かなかったので、今後に期待です。(結構デバッグしましたが、解決できませんでした…気が向いたらもう少し頑張ります)

せっかく環境を構築したので、Jenkinsとの連携なんかも次回あたりで書けたらと思います。

105
104
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
105
104

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?