Deploying Hubot to Heroku like a boss
Tuesday, November 01, 2011
What is Hubot?
Hubot was an almost mythical GitHub campfire bot. They use it for deploying, automate a lot of tasks, and to be a source of fun in the company. Was, because they open sourced it some time age.
Hubot & Heroku
When I decided to give hubot a try on Heroku I googled for it and found a few tutorials and blog posts. All of them advise to download (or clone) main hubot repository and deploy it to heroku. In may opinion this is not the best way to do it. This post describes how to create separated deployable hubot application.
Tools needed
You will need a ruby, git, node.js, npm and a heroku gem installed. Ruby and git is pretty common. You will install heroku gem by:
$ gem install heroku
then node.js with Homebrew
$ brew install node
and npm
$ curl http://npmjs.org/install.sh | sh
Things done locally
Clone hubot repository and create a new directory that will deployed to heroku.
$ git clone git://github.com/github/hubot.git
$ cd hubot
$ npm install # install all required dependencies
$ bin/hubot --create ../acmebot
If you go to the created directory you should see file structure similar to this:
$ cd ../acmebot
$ ls -l
~/www/blog/hubot/acmebot
total 32
-rw-r--r-- 1 martinciu staff 36 31 paź 21:28 Procfile
-rw-r--r-- 1 martinciu staff 3411 31 paź 21:28 README.md
drwxr-xr-x 3 martinciu staff 102 31 paź 21:28 bin
-rw-r--r-- 1 martinciu staff 56 31 paź 21:28 hubot-scripts.json
-rw-r--r-- 1 martinciu staff 518 31 paź 21:28 package.json
drwxr-xr-x 12 martinciu staff 408 31 paź 21:28 scripts
This will be your hubot application that you will deploy to heroku. First create a new git repository.
$ git init .
$ git add .
$ git commit -m "initial commit"
Now you can create a new heroku app.
$ heroku create acmebot --stack cedar
And now you can deploy your own hubot to heroku.
$ git push heroku
Heroku configuration
It is deployed, but hubot won’t join any campfire room because it doesn’t know anything about it. You have to tell him what room(s) should he go to. You can do it by heroku configuration variables.
# Campfire user's token. You can find it on user's profile pages.
# You should probably have additional campfire user for a hubot
$ heroku config:add HUBOT_CAMPFIRE_TOKEN=secret
# room ids coma-separated (you can find room id in room URL)
$ heroku config:add HUBOT_CAMPFIRE_ROOMS=123
# your campfire account subdoamin
$ heroku config:add HUBOT_CAMPFIRE_ACCOUNT="acme"
For some scripts Redis is required. You can add a free RedisToGo service by typing:
$ heroku addons:add redistogo:nano
All is set up. Now you can start hubot:
$ heroku ps:scale app=1
It’s alive!
Now if you go to you campfire room and type
$ Hubot help
you should get a list of commands that your Hubot is familiar with.
When it is not alive :/
If hubot doesn’t speak to you, it means that something went wrong. In that case you can check heroku logs by typing in console:
$ heroku logs
You can also check application status by typing:
$ heroku ps
More scripts
You have just deployed a basic hubot set up. If you want to add more commands you can find them on the hubot-scripts repository. It is already added to you your copy of hubot. To turn it on you should edit hubot-scripts.json file. It is simple JSON file with list of custom scripts that should be loaded. At the time of writing some of the scripts that are available in the hubot-scripts repository are not yet available on the npm. So if your hubot doesn’t start after adding some custom scripts, check it’s log files to see what scripts can’t be found.
Robot’s name
Hubot only talks to you if you call him by name. And it is a new of the user who’s token hubot uses. You can specify that name in the Procfile
app: bin/hubot --adapter campfire --name acmebot --enable-slash
And if you don’t want to talk to hubot by name you can add --enable-slash option. It will allow to replace robot’s name with /. Example:
/mustache me lady gaga
