From 83129c5af344047b5d1334b240f8ba8c831acdf5 Mon Sep 17 00:00:00 2001 From: madcoderbubt Date: Sat, 9 Jul 2022 02:28:20 +0600 Subject: [PATCH 1/5] Azure Function Publish & ci/cd pipeline added --- .../workflows/MadCoderAzureFunctionsDemo.yml | 37 ++++++++++ AzureFunctionsDemo/AzureFunctionsDemo.csproj | 1 + AzureFunctionsDemo/GitMonitorApp.cs | 30 ++++++++ AzureFunctionsDemo/MyInfo.json | 5 ++ .../appInsights1.arm.json | 67 ++++++++++++++++++ .../storage1.arm.json | 70 +++++++++++++++++++ ...pendencies.MadCoderAzureFunctionsDemo.json | 15 ++++ .../Properties/serviceDependencies.json | 7 +- 8 files changed, 229 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/MadCoderAzureFunctionsDemo.yml create mode 100644 AzureFunctionsDemo/GitMonitorApp.cs create mode 100644 AzureFunctionsDemo/MyInfo.json create mode 100644 AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/appInsights1.arm.json create mode 100644 AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/storage1.arm.json create mode 100644 AzureFunctionsDemo/Properties/serviceDependencies.MadCoderAzureFunctionsDemo.json diff --git a/.github/workflows/MadCoderAzureFunctionsDemo.yml b/.github/workflows/MadCoderAzureFunctionsDemo.yml new file mode 100644 index 0000000..b5fb005 --- /dev/null +++ b/.github/workflows/MadCoderAzureFunctionsDemo.yml @@ -0,0 +1,37 @@ +name: Build and deploy .NET Core application to Function App MadCoderAzureFunctionsDemo +on: + push: + branches: + - master +env: + AZURE_FUNCTIONAPP_NAME: MadCoderAzureFunctionsDemo + AZURE_FUNCTIONAPP_PACKAGE_PATH: .\published + CONFIGURATION: Release + DOTNET_CORE_VERSION: 3.1.x + WORKING_DIRECTORY: '' + DOTNET_CORE_VERSION_INPROC: '' +jobs: + build-and-deploy: + runs-on: windows-latest + steps: + - uses: actions/checkout@master + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_CORE_VERSION }} + - name: Setup .NET Core (for inproc extensions) + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_CORE_VERSION_INPROC }} + - name: Restore + run: dotnet restore "${{ env.WORKING_DIRECTORY }}" + - name: Build + run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore + - name: Publish + run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}" + - name: Deploy to Azure Function App + uses: Azure/functions-action@v1 + with: + app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }} + publish-profile: ${{ secrets.MADCODERAZUREFUNCTIONSDEMO_FFFF }} + package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} diff --git a/AzureFunctionsDemo/AzureFunctionsDemo.csproj b/AzureFunctionsDemo/AzureFunctionsDemo.csproj index 958d2f7..1ed5bc3 100644 --- a/AzureFunctionsDemo/AzureFunctionsDemo.csproj +++ b/AzureFunctionsDemo/AzureFunctionsDemo.csproj @@ -4,6 +4,7 @@ v3 + diff --git a/AzureFunctionsDemo/GitMonitorApp.cs b/AzureFunctionsDemo/GitMonitorApp.cs new file mode 100644 index 0000000..d6aa7c9 --- /dev/null +++ b/AzureFunctionsDemo/GitMonitorApp.cs @@ -0,0 +1,30 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Azure.WebJobs; +using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace AzureFunctionsDemo +{ + public static class GitMonitorApp + { + [FunctionName("GitMonitorApp")] + public static async Task Run( + [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, + ILogger log) + { + log.LogInformation("Git Monitor App"); + + string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); + dynamic data = JsonConvert.DeserializeObject(requestBody); + + log.LogInformation(requestBody); + + return new OkResult(); + } + } +} diff --git a/AzureFunctionsDemo/MyInfo.json b/AzureFunctionsDemo/MyInfo.json new file mode 100644 index 0000000..bddc3b1 --- /dev/null +++ b/AzureFunctionsDemo/MyInfo.json @@ -0,0 +1,5 @@ +{ + "FirstName": "Sudhananda", + "LastName": "Biswas", + "Designation": "Jr. Software Engineer" +} diff --git a/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/appInsights1.arm.json b/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/appInsights1.arm.json new file mode 100644 index 0000000..0153df1 --- /dev/null +++ b/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/appInsights1.arm.json @@ -0,0 +1,67 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "MadCoderAzureFunctionsDemoResourceGroup", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "centralindia", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('AzureFunctionsDemo', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "name": "AzureFunctionsDemo", + "type": "microsoft.insights/components", + "location": "[parameters('resourceLocation')]", + "kind": "web", + "properties": {}, + "apiVersion": "2015-05-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "appInsights.azure" + } +} \ No newline at end of file diff --git a/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/storage1.arm.json b/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/storage1.arm.json new file mode 100644 index 0000000..3add243 --- /dev/null +++ b/AzureFunctionsDemo/Properties/ServiceDependencies/MadCoderAzureFunctionsDemo/storage1.arm.json @@ -0,0 +1,70 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "MadCoderAzureFunctionsDemoResourceGroup", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "centralindia", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('mcoderazurefunctionsdemo', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "sku": { + "name": "Standard_LRS", + "tier": "Standard" + }, + "kind": "Storage", + "name": "mcoderazurefunctionsdemo", + "type": "Microsoft.Storage/storageAccounts", + "location": "[parameters('resourceLocation')]", + "apiVersion": "2017-10-01" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "storage.azure" + } +} \ No newline at end of file diff --git a/AzureFunctionsDemo/Properties/serviceDependencies.MadCoderAzureFunctionsDemo.json b/AzureFunctionsDemo/Properties/serviceDependencies.MadCoderAzureFunctionsDemo.json new file mode 100644 index 0000000..96313aa --- /dev/null +++ b/AzureFunctionsDemo/Properties/serviceDependencies.MadCoderAzureFunctionsDemo.json @@ -0,0 +1,15 @@ +{ + "dependencies": { + "storage1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Storage/storageAccounts/mcoderazurefunctionsdemo", + "type": "storage.azure", + "connectionId": "AzureWebJobsStorage" + }, + "appInsights1": { + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourcegroups/[parameters('resourceGroupName')]/providers/Microsoft.Insights/components/AzureFunctionsDemo", + "type": "appInsights.azure", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING", + "secretStore": "AzureAppSettings" + } + } +} \ No newline at end of file diff --git a/AzureFunctionsDemo/Properties/serviceDependencies.json b/AzureFunctionsDemo/Properties/serviceDependencies.json index df4dcc9..41441f6 100644 --- a/AzureFunctionsDemo/Properties/serviceDependencies.json +++ b/AzureFunctionsDemo/Properties/serviceDependencies.json @@ -1,11 +1,12 @@ { "dependencies": { - "appInsights1": { - "type": "appInsights" - }, "storage1": { "type": "storage", "connectionId": "AzureWebJobsStorage" + }, + "appInsights1": { + "type": "appInsights", + "connectionId": "APPINSIGHTS_CONNECTIONSTRING" } } } \ No newline at end of file From 10be88f25692b9d06477dfdff431053c170c4537 Mon Sep 17 00:00:00 2001 From: Sudhananda Biswas <25325501+madcoderBubt@users.noreply.github.com> Date: Sat, 9 Jul 2022 02:39:14 +0600 Subject: [PATCH 2/5] add readme file --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..97f0d98 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# AzureFunctionsDemo +Azure Functions Introduction From 75e2b1b523910bf693007bc47c7ab23076f02590 Mon Sep 17 00:00:00 2001 From: Sudhananda Biswas <25325501+madcoderBubt@users.noreply.github.com> Date: Sat, 9 Jul 2022 02:54:45 +0600 Subject: [PATCH 3/5] readme file update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 97f0d98..98003b2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # AzureFunctionsDemo Azure Functions Introduction +[![Build and deploy .NET Core application to Function App MadCoderAzureFunctionsDemo](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml/badge.svg?branch=master)](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml) From f4f0847ae1e9861f01bbb6e02225c21f23395e79 Mon Sep 17 00:00:00 2001 From: madcoderbubt Date: Sat, 9 Jul 2022 13:46:43 +0600 Subject: [PATCH 4/5] git monitor app function --- AzureFunctionsDemo/GitMonitorApp.cs | 123 +++++++++++++++++++++++++++- README.md | 3 +- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/AzureFunctionsDemo/GitMonitorApp.cs b/AzureFunctionsDemo/GitMonitorApp.cs index d6aa7c9..3e134b4 100644 --- a/AzureFunctionsDemo/GitMonitorApp.cs +++ b/AzureFunctionsDemo/GitMonitorApp.cs @@ -20,11 +20,132 @@ public static async Task Run( log.LogInformation("Git Monitor App"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); - dynamic data = JsonConvert.DeserializeObject(requestBody); + dynamic data = JsonConvert.DeserializeObject(requestBody); log.LogInformation(requestBody); return new OkResult(); } } + + public class Rootobject + { + public Authorization authorization { get; set; } + public string caller { get; set; } + public string channels { get; set; } + public Claims claims { get; set; } + public string correlationId { get; set; } + public string description { get; set; } + public string eventDataId { get; set; } + public Eventname eventName { get; set; } + public Category category { get; set; } + public DateTime eventTimestamp { get; set; } + public string id { get; set; } + public string level { get; set; } + public string operationId { get; set; } + public Operationname operationName { get; set; } + public string resourceGroupName { get; set; } + public Resourceprovidername resourceProviderName { get; set; } + public Resourcetype resourceType { get; set; } + public string resourceId { get; set; } + public Status status { get; set; } + public Substatus subStatus { get; set; } + public DateTime submissionTimestamp { get; set; } + public string subscriptionId { get; set; } + public string tenantId { get; set; } + public Properties properties { get; set; } + public object[] relatedEvents { get; set; } + } + + public class Authorization + { + public string action { get; set; } + public string scope { get; set; } + } + + public class Claims + { + public string aud { get; set; } + public string iss { get; set; } + public string iat { get; set; } + public string nbf { get; set; } + public string exp { get; set; } + public string httpschemasmicrosoftcomclaimsauthnclassreference { get; set; } + public string aio { get; set; } + public string altsecid { get; set; } + public string httpschemasmicrosoftcomclaimsauthnmethodsreferences { get; set; } + public string appid { get; set; } + public string appidacr { get; set; } + public string httpschemasxmlsoaporgws200505identityclaimsemailaddress { get; set; } + public string httpschemasxmlsoaporgws200505identityclaimssurname { get; set; } + public string httpschemasxmlsoaporgws200505identityclaimsgivenname { get; set; } + public string groups { get; set; } + public string httpschemasmicrosoftcomidentityclaimsidentityprovider { get; set; } + public string ipaddr { get; set; } + public string name { get; set; } + public string httpschemasmicrosoftcomidentityclaimsobjectidentifier { get; set; } + public string puid { get; set; } + public string rh { get; set; } + public string httpschemasmicrosoftcomidentityclaimsscope { get; set; } + public string httpschemasxmlsoaporgws200505identityclaimsnameidentifier { get; set; } + public string httpschemasmicrosoftcomidentityclaimstenantid { get; set; } + public string httpschemasxmlsoaporgws200505identityclaimsname { get; set; } + public string uti { get; set; } + public string ver { get; set; } + public string wids { get; set; } + public string xms_tcdt { get; set; } + } + + public class Eventname + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Category + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Operationname + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Resourceprovidername + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Resourcetype + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Status + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Substatus + { + public string value { get; set; } + public string localizedValue { get; set; } + } + + public class Properties + { + public string statusCode { get; set; } + public object serviceRequestId { get; set; } + public string eventCategory { get; set; } + public string entity { get; set; } + public string message { get; set; } + public string hierarchy { get; set; } + } + } diff --git a/README.md b/README.md index 98003b2..f9750b5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # AzureFunctionsDemo Azure Functions Introduction -[![Build and deploy .NET Core application to Function App MadCoderAzureFunctionsDemo](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml/badge.svg?branch=master)](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml) + +[![Build and deploy Azure Functions to MadCoderAzureFunctionsDemo](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml/badge.svg?branch=master)](https://github.com/madcoderBubt/AzureFunctionsDemo/actions/workflows/MadCoderAzureFunctionsDemo.yml) From e9860661fbe335b17b351d0cbbc91cd7f5fad79c Mon Sep 17 00:00:00 2001 From: Sudhananda Biswas <25325501+madcoderBubt@users.noreply.github.com> Date: Sun, 10 Jul 2022 00:05:47 +0600 Subject: [PATCH 5/5] git action on pull_request from master to release --- .github/workflows/MadCoderAzureFunctionsDemo.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/MadCoderAzureFunctionsDemo.yml b/.github/workflows/MadCoderAzureFunctionsDemo.yml index b5fb005..a43c468 100644 --- a/.github/workflows/MadCoderAzureFunctionsDemo.yml +++ b/.github/workflows/MadCoderAzureFunctionsDemo.yml @@ -1,8 +1,8 @@ name: Build and deploy .NET Core application to Function App MadCoderAzureFunctionsDemo on: - push: + pull_request: branches: - - master + - Release env: AZURE_FUNCTIONAPP_NAME: MadCoderAzureFunctionsDemo AZURE_FUNCTIONAPP_PACKAGE_PATH: .\published @@ -14,7 +14,7 @@ jobs: build-and-deploy: runs-on: windows-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@Release - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: