In build.gradle
update reference to local maven repo. Then run
# Windows
gradlew.bat publishToMavenLocal
# Linux/macOS
./gradlew publishToMavenLocal
plugins {
id "lenala.azure.azurewebapp" version "1.0.1"
}
Name | Required | Value |
---|---|---|
resourceGroup | true | Azure resource group to create Web App |
appName | true | Web App name |
region | false | Azure region. Optional, default is WEST_US2 |
appServicePlanResourceGroup | false | Specifies the resource group of the existing App Service Plan when you do not want to create a new one. If this setting is not specified, plugin will use the value defined in resourceGroup |
appServicePlanName | false | Specifies the name of the existing App Service Plan when you do not want to create a new one. |
stopAppDuringDeployment | false | Specifies whether to stop Web App during deployment. Optional, default is false |
appService | true | Block that specifies AppService settings |
type | true | Type of the AppService, one of {'linux','windows','docker'} |
runtimeStack | false | Supported are {'TOMCAT 8.5-jre8', 'TOMCAT 9.0-jre8', 'WILDFLY" 14-jre8', 'jre8'} |
javaWebContainer | false | One of WebContainer values, default is TOMCAT_8_5_NEWEST |
javaVersion | false | For App Service on Windows, supported versions are: {1.7, 1.7.0_51, 1.7.0_71, 1.8, 1.8.0_25, 1.8.0_60, 1.8.0_73, 1.8.0_111, 1.8.0_92, 1.8.0_102, 1.8.0_144} |
imageName | false | |
startUpFile | false | |
serverId | false | |
username | false | |
password | false | |
registryUrl | false | |
pricingTier | false | Specifies the pricing tier for your Web App; the default value is S1. |
authentication | true | Bloack that specifies authentication with Azure |
type | Authentication type, one of {FILE,PROPERTIES,AZURECLI} | |
authFile | false | File with authentication information. Optional, see Azure Authentication settings |
client | ||
tenant | ||
key | ||
certificate | ||
certificatePassword; | ||
deployment | true | Specifies deployment type and configuration |
deploymentType | false | Deployment type - one of {FTP, WAR, JAR, ZIP, NONE}. Optional, default value is WAR. |
warFile | false | Target war file to deploy. Not used for Web Apps for containers. Optional, if not specified, default war file output produced by 'war' plugin will be used. |
jarFile | false | Target jar file to deploy. Not used for Web Apps for containers. Optional, if not specified, default jar file output produced by 'bootJar' plugin will be used. |
deploymentSlot | false | Deployment slot name to use. For springboot1337/deploy the name you should enter is "deploy" |
contextPath | false | Url path |
appService
block should be specified, with the values:
Name | Value |
---|---|
type | 'windows' |
javaVersion | Java version. Supported versions are: {1.7, 1.7.0_51, 1.7.0_71, 1.8, 1.8.0_25, 1.8.0_60, 1.8.0_73, 1.8.0_111, 1.8.0_92, 1.8.0_102, 1.8.0_144} |
javaWebContainer | Web Container. Optional, default is newest Tomcat 8.5. |
azureWebApp {
resourceGroup = "${System.env.WEBAPP_RESOURCE_GROUP}"
appName = "${System.env.WEBAPP_NAME}"
pricingTier = "S2"
region = "southcentralus"
appService = {
type = 'windows'
javaWebContainer = "tomcat 8.5"
javaVersion = "1.8.0_102"
}
authentication = {
type = "file"
file = "<path_to_auth_file>"
}
deployment = {
type = "war"
// if 'warFile' is not specified, default output of the 'war' plugin will be used
// warFile = '<path_to_war_file>'
contextPath = 'todoapp' // Url path. Optional, if not specified Web App will be deployed to root. Works for WAR deployment type only.
}
}
appService
block should be specified, with the values:
Name | Value |
---|---|
type | 'windows' |
javaVersion | Java version. Supported versions are: {1.7, 1.7.0_51, 1.7.0_71, 1.8, 1.8.0_25, 1.8.0_60, 1.8.0_73, 1.8.0_111, 1.8.0_92, 1.8.0_102, 1.8.0_144} |
azureWebApp {
resourceGroup = "${System.env.WEBAPP_RESOURCE_GROUP}"
appName = "${System.env.WEBAPP_NAME}"
pricingTier = "S1"
appService = {
type = 'windows'
javaVersion = '1.8.0_25'
}
authentication = {
type = "file"
file = file('C:/stuff/2days.azureauth')
}
deployment = {
type = "jar"
// optional, if not provided, bootJar task output is used
// jarFile = file('<path_to_jar_file>')
}
}
appService
block should contain the values:
Name | Value |
---|---|
runtimeStack | Base image name. Right now possible values are: {'TOMCAT 9.0-jre8', 'TOMCAT 8.5-jre8} |
urlPath | Url path. Optional, if not specified Web App will be deployed to root. Works for WARDEPLOY deployment type only. |
azureWebApp {
resourceGroup = <resource_group>
appName = <appName>
pricingTier = "S2"
appService = {
type = 'linux'
runtimeStack = 'TOMCAT 9.0-jre8'
}
authentication = {
type = "file"
file = "<path_to_auth_file>"
}
deployment = {
type = "war"
// if 'warFile' is not specified, default output of the 'war' plugin will be used
// warFile = '<path_to_war_file>'
contextPath = 'todoapp'
}
}
In samples/todo-app-on-azure
folder, update reference to local maven repo, appName and Azure Container Registry url and credentials. Follow this tutorial to get started with Azure Container Registry.
In gradle.properties
, set your container registry serverId
, serverUsername
, and serverPassword
.
To push the Docker image, you'll need Docker running, then execute the dockerPushImage
task:
# Windows
gradlew.bat dockerPushImage
# Linux/macOS
./gradlew dockerPushImage
Create a new CosmosDB instance and set your CosmosDB credentials in src/main/resources/application.properties
.
Configure azurewebapp
in build.gradle
with valid values for resourceGroup
, appName
, pricingTier
, and authFile
(see the section on Azure Authentication settings).
Then deploy the ToDo web application to a Azure Container instance, you must specify the azureWebappDeploy
task:
# Windows
gradlew.bat azureWebappDeploy
# Linux/macOS
./gradlew azureWebappDeploy
containerSettings
block should be specified.
resourceGroup = <resource_group>
appName = <appName>
pricingTier = "S1"
appService = {
type = 'docker'
imageName = dockerImage
serverId = project.property('serverId')
registryUrl = "https://" + serverId
username = project.property('serverUsername')
password = project.property('serverPassword')
}
authentication = {
type = "file"
file = "C:/stuff/my2.azureauth"
}
deployment = {
type = "none"
}
}
plugins {
id "lenala.azure.azurefunctions" version "1.0.1"
}
Required only to run Azure Functions locally:
azurefunctions {
authFile = <file_with_authentication_info>
}
Package the functions for deployment.
task azureFunctionsPackage(type: PackageTask) {
dependsOn jar
appName = "myFunctionApp"
resourceGroup = "myFunctionApp"
region = "westus"
}
Deploy the project output jar to target Function App.
task azureFunctionsDeploy(type: DeployTask) {
appName = "myFunctionApp"
resourceGroup = "myFunctionApp"
region = "westus"
}
Invoke Azure Functions Local Emulator to run all functions.
task azureFunctionsRun(type: RunTask) {
appName = "myFunctionApp"
resourceGroup = "myFunctionApp"
region = "westus"
}
Create new Java function and add to current project.
task azureFunctionsAdd(type: AddTask) {
functionPackageName = "my.function"
functionTemplate = "HttpTrigger"
}
To build and deploy Azure Functions application, run:
gradle azureFunctionsPackage
gradle azureFunctionsDeploy
Where azureFunctionsPackage
is of type DeployTask
and AzureFunctionsDeploy
of type DeployTask
.
To verify function running, you can use curl -X POST -d "Azure World" <Deployed Host URL>/api/hello
.
To add a new function, run:
gradle azureFunctionsAdd
Where azureFunctionsAdd
is of type AddTask
.
To run function locally, use:
gradle azureFunctionsRun
Where azureFunctionsRun
is of type RunTask
.
To authenticate with Azure, device login can be used. To enable that, you need to sign in with Azure CLI first. Alternatively, authentication file can be used. The authentication file, referenced as "my.azureauth" in the example, contains the information of a service principal. You can generate this file using Azure CLI 2.0 through the following command. Make sure you selected your subscription by az account set --subscription and you have the privileges to create service principals.
az ad sp create-for-rbac --sdk-auth > my.azureauth
Please see Authentication in Azure Management Libraries for Java for authentication file formats. You can configure to use authentication file in gradle build script:
azurewebapp {
...
authFile=<path_to_file>
...
}
Another way to authenticate with Azure would be to provide settings in gradle.properties
:
client=<client_id>
tenant=<tenant_id>
key=(need key or certificate info)
certificate=(optional)
certificatePassword=(optional)
environment=(optional)
subscriptionId
can be also provided in gradle.properties, in case it is different from default subscription id.