Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Azure Spring Boot Deployment Plugin

DZone's Guide to

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.

Free Resource

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

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.

Source code: https://github.com/Muthuveerappanv/Azure-Deployment-Plugin.

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

image1

  • 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)Image2

Imag3

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

Image5

The last process is to provide ResourceGroup access to this particular AD app. Make it the owner or provide modifier access as shown below:

Image title

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

Projects:

  1. azure-deployment-plugin: The Maven Plugin that needs to be added to the project, which needs to be deployed in the Azure API app
  2. 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).

Build procedure:

  • 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>>'

Image title

Configuration Description
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
subscriptionId

Azure API app's subscription ID

Procedure

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:

  1. 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.
  2. Ensure that the FTP ports are not blocked in your network.
  3. 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:

Image title

Upon successful deployment:

Image titleThe sample web.config for deployment is attached: web.config. It uses Java8 to support Spring Boot in the Azure API app.

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
spring boot ,jenkins ,azure web service ,cloud

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}