diff --git a/.gitignore b/.gitignore index c85813a..0e3a90f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /source/.vs/AzureFunctionWebAPI/v16 /source/tests/SampleAzureFunctionCode.Tests/obj +/source/.vs/AzureFunctionWebAPI/DesignTimeBuild/.dtbcache diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 74f8782..a3f9733 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,7 +12,10 @@ variables: devazureSubscription: 'f27beff6-c5b7-41a5-bd50-2b9fce4760ca' # Function app name - devFunctionAppName: 'fcd-dev-web-app' + resourceGroupName: 'fcd-dev-function' + functionAppName: 'fcd-dev-web-app' + location: 'centralus' + templateLocation : '$(System.DefaultWorkingDirectory)/config/azurefunctiondeploy.json' # Agent VM image name vmImageName: 'vs2017-win2016' @@ -22,8 +25,27 @@ variables: testsDirectory: '$(System.DefaultWorkingDirectory)/source/tests/SampleAzureFunctionCode.Tests' stages: +- stage: Resource_Deployment + displayName: Resource Deployment + + jobs: + - job: Start_Resource_Deployment + displayName: Resources + pool: + vmImage: $(vmImageName) + + steps: + - task: AzureCLI@2 + displayName: 'Resource Deployment' + inputs: + azureSubscription: 'AzureFunction' + scriptType: ps + scriptPath: '$(System.DefaultWorkingDirectory)/config/config.ps1' + scriptArguments: $(templateLocation) $(resourceGroupName) $(functionAppName) $(location) - stage: Build displayName: Build stage + dependsOn: Resource_Deployment + condition: succeeded() jobs: - job: Build @@ -85,7 +107,6 @@ stages: testRunner: VSTest testResultsFiles: '**/*.trx' - - stage: Dev_Deployment displayName: Dev Deployment stage dependsOn: Start_Run_Test @@ -106,9 +127,9 @@ stages: - task: AzureFunctionApp@1 displayName: 'Azure functions app deploy' inputs: - azureSubscription: '$(devazureSubscription)' + azureSubscription: 'AzureFunction' appType: functionApp - appName: $(devFunctionAppName) + appName: $(functionAppName) package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' diff --git a/config/azurefunctiondeploy.json b/config/azurefunctiondeploy.json new file mode 100644 index 0000000..4dd6fc8 --- /dev/null +++ b/config/azurefunctiondeploy.json @@ -0,0 +1,136 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "appName": { + "type": "string", + "metadata": { + "description": "The name of the function app that you wish to create." + } + }, + "storageAccountType": { + "type": "string", + "defaultValue": "Standard_LRS", + "allowedValues": ["Standard_LRS", "Standard_GRS", "Standard_RAGRS"], + "metadata": { + "description": "Storage Account type" + } + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]", + "metadata": { + "description": "Location for all resources." + } + }, + "runtime": { + "type": "string", + "defaultValue": "dotnet", + "allowedValues": ["dotnet", "node", "java"], + "metadata": { + "description": "The language worker runtime to load in the function app." + } + } + }, + "variables": { + "functionAppName": "[parameters('appName')]", + "hostingPlanName": "[parameters('appName')]", + "applicationInsightsName": "[parameters('appName')]", + "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunctions')]", + "storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", + "functionWorkerRuntime": "[parameters('runtime')]" + }, + "resources": [ + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[variables('storageAccountName')]", + "apiVersion": "2016-12-01", + "location": "[parameters('location')]", + "kind": "Storage", + "sku": { + "name": "[parameters('storageAccountType')]" + } + }, + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2018-02-01", + "name": "[variables('hostingPlanName')]", + "location": "[parameters('location')]", + "sku": { + "name": "Y1", + "tier": "Dynamic" + }, + "properties": { + "name": "[variables('hostingPlanName')]", + "computeMode": "Dynamic" + } + }, + { + "apiVersion": "2015-08-01", + "type": "Microsoft.Web/sites", + "name": "[variables('functionAppName')]", + "location": "[parameters('location')]", + "kind": "functionapp", + "dependsOn": [ + "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]", + "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]" + ], + "properties": { + "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]", + "siteConfig": { + "appSettings": [ + { + "name": "AzureWebJobsStorage", + "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]" + }, + { + "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", + "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]" + }, + { + "name": "WEBSITE_CONTENTSHARE", + "value": "[toLower(variables('functionAppName'))]" + }, + { + "name": "FUNCTIONS_EXTENSION_VERSION", + "value": "~2" + }, + { + "name": "WEBSITE_NODE_DEFAULT_VERSION", + "value": "~10" + }, + { + "name": "APPINSIGHTS_INSTRUMENTATIONKEY", + "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]" + }, + { + "name": "FUNCTIONS_WORKER_RUNTIME", + "value": "[variables('functionWorkerRuntime')]" + }, + { + "name": "SCM_DO_BUILD_DURING_DEPLOYMENT", + "value": "true" + }, + { + "name": "WEBSITE_RUN_FROM_PACKAGE", + "value": "1" + } + ] + } + } + }, + { + "apiVersion": "2018-05-01-preview", + "name": "[variables('applicationInsightsName')]", + "type": "microsoft.insights/components", + "location": "[parameters('location')]", + "tags": { + "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('applicationInsightsName'))]": "Resource" + }, + "properties": { + "ApplicationId": "[variables('applicationInsightsName')]", + "Request_Source": "IbizaWebAppExtensionCreate" + } + } + ] +} diff --git a/config/config.ps1 b/config/config.ps1 new file mode 100644 index 0000000..d028895 --- /dev/null +++ b/config/config.ps1 @@ -0,0 +1,36 @@ +param( + [Parameter(Mandatory = $true)][String]$templateLocation, + [Parameter(Mandatory = $false)][String]$resourceGroupName = "fcd-dev-function", + [Parameter(Mandatory = $false)][String]$functionAppName = "fcd-dev-web-app", + [Parameter(Mandatory = $false)][String]$location = "centralus", + [Parameter(Mandatory = $false)][String]$runtime = "dotnet") + +# Create the parameters for the file, which for this template is the function app name. +# $TemplateParams = @{"appName" = $functionAppName} + +# Register Resource Providers if they're not already registered +az provider register --namespace "microsoft.web" +az provider register --namespace "microsoft.storage" + +$resourceExist = az group exists -n $resourceGroupName + + +if($resourceExist -eq $true){ + # Create a resource group for the function app + Write-Host "resources exist" +} +else{ + Write-Host "resources not exist" + az group create -n $resourceGroupName -l $location +} + +$checkFunctionAppName = az functionapp show -g $resourceGroupName -n $functionAppName +if($checkFunctionAppName -eq $null){ + # Deploy the template + Write-Host "function not exist" + az group deployment create --resource-group $resourceGroupName --template-file $templateLocation --parameters appName=$functionAppName runtime=$runtime --verbose + +} +else{ + Write-Host "function exist" +} \ No newline at end of file diff --git a/source/.vs/AzureFunctionWebAPI/config/applicationhost.config b/source/.vs/AzureFunctionWebAPI/config/applicationhost.config new file mode 100644 index 0000000..136bd79 --- /dev/null +++ b/source/.vs/AzureFunctionWebAPI/config/applicationhost.config @@ -0,0 +1,1027 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +