An Azure Spring Boot Deployment Plugin
An Azure Spring Boot Deployment Plugin
Take a look, and learn how to use, this plugin, that bridges the gap between Spring Boot and the Azure API, opening doors for your deployments.
Join the DZone community and get the full member experience.Join For Free
Azure does not provide any Maven or Jenkins plugin to deploy applications onto the Azure API or web apps. So, this plugin helps deploy binaries in the Azure API or web apps by using the Azure AD Oauth app and FTP.
Step 1: Create an Azure AD Oauth App and Provide Access
- To create an OAuth App in Azure AD, go to Azure Active directory in the navigation pane and click on New-Application-Registration
- After Creating the app, select Required Permissions and add 'Windows Azure Service Management API' and provide all required permissions. (read-write). This ensures that the AD OAuth app has access to the Azure Service Management APIs (start/stop API/web app)
- After granting permissions, access keys need to be generated and saved, as they are visible only during creation.
- A detailed explanation of the Azure API app is provided in the following flow: https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications
Before adding the resource group, make sure we have the following:
- Application ID (Client ID) (from the previous steps).
- Client Password (from the previous step)
- Tenant ID — refer to the screenshot below
Go to Azure Active Directory -> Properties -> Directory ID
The last process is to provide ResourceGroup access to this particular AD app. Make it the owner or provide modifier access as shown below:
Set up the deployment credentials and save them for further use: https://docs.microsoft.com/en-us/azure/app-service/app-service-deployment-credentials
Step 2: Building and Deploying Your App
- azure-deployment-plugin: The Maven Plugin that needs to be added to the project, which needs to be deployed in the Azure API app
- hello-world-sb: A simple hello world Spring Boot application that needs to be deployed in Azure with a configuration in the pom.xml to add the custom Maven plugin (above).
- Run a 'mvn clean install' on the root folder of this repository.
- Once the build is successful, move onto the sample application. Open the pom.xml and provide the application and Azure specific values.
ftpCredentials -> '<<username>>::<<password>>'
|appName||Application name in Azure|
|clientId||Azure AD Oauth App's Client Id|
|clientPassword||password associated with the Oauth App|
|ftpCredentials||Azure deployment credentials - username::password (format)|
|ftpHostName||Azure API app's FTP hostname|
|resourceGroup||Azure API App's resource group|
|tenantId||Azure AD Tenant ID|
Azure API app's subscription ID
Upon completing the above configuration, assuming that the project is already built and the binary is available in the target folder, move onto the following steps:
- Run the custom Maven command azure-deploy:deploy from the 'hell-world-sb' project to push the JAR file to the Azure cloud via FTP.
- Ensure that the FTP ports are not blocked in your network.
- Continuous deployment is enabled by default. If there is an existing deployment already available, then the plugin does the following:
- Stops the application
- Pushes the JAR into a temp directory
- Moves the current deployment into backup folder and renames with a timestamp (creates a backup dir if not present)
- Moves the new JAR to the root folder
- Upon successful completion of the above steps, it starts the application. Upon hitting any exception, it still holds onto the existing deployment already available
- Clears the temp directory.
The concept was inherited from https://docs.cloudfoundry.org/devguide/deploy-apps/blue-green.html.
API App Screenshots
Simple API app tied to an app-service-plan:
Upon successful deployment:
The sample web.config for deployment is attached: web.config. It uses Java8 to support Spring Boot in the Azure API app.
Opinions expressed by DZone contributors are their own.