Tuesday, 27 October 2015

Introduction to CI and Cloud deployment with GitHub,Travis and Heroku


These past weeks, while (eventually) working in my Stokker project, I noted the lack of continuous build that I usually enjoy at work. I committed many bugs to my code-base and even, non-compiling code!

So, what are the alternatives to fix this situation? Perhaps having a local Jenkins environment? Too hard to maintain. No CI at all? Not feasible if we pretend that somebody might cooperate in the future.

One possible solution: Use Github integration with Travis CI and Heroku

This is one of many and, to be fair, I did´t do a thorough study on the different choices before trying it. I noticed that JHipster is using it as CI system for part of its code-base, though.

Basically, what Travis-CI does is to poll regularly your repository and perform a build based on the parameters specified in a file called .travis.yml.

Here, we can see a very basic example on how does this file look like:
Basically, we are stating that:
  • This is a Java project. As no build.gradle file has been provided, it will execute these Maven commands:
    • mvn clean install
    • mvn test
  • We intend to deploy the result of the successful build to Heroku
    • You can get the API Key later on, after registering in Heroku.

Hint on working with the .travis.yml file: One handy tool is this YAML validator, specially due to the cryptic error messages given by Travis-CI.

Once a change in the master branch is detected, Travis-CI will pull the code and perform a Maven build. If a compilation or test failure is detected the process will be stopped and notification mails will be sent.

This is how a successful build looks like:

As said, once you have a successful build, Travis CI will trigger a Heroku deployment. By the way, what is Heroku? Heroku is a commercial PaaS that also offers some free functionality for hobby programmers and people learning. If you want to test it, follow this steps:

  • Register in Heroku with your personal details.
  • Create an application and link it with your Github:
    • By doing so, you will be provided with an application key (which was inserted in the YML snippet above).
  • Choose the "Free" dyno mode. This mode offers you very limited resources and the machine is shut down after 60 minutes of inactivity.
    • By the way, these are the different plans available:

The way in which your application is executed, is defined in a Procfile (this file should be placed in the same folder of .travis.yml)

Running example

You can check the unfinished application running here: https://stokker.herokuapp.com

Update on November 1st 2015: I had to separate Stokker and Portfolio Manager into two different Github repositories (and two Heroku applications) in order to be able to run both of them so the URL for the Portfolio manager in Heroku is now: https://stokker-portfolio-manager.herokuapp.com

  • Please excuse me for the ugly interface, learning AngularJS is still one of my non achieved goals!). Moreover I have not yet provided a CRUD JavaScript interface for the entities managed in the project (Portfolio, Market Position and Stock). If you want to interact with the database, you can use the Spring Data REST endpoints:
  • You will notice that no price is used for the portfolios, as I still have not figured out how to run more that one application per repository.
  • Kibana functionality won´t be available.

Manage your application with Heroku toolbelt

Heroku offers you a tool called Heroku toolbelt that you can install in your local computer and use it to:
  • Manage and monitor your applications:
    • You can login and check the application logs.
    • You can deploy directly by performing a git push heroku.
  • Deploy your applications in a local environment in order to ensure that everything is OK before pushing your code.


This is a really shallow introduction to Travis CI and Heroke. I am astonished, as the more I read the more documentation I found. Here you might find some interesting links in case you want to continue learning on this topic:

Hope that you find this quick introduction interesting, any feedback is always more than welcome! You can find the code of the unfinished application here.

Wednesday, 14 October 2015

Integrate your Kibana dashboard in your Spring Boot + AngularJS application


Let´s review the process to follow in order to:

  •  Provide your Spring Boot application with a very basic AngularJS interface
  •  Show an already defined Kibana dashboard and interact with it.

The application for which we are going to define the user interface is called Portfolio Manager, a really simple Spring Boot application with some JPA entities (stock, position, portfolio, etc.) exposed via REST.
In order to feed the Elastic Search node from which Kibana will read, we will use Stokker (application described in past articles).

See this high-level diagram for a clearer picture of the system:

Both of them can be checked in this Git Hub repository along with the instructions to run all the components.