Giter Site home page Giter Site logo

azure-gradle-plugins's Introduction

Build Status

azure-gradle-plugins

Compiling plugins locally

In build.gradle update reference to local maven repo. Then run

# Windows
gradlew.bat publishToMavenLocal

# Linux/macOS
./gradlew publishToMavenLocal

Azure WebApp plugin

plugins {
  id "com.microsoft.azure.azurewebapp" version "1.0"
}

Common settings

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.
contextPath false Url path

These types of deployment are supported:

Web App on Windows

Deploy WAR

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.
    }
}

Deploy JAR

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>')
    }
}

Sample ToDo app

Web App on Linux

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

Sample ToDo App

Web Apps on Containers

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.

Deployment from Private Container Registry (Azure Container Registry)

    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"
    }
}

Usage example

Deployment from public Docker Hub

Deployment from private Docker Hub

Azure Functions plugin

plugins {
  id "com.microsoft.azure.azurefunctions" version "1.0"
}

Prerequisites

Required only to run Azure Functions locally:

Common configuration

azurefunctions {
    authFile = <file_with_authentication_info>
}

Tasks

PackageTask

Package the functions for deployment.

task azureFunctionsPackage(type: PackageTask) {
    dependsOn jar
    appName = "myFunctionApp"
    resourceGroup = "myFunctionApp"
    region = "westus"
}

DeployTask

Deploy the project output jar to target Function App.

task azureFunctionsDeploy(type: DeployTask) {
    appName = "myFunctionApp"
    resourceGroup = "myFunctionApp"
    region = "westus"
}

RunTask

Invoke Azure Functions Local Emulator to run all functions.

task azureFunctionsRun(type: RunTask) {
    appName = "myFunctionApp"
    resourceGroup = "myFunctionApp"
    region = "westus"
}

AddTask

Create new Java function and add to current project.

task azureFunctionsAdd(type: AddTask) {
    functionPackageName = "my.function"
    functionTemplate = "HttpTrigger"
}

Running sample Azure Functions app

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.

Source code for sample app

Azure Authentication settings

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.

azure-gradle-plugins's People

Contributors

aalmiray avatar brunoborges avatar eriwen avatar lenala avatar yoichiro avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

stuartraetaylor

azure-gradle-plugins's Issues

Resolve warnings from validateTaskProperties

> Task :azure-functions-gradle-plugin:validateTaskProperties
Task property validation finished with warnings:
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'appName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'appSettings' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'authFile' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'azureClient' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'basedir' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'buildDirectoryAbsolutePath' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'className' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'deploymentStageDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'finalName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'functionApp' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'functionName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'functionPackageName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'functionTemplate' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'outputDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'region' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'resourceGroup' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'sourceRoot' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'subscriptionId' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.AddTask': property 'userAgent' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'appName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'appSettings' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'authFile' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'azureClient' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'buildDirectoryAbsolutePath' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'deploymentStageDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'deploymentType' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'finalName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'functionApp' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'outputDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'pricingTier' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'region' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'resourceGroup' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'subscriptionId' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.DeployTask': property 'userAgent' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'appName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'appSettings' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'authFile' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'azureClient' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'buildDirectoryAbsolutePath' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'deploymentStageDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'finalName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'functionApp' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'outputDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'region' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'resourceGroup' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'subscriptionId' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.PackageTask': property 'userAgent' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'appName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'appSettings' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'authFile' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'azureClient' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'buildDirectoryAbsolutePath' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'deploymentStageDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'finalName' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'functionApp' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'inputFile' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'inputString' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'outputDirectory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'region' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'resourceGroup' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'subscriptionId' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'targetFunction' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.functions.RunTask': property 'userAgent' is not annotated with an input or output annotation.

> Task :azure-webapp-gradle-plugin:validateTaskProperties
Task property validation finished with warnings:
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'authenticationSettings' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'azureClient' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'azureWebAppExtension' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'factory' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'subscriptionId' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'userAgent' is not annotated with an input or output annotation.
  - Warning: Task type 'com.microsoft.azure.gradle.webapp.DeployTask': property 'webApp' is not annotated with an input or output annotation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.