CI/CD pipeline for OrangeHRM open source application

Thulana Kannangara
4 min readAug 8, 2017

--

OrangeHRM is a open source application for human resource management. It is one of the mainly used HR software in the world. It is a PHP based application. So this article will be a insight into how OrangeHRM Open Source CICD pipeline works.

In tech Ops one of the main area is continuous integration. Continuous integration (CI) is the process of automatically building and testing your software on a regular basis. Continuous delivery is extended version of it. Continuous delivery is set of principles that ensures the product is always stable and releasable. But in continuous delivery, deployment to product environment happens manually. But if we automate deployment we say it’s continuous deployment. In theory, this process should happens regularly for its to be continuous.

Basic stages in CI

1st step

First step in CI work flow is to manage the source code. Git is one of the amazing tool to manage your code. Another thing, for a robust pipeline, code should be regularly pushed to a central repository. Here comes Git Hub. Git hub is compatible with CI work flows and even support open source CI sever, Travis. So in this example, I create the pipeline using git + git hub + Travis + docker + heroku .

CICD can works with both distributed and centralised version controlling systems. But its much more productive if we can use a distributed version control system. Here we decided to stick with feature branch workflow.

In feature branch workflow, wehave two main branches. They are,

  • Master
  • Develop

Master branch is used to maintain releases of the product and develop branch contains the up to date code base. When we needs to make a release what we do is we create a pull request from develop to master and merge it after code review. When there is a new feature or bug fix we create a feature branch in issue number and do the developments. Once its done it will be merged to develop branch using a pull request.

Both these branches have two CICD pipelines. Master branch pipeline ends in production environment and develop branch ends in development environment. There should not be any build failures in these two pipelines, therefore every pull request is reviewed and tested using pipeline.

2nd step

Pipeline starts when you push a commit to the repo. Then Travis should pull the commit and build it. Once its done, tests should be executed automatically. If tests are passed, application will be deployed to heroku. So, Second step is to configure Travis. We can create Travis account using git hub account. Then from Travis we can enable Travis builds for repositories. But we have to configure what should Travis do. This is done using .travis.yml file. For each commit travis will be triggered and will build the project using the .travis.yml file in the project root folder. In the travis file we can define what is the language and prerequisites for build process and how to run tests. This is the best part of the pipeline. In this project our intention is to run tests automatically and if they passed move on to deployment phase.

There are tags in Travis that we can use to configure the build. Use them wisely to improve the build time.

3rd Step

In travis I configured the build process in two stages. One is testing and the second is deploy. Testing can be parallel for functional, unit and acceptance testing. Then the deploy stage has two parallel pipelines for heroku deployment and dockerhub push. So lets talk about the testing stage. Here in this implementation I used PHPUnit and Codeception both for testing. Then I have added another feature to oil up the pipeline. That is code coverage. Travis doesn’t support code coverage visualization like Jenkins but whatwe can do is extract the code coverage details from php unit and send them to opensource code coverage analizing service. Here I use Xdebug and collect coverage data and send them to https://codecov.io/ .

I have enabled my project in the codecov account. So Once tests are done, I can view detailed code coverage report in Codecov. Isn't that cool??

4th step

Lets move on to first step of the deploy stage. What I did here was pushing a docker Image of the OrangeHRM Application wrapped in a complete AMP stack. Now I can deploy the application just by running the container. It includes apache server with the application and mysql server configured and prepared for the application. It’s pretty amazing what we can do with docker. Checkout docker documentation for more info. You can get a little idea about that by referring the dockerfile inside the project.

Docker is used to satisfy one important requirement. We have specific development and production environments for OrangeHRM application. So when we deploy the application using heroku, we should use this environment. We can eliminate the dependency between application and environment using docker.

5th step

In the second pipeline of the deploy stage, I deploy the docker image that I created to heroku. So after every commit to develop and master branches, Application is available live on web. Whole pipeline doesn’t take more than 15 mins. This means we can push a new change to production within 15 mins. Master and develop branches will be deployed to production and development environments.

This kind of a robust well oiled pipeline can be beneficial for software development life cycle. We have confidence that, at all time our code is working perfectly.

Hope you will take a step towards CICD. And don’t forget to checkout OrangeHRM Application.

You can refer the CICD implementation using following project.

Hope you have an idea how OrangeHRM ope source CICD pipeline works. Don’t forget to checkout OrangeHRM application and contribute to it. Thanks.

--

--