LoginSignup
16
17

More than 5 years have passed since last update.

Docker をつかって Hubot の環境を整え、AWS で動かす

Posted at

Hubot 用の環境を Dockerfile にまとめ、ビルドしたものを Dockerhub においておけば、AWS にかぎらず docker が使えればどこでも同じ環境をモリモリ用意できるので、その手順をまとめておく。

Dockerfile

Hubotの環境に必要なものを Dockerfile に入れてく。

Dockerfile

FROM ubuntu:14.04
MAINTAINER keithyokoma

ENV HUBOT_SLACK_TOKEN your-slack-token

## install
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install git nodejs npm redis-server -y
RUN npm install -g coffee-script
RUN npm install -g hubot
RUN npm install --save hubot-slack
# replace nodejs to node
RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10

ビルド

Mac ならboot2dockerを使ってビルドし、DockerHub の private repo にプッシュする。


(client)      $ boot2docker ssh
(boot2docker) $ docker build .
(boot2docker) $ docker login
(boot2docker) $ docker push my_account/repo:latest

ビルドには時間がかかるのでじっくり待つ。

AWS

Amazon Linux なら、まずyumで docker をいれデーモン化し、DockerHub の private repo から pull してきてコンテナを起動する。名前をつけておくとあとでコンテナを起動したり止めたりが簡単になって良い。

コンテナを起動したら、コンテナにアタッチして入り、自分用の Hubot を GitHub などから取ってきて走らせ、Ctrl+pCtrl+qでコンテナから抜けて終わり。


(client)    $ ssh aws
(aws)       $ sudo yum update
(aws)       $ sudo yum install docker
(aws)       $ sudo service docker start
(aws)       $ sudo docker login
(aws)       $ sudo docker pull my_account/repo:latest
(aws)       $ sudo docker run -i -t --name HUBOT drivemode/hubot /bin/bash
(container) # exit
(aws)       $ sudo docker start HUBOT
(aws)       $ sudo docker attach HUBOT
(container) # git clone https://github.com/your_account/your_hubot
(container) # cd your_hubot
(container) # nohup ./bin/hubot -a slack > LOGFILE &
(container) # (Ctrl+p, Ctrl+q)
(aws)       $ exit

コンテナから抜けるとき、exitするとdocker start HUBOTで起動したコンテナが止まっちゃうので、Ctrl+pCtrl+qで抜けるようにする。そうするとコンテナは起動したままになる。

16
17
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
16
17