Effortless CI/CD for Spring Boot Apps on Azure App Service with GitHub Action
A step-by-step guide to setting up CI/CD for your Spring Boot apps on Azure App Service using GitHub Actions.
4 min read
In this article, we will go through the process of hosting Spring Boot Java application on Microsoft Azure App Service. Azure App Service allows you to quickly and easily create enterprise-ready web and mobile apps for any platform or device, and deploy them on a scalable and reliable cloud infrastructure.
Azure Account. (Create for free here) (You will need a debit/credit card for sign-up but won't be charged until you move to a pay-as-you-go plan post-exhaustion of the Free plan. Free Trial plan gives enough credit to run side-projects before you can scale out pricing plan.)
Spring Boot App. (We will bootstrap one quickly!)
Bootstrap Spring Boot App
We will quickly Bootstrap Spring Boot via Spring IO Initialzr.
Just change the Build tool to Maven and add Spring Web dependency.
Rest keep as default and generate the artifact. We are going with JDK17 and Spring Boot v3, won't matter in terms of how this article pans out.
Just adding a basic web controller to Spring Boot Project to hit the HTTP endpoint once deployed on Azure Cloud.
We will test locally once, to see if we get an HTTP response on the exposed Controller
The next step involves pushing our locally written code to Github.
We are pushing to the below repository named spring-boot-greet-azure. Post push it's time to deploy our code to Azure App Service.
Setup Azure App Service
Visit Microsoft Azure Cloud Portal.
Click on App Services and then on Create app Service. This will take us to Create Web app information page.
Select Free Trial as Subscription and Create a new Resource group if required in the same step.
A resource group is a collection of resources that share the same lifecycle, permissions, and policies. A resource group is a container with related resources for an Azure solution. The resource group can include all the resources for the solution, or only those resources that you want to manage as a group.
Give a meaningful name to the Instance. We are naming it spring-boot-greet-azure, and selecting Publish method as Code. (We will have one via Docker soon using Private Azure Registry.)
Select Runtime Stack as Java 17, and OS as Linux. Keep Region of East US as default.
Select the Free F1 pricing plan which is shared infrastructure for demo purposes.
Click on Review + Create. Then review the information once, and click Create.
Wait for some time, before App and Resources will be created. Then click on Go to resource.
Setup GitHub Actions for CI/CD
Here click on Deployment Center, here we will try to set up CI/CD with GitHub Actions.
Select Source as GitHub and then Authorize GitHub with MS Azure.
Select the required organization, Repository in our case is spring-boot-greet-azure, and the branch is main. You can preview the Github
workflow.ymlfile too, which will trigger our CI/CD process.
Click on Save in Top Left Corner. As soon as you save, and with no issues this will create and commit workflow file for GitHub action against our repository and also trigger Build and deployment for same.
Wait for Workflow Run to be successful, which Builds and Triggers deployment on Azure.
Once the build is successful, you can view deployment logs in Azure App Service itself or GitHub Workflow run for the same.
You can now click on HTTP URL create based on your web app name inputted, you can find in the Overview page of the Azure App Service you created below
We can now hit our /greet endpoint deployed on Azure App Service by visiting https://spring-boot-greet-azure.azurewebsites.net/greet
Voila! We have successfully deployed Spring Boot v3 Application running with JDK17 on Azure App Service with CI/CD via GitHub Action with ease.
We can integrate SONAR/Quality COde coverage along with other pipeline features to make it end to end SDLC pipeline.
Sometimes, you may get
404 errors on accessing the endpoint.
It may be due to the Application Insights Agent's interference with the tomcat version. Github Comment Issue on same highlights that.
In that case, we need to override the version for the Application Insight agent to use 3.4.9 as below.
Go to your Azure App Service --> Configuration --> Update Value for ApplicationInsightsAgent_EXTENSION_VERSION to 3.4.9
Thank you for reading, If you have reached it so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback and suggestions!