ChatOps is a term that refers to conversation-driven development. What that means is the ability to perform development tasks such as deployments from a chatting window by interacting with a chat bot to interpret and orchestrate such commands for you. In this tutorial, we are going to demonstrate how to implement GitHub deployments in scriptr.io using the open source Hubot chat bot.
Prerequisites
- Install Hubot
- Install the GTalk adapter for Hubot from https://github.com/atmos/hubot-gtalk
- Install the Hubot GitHub deployments module from hubot-github-deployments
Hubot
Hubot is an internal automation assistant developed by GitHub. Although it only comes with a few functions out of the box, it is an extensible and scriptable bot. There are hundreds of scripts written and maintained by the community and it’s easy to write your own and customize like we’re going to do in this tutorial.
Installing Hubot
You will need node.js and npm. Once those are installed, you can install the Hubot generator:
- npm install -g yo generator-hubot
git pull https://github.com/atmos/hubot-deploy.git
#pull the hubot-deploy from github using- cd hubot-deploy-master/
npm update * npm install
Next, from your home directory create a new directory using mkdir and switch to this directory. Then execute the following:
- run
yo hubot
inside this directory - proceed with the installation process by adding the needed answers in order to test the installation
- execute
bin/hubot
from the created directory.
Troubleshooting
If you got an error like this:
ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL
Try the following steps to fix:
cd <your-hubot-project-dir>
\npm uninstall hubot-heroku-keepalive --save\
- edit “external-scripts.json” and remove “hubot-heroku-keepalive”
Installing the GTalk Adapter
After making sure that Hubot is installed, you need to install the GTalk adapter. GTalk is the Jabber-based instant messaging service provided by Google. You should report any issues or submit pull requests to the GTalk adapter repository.
You will need to edit the package.json
file for your Hubot and add the hubot-gtalk
adapter dependency.
"dependencies": { "hubot-gtalk": ">= 0.0.1", "hubot": ">= 2.0.0", ... }
Save the file, and commit the changes to your Hubot’s GitHub repository.
If you’re deploying to Heroku, you will need to edit the Procfile
and change the -a campfire
option to -a gtalk
. If you’re deploying locally, however, you will need to use -a gtalk
when running Hubot.
Now launch Hubot using bin/hubot -gtalk
.
In some cases the system will generate an error saying that the node-stringprep is not installed, in which case you can install it using:
yo install node-stringprep using npm install node-stringprep
Configuring the GTalk Adapter
The GTalk adapter requires only the following environment variables:
HUBOT_GTALK_USERNAME
: the username (email) of the account that Hubot will use to connect to GTalk.HUBOT_GTALK_PASSWORD
: the password of the account that Hubot will use to connect to GTalk.
Testing GTalk
In order to test the GTalk installation:
- Uncomment these 2 lines in “scripts/example.coffee”
- robot.hear /badger/i, (res) ->
- res.send “Badgers? BADGERS? WE DON’T NEED NO STINKIN BADGERS
- Send a chat message to the robot email containing the word “badger”. You should get this reply:
“Badgers? BADGERS? WE DON’T NEED NO STINKIN BADGERS”
Hubot GitHub Deployments
This module allows you to create payloads to send to the GitHub Deployment API, then check the status of the deployments. Combined with a deployment tool that listens to organizational or repository DeploymentEvent webhooks, this module can help automate this process via ChatOps.
Installation
In your Hubot repository, run:
npm install hubot-github-deployments --save
Then add hubot-github-deployments to your external-scripts.json
file:
["hubot-github-deployments"]
You must update line 111 in “/node_modules/hubot-github-deployments/src/hubot-github-deployments.coffee” and remove the “.toLowerCase()” because GTalk does not support the concept of rooms like other chat tools.
Configuration
Type the following in the console:
export HUBOT_GITHUB_TOKEN=xxx
export HUBOT_GITHUB_USER=xxx
export HUBOT_GITHUB_DEPLOY_TARGETS=production
export HUBOT_GITHUB_REPO=user/repo
Chat Commands
Now that you’re done, you can send the following commands from the GTalk chat window:
deploy status
– List the statuses of most recent deployments.deploy status <id>
– List the status of a particular deployment.deploy list targets
– List available deployment targets.deploy list branches <search>
– List available branches, filtered by an optional search term.deploy <branch or SHA> to <server>
– Creates a GitHub deployment of a branch/SHA to a server.