Deploy from github to heroku via travis-ci

Posted: 2014-01-20

A small test of using travis-ci to build a github project and auto deploy it to heroku.

Step 1 - A webapp

Create your webapp. For this I created a simple hello world webapp (1 jsp) with a dummy test (just to give travis-ci something to do).

Commit on github for this step

Step 2 - CI

Let's add that to travis.

  • Head to Travis and log in with github oauth.
  • Click on your logged in account name and choose Accounts
  • Hit the sync now button if the last sync isn't recent enough
  • Find your project and switch from off to on
  • Click the spanner (takes you to the deploy hooks for the github project), choose travis and enter your username/token (available from your travis profile)
  • Add travis config to the project. This means we need to add a .travis.yml file. This specifies the language as java and what JDK you want to use. See .travis.yml
  • The build should now appear in your list on travis

Commit on github for this step

Step 3 - Let's get the build status to show at github

Once your build passes - on the travis page you can see an icon - build passing. If you click on that you get a popup of build status links.

Grab the one that uses the same format you want to use for your README.

Create the README file if not already present and include the link to the image. For this test I used markdown

Once pushed - refresh the github project page and you should see the build status icon.

Commit on github for this step

Step 4 - Create heroku app

Heroku's example uses embedded jetty - so update the app

And initial deploy:

$ heroku create web-hello-world
Creating web-hello-world... done, stack is cedar | [email protected]:web-hello-world.git
Git remote heroku added
$ git push heroku master

And now we can test the deployment

Commit on github for this step

Step 5 - Push builds to heroku

We need to add the heroku information to the travis yaml file. We don't want to have the auth key in plain text - so grab the travis command line tool and then run

$  travis setup heroku

Make sure you choose to encrypt the key.

Commit on github for this step

Step 6 - Test it

Change the app, commit and wait. Your change should arrive on the heroku site.

Once it's been tested and deployed - you can see the change

Commit on github for this step

More info:

Other useful links