It's been a while since I wrote my last blog post. Having some free time at work, I thought this would be a great time to start writing this. Last semester, which was the 2nd semester for the 3rd year at SLIIT, we had to implement Ticketing application for the public transport services. We came up with a design with four separate microservices, an web application and a mobile application. To keep the development of the microservices on the right track, I decided to have a CI/CD pipeline.
CI – Continuous Integration is a development practice that reduces the conflicts that could arise when a team of developers integrate code into a shared repository. Each commit to the repository is verified by an automated build making it easy to identify issue early.
CD – Continuous Deployment is closely related to Continuous Integration and refers to the release into production of software that passes the automated tests.
So, lets get started. I will be using a sample application that I implemented using NodeJS + ExpressJS and the tests were written on chai.
Continuous Integration on Travis CI
First we head over to Travis-CI and there after connecting our GitHub account, we flick the respective toggle button to enable CI or to connect the project to Travis-CI.
Then we add the Travis-CI configurations in the .travis.yml file as follows. These configurations are likely to change based on the application you develop and the language you would be using.
language: node_js
node_js:
- "7"
before_script:
- npm install
script: npm test
Next, we can trigger our first build by simply pushing our changes to the remote repository. If everything goes on very well, you could see this output on the Travis-CI console.
One issue I faced during the CI integration was that the newer version of Mocha does not simply stop executing after the tests are done, hence the builds started failing. Using a little older version of mocha helped me out.
Continuous Deployment on Heroku
- Create a Heroku account.
- Create new application.
- Under 'Deploy' of you application, connect to GitHub and then to your repository.
- Enable Automatic Deploys from a branch of your choice and enable 'Wait for CI to pass before deploy'.