How to Boost Our Software Engineers Productivity with CI/CD.

Kindest deployment and testing tasks that can be done effortlessly by using simple CI/CD.

--

Source of image: Getty Images

Have you ever accidentally deployed some change that breaks the application, and it happened because you forgot to fully test the application on your local machine?

Or maybe you are just too tired to do a repetitive task and then unconsciously deploying the application as fast as you can without testing it in your local machine.

I used to test my code to pass the test case, following the right convention, making sure the code won’t break anything at every time and the code is pushed to the currently active branch.

After successfully completing the previous steps and deploying the branch to the server, here are some actions that can be taken afterwards :

  1. Access to the server VPS
  2. Pull the latest code
  3. Update server configuration
  4. Restart the server

Well, at the first glance, you will not notice the problem, but I’d like to tell you that I do those tasks MANUALLY!

I think it’s fine if this activity only occurs once a month, but back then when I used to deploy the new version of the application, at least once a week and push the daily progress to the currently active branch. It was frustrating because there were lots of tasks that can be done automatically instead of doing it all manually.

(1) Every manual action must have a dual purpose of completing a task and improving the system. (2) Manual work should not be tolerated unless it generates an artifact(scripts/docs) or improves an existing one.

https://queue.acm.org/detail.cfm?id=3197520

One of the things we can do to eliminate the repetitive and manual tasks is to implement CI/CD for our application.

The acronym CI/CD refers to two separate concepts that are generally used together: continuous integration and continuous delivery.

Continuous Integration refers to an automation process that developers use to build, test, and merge application code changes.

Continuous Delivery is the next step in the process where the tested code from continuous integration is automatically deployed in various environments by a manual trigger.

https://blog.stackpath.com/ci-cd/

Before move forward to the example of using Gitlab + Heroku CI/CD, I’m assuming that you are already have the Heroku account, GitLab account, and its repository.

Setting Up Heroku CI/CD

After login into the Heroku dashboard, we need to create 2 Heroku applications (Staging & Production).

Click ‘New’ on the top right side and then choose “Create a new app”.

Then fill up the application name,

Please be aware to the app name whether it’s available or not.

here is an example if we successfully created staging and production applications.

After that, we need to get our API Key for the deployment purpose on Gitlab CI.

Navigate to the “Account setting”. Scroll down until you find the API Key.

Setting Up Gitlab CI/CD

First of all, clone your repository and make sure your account is validated especially when you are using a free tier just like mine.

After you successfully validate your account then create the .gitlab-ci.yml in your root application folder.

Here is the example of .gitlab-ci.yml for my simple blog using Ruby On Rails

There are few things that need to be highlighted.

First, Make sure you are managing a branch protection rule because the pipeline will automatically deploy if there are changes to the staging and master branches.

Second, the database configuration should have the same value as the Gitlab CI/CD configuration. Here is an example of my database configuration

Last but not least, We need to add CI/CD variable, from the configuration there are 3 main variables $HEROKU_API_KEY, $HEROKU_PRODUCTION_APP, and $HEROKU_STAGING_APP.

To configurate the CI/CI Variable, you’ll need to navigate to your repository settings and find CI/CI menu, then you will see the “Variables” section.
Add those 3 variables with the value that we got from the previous steps.

After that, whenever there are changes that pushed to the repository, the pipeline will do its magic

For further details, you can check the official GitLab CI/CD docs https://docs.gitlab.com/ee/ci/quick_start/

There are lots of CI/CI alternatives too, you can check them through this link https://stackshare.io/gitlab-ci/alternatives

Congrats, we successfully implemented the pipeline for our application, our team will get these advantages:
1. We don’t have to manually deploy the application anymore
2. We don’t have to worry if our changes will break the production, because when the pipeline failed, it will not deploy anything.
3. More importantly we can focus on the high level rather than the repetitive one.

Here are my other articles that discuss about system design, please kindly check them out too.

https://muhammad-rahmatullah.medium.com/the-pyramid-of-basic-coding-principles-e33b7c3cb316

https://medium.com/life-at-mekari/what-you-need-to-make-your-app-a-high-availability-system-tackling-the-technical-challenges-8896abec363f

https://medium.com/life-at-mekari/why-does-my-website-run-very-slowly-and-how-do-i-optimize-it-for-free-b21f8a2f0162

--

--

Muhammad Rahmatullah 🇮🇩
Stockbit-Bibit Engineering

An Expert Full-stack Software Engineer with years of experience, adept at developing, scaling software solutions. https://www.linkedin.com/in/rahmatullah5/