Hubot, Slack and Azure deployments – Part 1

I’m aiming at doing this a multipart series (this being the first part). I will update this intro with links to the follow up posts as I publish them.

Intro

We just pulled off our first hackday with the tech-team at acast. I set out to get GitHub’s open source robot Hubot to integrate with our Slack chat (a guerrilla warfare move on my part to move us from HipChat to Slack :), next I’ll tackle the tabs vs spaces issue). This post is a step by step account for how I did it.

The Goal

Deploy our projects to azure from the chat tool to:
1. Lower the barrier of deployment
2. Increase transparency and to use the chat as a information radiator (”Niklas is now deploying the rss-service”)

Doin’ it

Enabled Hubot integration in Slack

I logged into slack.com, went to *Configure Integrations* and enabled Hubot, giving the hubot user name, in our case abot.

Getting an instance of Hubot up and running

Now Slack is ready and we need an instance of Hubot running to do our biddings. I chose to put it on Heroku because of the simplicity and the good tutorials. I will be looking at setting it up on Azure WebSites later on.

In broad strokes I followed the Getting started with Hubot tutorial.

First let’s get our local environment in order (Caveat: I did this on Mac OS X and I haven’t tested it on Windows yet). Start by installing yeoman and a hubot generator.

In the wizard I entered `slack` as adapter. I don’t think that matter in this stage. It can be configured in the Procfile (see further down in this post). But we still needed to install the adapter for slack to test it later on:

If `node_modules` is not entered in the .gitignore file, it can be wise to add it. Now we’re ready for our first commit:


If you want to you can start a local redis for dev purposes. I don’t think that is needed. Let’s try if we’ve done everything correctly. Kick it off locally.

To the Cloud

So we’re running locally. Nice! Now let’s see if we can push it up to Heroku.

First up we need to crete a Heroku app. You need Heroku Toolbelt installed and a account on Heroku to do this. Let’s get cracking creating the app:

Log in first:

Next up, create the app. The –region parameter is not needed. If we don’t enter it we end up in the US which isn’t what I wanted :). The commands below also renames the site after creating it, not necessary.

Alright, we got a repo and we got an app. Now we need to push up some configuration to the app before pushing up the code. Since we’re using the slack adapter in this post we need to add config for it. This is documenteed in the Slackbot on Heroku article. In the code below, replace the value of the HUBOT_SLACK_TOKEN with the token we got when enabling the Slack integration on Slack.com.

For Hubot to persist it needs a brain. It’s brain is a Redis instance. We need to add it if we want persistence. I opted for the Heroku Redis addon Redistogo (it’s free in the nano version).

One last thing before we’re ready to give it a spin. Heroku work using a file called a Procfile which defines how it should start the app pushed to it. We just need to make sure it looks good. Should look something like this:

Where “botname” should be same as entered in the slack integration.

Now, let’s see if it flyes:

It works! For me it did anyway. I waited a little while with my eyes pealed at my Slack client and loe and behold if the user abot (in my case) got a green dot next to it. We can the spark up a private chat with it and say “help” or “ship it” or other extremely useful stuff.

So first part done! In the next post we’ll look at how to trigger TeamCity builds from the chat.

One thought on “Hubot, Slack and Azure deployments – Part 1

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *