Skip to content

Commit 83129c5

Browse files
committed
Azure Function Publish & ci/cd pipeline added
1 parent 22ed2d2 commit 83129c5

File tree

8 files changed

+229
-3
lines changed

8 files changed

+229
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and deploy .NET Core application to Function App MadCoderAzureFunctionsDemo
2+
on:
3+
push:
4+
branches:
5+
- master
6+
env:
7+
AZURE_FUNCTIONAPP_NAME: MadCoderAzureFunctionsDemo
8+
AZURE_FUNCTIONAPP_PACKAGE_PATH: .\published
9+
CONFIGURATION: Release
10+
DOTNET_CORE_VERSION: 3.1.x
11+
WORKING_DIRECTORY: ''
12+
DOTNET_CORE_VERSION_INPROC: ''
13+
jobs:
14+
build-and-deploy:
15+
runs-on: windows-latest
16+
steps:
17+
- uses: actions/checkout@master
18+
- name: Setup .NET Core
19+
uses: actions/setup-dotnet@v1
20+
with:
21+
dotnet-version: ${{ env.DOTNET_CORE_VERSION }}
22+
- name: Setup .NET Core (for inproc extensions)
23+
uses: actions/setup-dotnet@v1
24+
with:
25+
dotnet-version: ${{ env.DOTNET_CORE_VERSION_INPROC }}
26+
- name: Restore
27+
run: dotnet restore "${{ env.WORKING_DIRECTORY }}"
28+
- name: Build
29+
run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore
30+
- name: Publish
31+
run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}"
32+
- name: Deploy to Azure Function App
33+
uses: Azure/functions-action@v1
34+
with:
35+
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
36+
publish-profile: ${{ secrets.MADCODERAZUREFUNCTIONSDEMO_FFFF }}
37+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}

AzureFunctionsDemo/AzureFunctionsDemo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
55
</PropertyGroup>
66
<ItemGroup>
7+
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
78
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
89
</ItemGroup>
910
<ItemGroup>

AzureFunctionsDemo/GitMonitorApp.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Azure.WebJobs;
6+
using Microsoft.Azure.WebJobs.Extensions.Http;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.Extensions.Logging;
9+
using Newtonsoft.Json;
10+
11+
namespace AzureFunctionsDemo
12+
{
13+
public static class GitMonitorApp
14+
{
15+
[FunctionName("GitMonitorApp")]
16+
public static async Task<IActionResult> Run(
17+
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
18+
ILogger log)
19+
{
20+
log.LogInformation("Git Monitor App");
21+
22+
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
23+
dynamic data = JsonConvert.DeserializeObject(requestBody);
24+
25+
log.LogInformation(requestBody);
26+
27+
return new OkResult();
28+
}
29+
}
30+
}

AzureFunctionsDemo/MyInfo.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FirstName": "Sudhananda",
3+
"LastName": "Biswas",
4+
"Designation": "Jr. Software Engineer"
5+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"resourceGroupName": {
6+
"type": "string",
7+
"defaultValue": "MadCoderAzureFunctionsDemoResourceGroup",
8+
"metadata": {
9+
"_parameterType": "resourceGroup",
10+
"description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
11+
}
12+
},
13+
"resourceGroupLocation": {
14+
"type": "string",
15+
"defaultValue": "centralindia",
16+
"metadata": {
17+
"_parameterType": "location",
18+
"description": "Location of the resource group. Resource groups could have different location than resources."
19+
}
20+
},
21+
"resourceLocation": {
22+
"type": "string",
23+
"defaultValue": "[parameters('resourceGroupLocation')]",
24+
"metadata": {
25+
"_parameterType": "location",
26+
"description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
27+
}
28+
}
29+
},
30+
"resources": [
31+
{
32+
"type": "Microsoft.Resources/resourceGroups",
33+
"name": "[parameters('resourceGroupName')]",
34+
"location": "[parameters('resourceGroupLocation')]",
35+
"apiVersion": "2019-10-01"
36+
},
37+
{
38+
"type": "Microsoft.Resources/deployments",
39+
"name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('AzureFunctionsDemo', subscription().subscriptionId)))]",
40+
"resourceGroup": "[parameters('resourceGroupName')]",
41+
"apiVersion": "2019-10-01",
42+
"dependsOn": [
43+
"[parameters('resourceGroupName')]"
44+
],
45+
"properties": {
46+
"mode": "Incremental",
47+
"template": {
48+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
49+
"contentVersion": "1.0.0.0",
50+
"resources": [
51+
{
52+
"name": "AzureFunctionsDemo",
53+
"type": "microsoft.insights/components",
54+
"location": "[parameters('resourceLocation')]",
55+
"kind": "web",
56+
"properties": {},
57+
"apiVersion": "2015-05-01"
58+
}
59+
]
60+
}
61+
}
62+
}
63+
],
64+
"metadata": {
65+
"_dependencyType": "appInsights.azure"
66+
}
67+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"resourceGroupName": {
6+
"type": "string",
7+
"defaultValue": "MadCoderAzureFunctionsDemoResourceGroup",
8+
"metadata": {
9+
"_parameterType": "resourceGroup",
10+
"description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
11+
}
12+
},
13+
"resourceGroupLocation": {
14+
"type": "string",
15+
"defaultValue": "centralindia",
16+
"metadata": {
17+
"_parameterType": "location",
18+
"description": "Location of the resource group. Resource groups could have different location than resources."
19+
}
20+
},
21+
"resourceLocation": {
22+
"type": "string",
23+
"defaultValue": "[parameters('resourceGroupLocation')]",
24+
"metadata": {
25+
"_parameterType": "location",
26+
"description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
27+
}
28+
}
29+
},
30+
"resources": [
31+
{
32+
"type": "Microsoft.Resources/resourceGroups",
33+
"name": "[parameters('resourceGroupName')]",
34+
"location": "[parameters('resourceGroupLocation')]",
35+
"apiVersion": "2019-10-01"
36+
},
37+
{
38+
"type": "Microsoft.Resources/deployments",
39+
"name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('mcoderazurefunctionsdemo', subscription().subscriptionId)))]",
40+
"resourceGroup": "[parameters('resourceGroupName')]",
41+
"apiVersion": "2019-10-01",
42+
"dependsOn": [
43+
"[parameters('resourceGroupName')]"
44+
],
45+
"properties": {
46+
"mode": "Incremental",
47+
"template": {
48+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
49+
"contentVersion": "1.0.0.0",
50+
"resources": [
51+
{
52+
"sku": {
53+
"name": "Standard_LRS",
54+
"tier": "Standard"
55+
},
56+
"kind": "Storage",
57+
"name": "mcoderazurefunctionsdemo",
58+
"type": "Microsoft.Storage/storageAccounts",
59+
"location": "[parameters('resourceLocation')]",
60+
"apiVersion": "2017-10-01"
61+
}
62+
]
63+
}
64+
}
65+
}
66+
],
67+
"metadata": {
68+
"_dependencyType": "storage.azure"
69+
}
70+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"dependencies": {
3+
"storage1": {
4+
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Storage/storageAccounts/mcoderazurefunctionsdemo",
5+
"type": "storage.azure",
6+
"connectionId": "AzureWebJobsStorage"
7+
},
8+
"appInsights1": {
9+
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourcegroups/[parameters('resourceGroupName')]/providers/Microsoft.Insights/components/AzureFunctionsDemo",
10+
"type": "appInsights.azure",
11+
"connectionId": "APPINSIGHTS_CONNECTIONSTRING",
12+
"secretStore": "AzureAppSettings"
13+
}
14+
}
15+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"dependencies": {
3-
"appInsights1": {
4-
"type": "appInsights"
5-
},
63
"storage1": {
74
"type": "storage",
85
"connectionId": "AzureWebJobsStorage"
6+
},
7+
"appInsights1": {
8+
"type": "appInsights",
9+
"connectionId": "APPINSIGHTS_CONNECTIONSTRING"
910
}
1011
}
1112
}

0 commit comments

Comments
 (0)