In this blog, we will see how to set up a Bit-Bucket Pipeline to get CI/CD for your Akka HTTP Application. We will be deploying the application on the HEROKU server, but in this blog, we will also see how to dockerize the application and push the image on Docker Hub which further can be used to deploy on any container orchestration platform.
Let’s get straight to the implementation, for more information on CI/CD and on Bitbucket pipelines refer to our other blogs:
Introduction to Bit-Bucket Pipelines
CI/CD Overview and Jenkins Introduction
All Blog For CI/CD
Step 1) Akka HTTP Appication Code
Develop ( let’s Treat it as the Development branch)
Master ( Will be treated as the master or production branch from which the code is deployed into production)
You can have other branches also like feature/, bug/ etc, but to demonstrate the CI/CD pipeline functionality and to keep it simple, we will use these two branches.
Code Details –
This is a sample project using Akka-HTTP, that start’s an HTTP server at localhost and port 8080 and contains two basic get routes –
Provide you the health status(ok):
Provides you a random no on an HTTP web page:
Now our focus is to create a CI/CD pipeline for our project that basically take care of the following –
1) On Any pull request –
From the “develop” branch to “master” should check for security concerns ( here we will be doing the git-secret-scan, but you can also use the third-party plugins in your project).
Run and ensure all the test cases pass with maintaining the code coverage.
check’s for your scale style and formatting. And if and only if all the above cases pass you will have a GREEN PIPELINE and are ready to merge.
2) On Merge Of Pull request –
Should create JAR/ASSEMBLY for your project.
Will then eventually create a docker image, and/or push it to a repository
Deploy the image to your orchestration cluster ( like Kubernetes). – This can be an option or depends on where you want to deploy the app.
Step 2) Create a Bit-Bucket Pipeline
The complete downloadable code is present – CI/CD with Bit-Bucket Pipelines. Go get it and start playing.
Now few key points that one need to take care for building the pipeline.yml file –
2.1) Store your docker hub credentials under your Repository Setting –
akka-sample -> Repository settings
2.2) Define your pipeline steps as the following hierarchy –
Under this, we will define all the steps we have to take when a Pull-Request is raised from the “develop” branch. Here we are adding two steps –
1) name: ‘Test and Lint and Formatting check Akka-Sample App’, (which does the style check, Formatting Check, and coverage)
2) name: Security Scan
The next thing that we will define is for our Continous Deployment, where when the PR is merged into “master” branch.
Here we are doing the following steps –
branches: # master branch pipeline
1) name: Build docker image for Akka sample microservice
2) name: Packaging the jar for Akka-sample microservice
3) name: Deploy Akka-sample microservice
So the 3rd step now will totally be based on where you want to deploy your application, here we are using Heroku and you will have to define HEROKU_API_KEY and HEROKU_APP_NAME for that.
git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD Step
3) Live Check – Demo
Now let’s verify our pipeline – Let’s first look at how the app looks like when first deployed on Heroku
Let change some text and create a Pull-Request I have added some information about myself and created a PR –
We will see as soon as the PR is created, it will trigger the Pipeline –
and once all the check passes we are good to merge it –
This comprises your Continuous Integration Step, now as soon as we merge the PR, we will have our Continous Deployment pipeline gets triggered and the magic is on.
– The Merge to the “master” branch triggers the deployment steps and it should create a new jar, docker image ( here for reference) and should deploy it to the Heroku server, and finally, we should see the new changes.
The screen shot below shows the described steps –
Creating the Jar:
Creating Docker Image:
Deploying it on Heroku:
and hence once deployed finally The Updated Code:
that’s all pretty much, I have tried to make the steps simple and clear. We will cover how to deploy it on the Kubernetes cluster in our next blog, so till then keep reading and ease your learning and development.