LoginSignup
8
8

More than 5 years have passed since last update.

hubot-slackを使うDockerコンテナを作成するまでメモ

Last updated at Posted at 2015-01-01

hubot-xmppを使う場合の説明に対し、そもそも最新のhubot-slackで十分というご指摘をいただいた。実際楽だったので修正して再掲。
@mako0901さんありがとうございます。

制約等

  • herokuの代わりにローカルのCentOS 6.5で動かす
  • Slackのprivate groupでも使えるようにするため、adapterとして新しめのhubot-slackを使う

バージョン

以下で行っているが、バージョンの制約については未検証

  • Docker 1.3.2
  • nodebrew 0.7.5
  • node 0.10.35
  • npm 1.4.28
  • yo 1.3.3
  • coffee 1.8.0
  • hubot 2.11.0
  • hubot-slack 3.2.1

準備

  • Hubotのintegrationを追加する。ユーザー追加は不要。
  • bot名を指定し、HUBOT_SLACK_TOKENを取得しておく

Dockerfile

試行錯誤の結果以下のようになっている。

  • 変更の影響範囲を最小限にする意図で、node関連の作業はnon-rootユーザーのディレクトリで、npm installはグローバルインストールなしで行うようにしている。
  • hubotの作成はinteraction無視で自動にしている。yes | yo hubot --defaults
  • 以前と異なり、private groupにログインさせることができる。
FROM centos:centos6
RUN sed -i 's/mirrorlist=http/#mirrorlist=http/g'                                    /etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's!#baseurl=http://mirror.centos.org!baseurl=http://ftp.riken.jp/Linux!g' /etc/yum.repos.d/CentOS-Base.repo
RUN yum -y install which
RUN yum -y install perl
RUN yum -y install tar
RUN yum -y install gcc-c++
RUN yum -y install libicu-devel.x86_64
RUN useradd hubot


USER hubot
RUN mkdir /home/hubot/myslackbot
WORKDIR /home/hubot/myslackbot

RUN curl -k -L git.io/nodebrew | perl - setup
ENV PATH /home/hubot/.nodebrew/current/bin:$PATH
RUN nodebrew install v0.10.35
RUN nodebrew use 0.10.35
ENV PATH /home/hubot/myslackbot/node_modules/.bin:$PATH

RUN npm install  generator-hubot
RUN npm install  yo
RUN npm install  coffee-script
RUN npm install  hubot
RUN npm install  hubot-slack

RUN yes | yo hubot --defaults

ENV HUBOT_LOG_LEVEL     debug

#https://TEAM.slack.com/services
ENV HUBOT_SLACK_TOKEN xxxx-XXXXXXXXXXXXXXXXXXXXXXXXXXXX
RUN hubot -a slack

これをdocker build .する。

対話

/inviteして<botname> echo happy new yearとか打ってみる。

HUBOT_LOG_LEVELdebugにしていると、docker logs CONTAINERIDなどでdebug logが見られる。単純ではあるが、adapterが受け取った文字列がscriptに渡されて正規表現マッチさせている様子がわかる。

[Wed Dec 24 2014 11:41:33 GMT+0000 (GMT)] DEBUG Received message: 'satodabot echo happy new year' in channel: gt, from: satoda
[Wed Dec 24 2014 11:41:33 GMT+0000 (GMT)] DEBUG Message 'satodabot echo happy new year' matched regex //^\s*[@]?satodabot[:,]?\s*(?:ECHO (.*)$)/i/
[Wed Dec 24 2014 11:41:33 GMT+0000 (GMT)] DEBUG Sending to gt: happy new year

検証パスした事項

  • package.jsonを外からADDするようにしてもいいかもしれないが、うまくできなかった(いずれにしてもyo hubotが必要?)
  • (hubot関係ないけど)yumのrepository指定は外してもよいかも

宿題

  • 接続・プロセス管理、デーモン化
  • hubot logにredisとかherokuのエラーやメッセージが出ているので、使わなくするか、エラーが出ないようにする
8
8
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
8
8