As you saw in Part 1 of this howto we now have a GitHub Hubot up and running on CloudFoundry, pretty cool! But let’s see if we can manage it in a more automated way, how about automatically deploying a new version of it as soon as we push our code up to GitHub? Sounds good? Cool, lets’ do it.
For this we’re gonna be using Travis CI, a CI/CD system that can automatically test your code and see if it works or not, mark it as “passing” or show errors, and if everything’s A-OK then deploy it somewhere or spit out an artifact. Since we all never do mistakes this is gonna work from the beginning, hopefully :)
First, put your stuff up on GitHub. I’ve created a repo for the bot we’re using currently at EMC {code}, have a look at it if you’d like. Once it’s there, sign in to Travis CI with your Github account, and you’ll see something like this:
Enable the repo to monitored by Travis and let’s get started with enabling Travis support in your repo. It’s pretty simple, all you need is a file called .travis.yml in the root of your Hubot folder, and it should look something like this:
language: node_js node_js: - '0.10' notifications: email: false
We’re now telling Travis that our code is using nodejs and we’re specifying the version we want to use to check if everything works. We’re also disabling email notifications as they can get a bit annoying after a while, but that’s entire up to you if you want to leave out.
Now push your changes to your GitHub repo and watch as Travis does it’s magic. Sometimes it takes a few minutes for it to show up but don’t worry, it will be taking care of your code rather soon.
Alright, time to add another piece; the deployment to CloudFoundry. Since you already have the code up on GitHub there’s no need to push to CF from your local dev environment anymore! Let’s add some stuff to the .travis.yml file:
language: node_js node_js: - '0.10' notifications: email: false deploy: provider: cloudfoundry api: https://api.run.pivotal.io username: secure: yoursecuredusername password: secure: yoursecuredpassword organization: yourorg space: development on: repo: yourname/codebot branch: master
Deployment info added, but what is that “secure” part? It’s a really cool part of Travis, you can store secure information such as credentials and environment variables in the .travis.yml file in a way so they can’t be read by anyone else than the Travis CI system, making it very useful when storing stuff up on GitHub.
To create your own secured information strings, install the travis gem:
gem install travis
Now you can encrypt whatever you want:
$ travis encrypt somethingsecretlikeyourusernameorpassword Please add the following to your .travis.yml file: secure: "FonSR3cMHrGW2WZajEWOBuaBwTmzsvXZf8rOrGE6G070fZwZwq6JZH36M6VJWB4G9m35Y9JhFW/zL7uspm0wslF9LpztepEgc2HgAKnvICT1F6yx0Awo9kdEvkpBiWlI6JVS1fMbwbQG5309/qAIevMb4doJR8sP3jt8LfA4KkI="
Make sure you encrypt all sensitive information you want to before you store it up on GitHub, ok?
We’re now gonna add the last piece of the puzzle, a manifest.yml file that’s necessary for CloudFoundry to understand what we’re deploying:
$ cat manifest.yml --- applications: - name: codebot memory: 256M no-route: true
Here we define the name of the app (codebot), the amount of RAM we want to allocate to it, and that we don’t need a CloudFoundry route to it (if you had issues in Part 1 because of your botname here’s how you fix it!).
Now, when you’re done with all the copy&pasting and the encrypting, push the changes up to GitHub again and hopefully you should see your Hubot come alive on CloudFoundry automagically! You’re awesome, now go have fun with your automated build environment and your awesome bot :)
