Github, Travis CI and Heroku Platform

The Project

We wanted to start a small project that will improve how we organize ourselves at work and ultimately enhance our workflows as a team, and we wanted to do it open source.

This project consists in an iPhone app, a small website and web API for communication between the different components of the system. We need to figure out what technologies to use and how to integrate them. We are experienced C# / .NET developers, so it makes sense to us to go with the Microsoft platform; however, we chose to do something different from what we do every day at work, so we go Scala and Play for the web and Swift for the iPhone application.

Team Collaboration

The first thing we need to do is set up the collaboration tools we, as a team, are going to use. Specially to share the code so we all can code on our own time without any limitations. Github is our perfect choice since it provides a Web-based graphical interface. It also provides access control and several collaboration features, such as a wikis and basic task management tools for every project. The only problem is that we are limited to have our code open to everyone, but part of our initiative is exactly that, so you could contribute if you like it. A quick git tutorial can be found here.

On the other hand, we need a message platform so we can communicate and collaborate easily. Slack lets us collaborate without any difficulties and after some time using it we have not found anything better, so far. More info about Slack can be found here.

The Language and Framework

We have been using Scala for data processing for some time now and we wanted to do more with it. Play, on the other hand, seems to be quite advance in the web engines world, and it supports Scala as a language. We just found our perfect combination!

Continuous Integration

Now that we have created the Github Repository for our code, we need to be able to compile and test our application automatically, without human intervention. Travis CI has a perfect integration with Github, and adding projects to be built in Travis is just a matter of connecting your Github account to Travis. Then you will be able to add any project you have on Github to be compiled.

There is a catch when using Travis, we need to define a .yml file to define the build process. The .yml file is like a MSBuil or NAnt file, but the syntax is far more easy.

Let’s take a look at how this file looks like

language: scala

scala:

- 2.10.4

- 2.11.7

branches:

only:

- master

notifications:

email:

recipients:

- SomeEmail@gmail.com

jdk:

- oraclejdk7

- oraclejdk8

As we can see here, we can build the project against two different versions of Scala while building only the master branch from our code repository. There is a section for notification and the different Java platforms we want to use. The .yml is very customizable, but it is simple to use and Travis documentation is quite extensive.

When using Scala projects, Travis will use sbt test by default to run our test suit but it can be configured as well if we want to do some custom steps.

Travis offers build status integration so we can add the status of our build directly into Github. Everyone will be able to see the build status in our project’s main page on Github. Something like this will be shown.

Deployment Platform

We selected Heroku as our deployment platform based on the simplicity it offers. It gives us the ability to deploy Scala application with no efforts at all. We can add plugins for databases such as PostgresQL and business intelligence and application insight tools like Sumo Logic.

Heroku lets us have a free container that even though is not production ready, we can use it for testing the basics of our application (Our Development Environment) and then we can promote the application to production ready containers for $7 a month. The smallest container is more than enough for what we want, so Heroku complies with our requirements and our low budget.

We want to automate deployments to Heroku, but it already has these capabilities built in. Heroku can pull our code from Github every time we push changes, then it will build our code and deploy it, but wait!, we are doing the same with Travis CI, so why we want to do it again? We don’t.

We could only use Github-Heroku integration, but if at some point we want to change to a different platform to run our application, then we will have no build tool to use. We want to keep our build tool and our deployment platform independent from each other even when Heroku has some of the Travis CI capabilities. Because of this, we did not investigate further, but in our initial research we did not find a way to run the test suit before deploying within Heroku, yet there should be a way. Anyways, Travis CI is specialized in building projects, so let’s stick to it for now.

Automated Workflow

We have seen that every time we push code to our Github repository Travis CI pick that code up (pull) and build and test our code automatically while updating the status of the build in Github. However, we also want to deploy our code every time it changes.

Some people will argue about this, but we believe that our code, which is built using Test Driven Development (TDD), should be deployable all the time. We should be able to deploy even when particular features are not ready and have to be toggled off. We, as a small DevOps group, find a high amount of value on Continuous Deployment and we can implement it using the tools we have chosen.

Let’s take a look how to integrate Travis CI and Heroku in order to get to our goal.

First, we need to install the Travis CLI, here is how. Second, we need to install the Heroku tools, which can be achieve by following this tutorial.

After we have installed these tools, we need to generate a Heroku key that allows us to integrate with the Heroku API. Generating the key is just matter of running

travis encrypt $(heroku auth:token) --add deploy.api_key

in the directory of our project. The command will add the following segment to our .yml

deploy:

provider: heroku

api_key:

secure: some key.....

Now, we could just commit, and push our code to Github, then Travis CI will compile it, test it and deploy it to Heroku. In our case, we wanted a different application name from the name our project has, so we added the following section to the .yml file.

app: my-heroku-app-name

iOS Application

Travis CI supports iOS builds. We only need to add these sections to the iOS .yml file.

language: objective-c xcode_project: my-app.xcodeproj

xcode_scheme: my-appTests

osx_image: beta-xcode6.3

xcode_sdk: iphonesimulator8.3 script:

- xcodebuild test -project my-app.xcodeproj -scheme my-appTests

Here is some info about configuring the Apple certificates and profile.

Endings

We have spent some time configuring all this integration and automated workflow, but they totally worth the time. This is a one time process that almost never changes, unless the project structure changes which rarely happens. However, the next time anything changes in our code, that change will go all the way to production without human intervention, which ultimately will accelerate our release cycles.

We believe that this process should be implemented even before the first line of code gets written and the value we find in the process overcome the work in configuring it. We have seen how manual deployments get messed up because people make mistakes. The automation process removes these mistakes and guarantee its repeatability. The continuos deployment lets us test the process itself. Even when we are not putting anything new in production, we are still testing the deployment process.

We hope that the processes we just described will help you to understand how to integrate different tools that can get you to your goals faster and easier as they have helped us.