Skip to content

Commit f8ea214

Browse files
committed
Add Azure Bicep scaffold and GitHub Actions
1 parent 75d62ed commit f8ea214

File tree

6 files changed

+266
-2
lines changed

6 files changed

+266
-2
lines changed

.editorconfig

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
trim_trailing_whitespace = true
9+
10+
[*.{yaml,yml}]
11+
indent_size = 2
12+
indent_style = space
13+
14+
[*.bicep]
15+
indent_size = 2
16+
indent_style = space
17+
18+
[*.json]
19+
indent_size = 2
20+
indent_style = space
21+
22+
[*.cs]
23+
indent_size = 4
24+
indent_style = space
25+
insert_final_newline = true

.github/workflows/deploy.yml

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
name: Deploy Azure Functions
2+
3+
env:
4+
AZURE_FUNCTIONAPP_NAME: nfderpidlfunc
5+
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
6+
DOTNET_VERSION: '6.*'
7+
Location: 'southcentralus'
8+
ResourceGroupName: 'nf-derpidl-dev'
9+
DEV_ResourceGroupName: 'nf-derpidl-dev'
10+
PRD_ResourceGroupName: 'nf-derpidl-new-prd'
11+
12+
on:
13+
push:
14+
paths:
15+
- 'bicep/**'
16+
- 'src/**'
17+
- 'tests/**'
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
- name: Setup .NET
27+
uses: actions/setup-dotnet@v2
28+
with:
29+
dotnet-version: ${{ env.DOTNET_VERSION }}
30+
- name: Setup dependency caching for faster builds
31+
uses: actions/cache@v3
32+
with:
33+
path: ~/.nuget/packages
34+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-nuget-
37+
- name: Build with .NET
38+
run: dotnet build --configuration Release
39+
- name: dotnet publish
40+
run: dotnet publish -c Release -o ${{ env.DOTNET_ROOT }}/myapp
41+
- name: Upload artifact for deployment job
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: .net-app
45+
path: ${{ env.DOTNET_ROOT }}/myapp
46+
47+
bicep-development:
48+
runs-on: ubuntu-latest
49+
environment: development
50+
outputs:
51+
functionAppName: ${{ steps.bicep.outputs.functionAppName }}
52+
functionAppUrl: ${{ steps.bicep.outputs.functionAppUrl }}
53+
steps:
54+
- uses: actions/checkout@v3
55+
with:
56+
fetch-depth: 0
57+
58+
- name: Login via Azure CLI
59+
uses: azure/login@v1
60+
with:
61+
creds: ${{ secrets.AZURE_CREDENTIALS }}
62+
63+
- name: Create Resource Group
64+
run: az group create --location ${{ env.Location }} --resource-group ${{ env.ResourceGroupName }}
65+
66+
- id: bicep
67+
uses: azure/arm-deploy@v1
68+
with:
69+
scope: resourcegroup
70+
resourceGroupName: ${{ env.ResourceGroupName }}
71+
region: ${{ env.Location }}
72+
template: bicep/deploy.bicep
73+
74+
deploy-development:
75+
runs-on: ubuntu-latest
76+
environment:
77+
name: development
78+
url: ${{ needs.bicep-development.outputs.functionAppUrl }}
79+
needs: [build, bicep-development]
80+
steps:
81+
- name: Download artifact from build job
82+
uses: actions/download-artifact@v3
83+
with:
84+
name: .net-app
85+
86+
- name: Login via Azure CLI
87+
uses: azure/login@v1
88+
with:
89+
creds: ${{ secrets.AZURE_CREDENTIALS }}
90+
91+
- name: Deploy to Azure Function App
92+
id: fa
93+
uses: azure/functions-action@v1
94+
with:
95+
app-name: ${{ needs.bicep-development.outputs.functionAppName }}
96+
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
97+
98+
clean-development:
99+
runs-on: ubuntu-latest
100+
environment: clean
101+
needs: deploy-development
102+
steps:
103+
- name: Login via Azure CLI
104+
uses: azure/login@v1
105+
with:
106+
creds: ${{ secrets.AZURE_CREDENTIALS }}
107+
108+
- name: Delete Resource Group
109+
run: az group delete --resource-group ${{ env.ResourceGroupName }} --yes
110+
111+
# bicep-production:
112+
# runs-on: ubuntu-latest
113+
# environment: production
114+
# needs: [deploy-development]
115+
# outputs:
116+
# functionAppName: ${{ steps.bicep.outputs.functionAppName }}
117+
# functionAppUrl: ${{ steps.bicep.outputs.functionAppUrl }}
118+
# steps:
119+
# - uses: actions/checkout@v3
120+
# with:
121+
# fetch-depth: 0
122+
123+
# - name: Login via Azure CLI
124+
# uses: azure/login@v1
125+
# with:
126+
# creds: ${{ secrets.AZURE_CREDENTIALS }}
127+
128+
# - name: Create Resource Group
129+
# run: az group create --location ${{ env.Location }} --resource-group ${{ env.PRD_ResourceGroupName }}
130+
131+
# - id: bicep
132+
# uses: azure/arm-deploy@v1
133+
# with:
134+
# scope: resourcegroup
135+
# resourceGroupName: ${{ env.PRD_ResourceGroupName }}
136+
# region: ${{ env.Location }}
137+
# template: bicep/deploy.bicep
138+
139+
# deploy-production:
140+
# runs-on: ubuntu-latest
141+
# environment:
142+
# name: production
143+
# url: ${{ needs.bicep-production.outputs.functionAppUrl }}
144+
# needs: [build, bicep-production]
145+
# steps:
146+
# - name: Download artifact from build job
147+
# uses: actions/download-artifact@v3
148+
# with:
149+
# name: .net-app
150+
151+
# - name: Login via Azure CLI
152+
# uses: azure/login@v1
153+
# with:
154+
# creds: ${{ secrets.AZURE_CREDENTIALS }}
155+
156+
# - name: Deploy to Azure Function App
157+
# id: fa
158+
# uses: azure/functions-action@v1
159+
# with:
160+
# app-name: ${{ needs.bicep-production.outputs.functionAppName }}
161+
# package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,7 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
# VS Code
353+
.vscode
354+
!.vscode/launch.json

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 nullforce-public
3+
Copyright (c) 2022 nullforce
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# derpidl-functions
1+
# derpidl-functions

bicep/deploy.bicep

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/
2+
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/bicep-functions
3+
@allowed([
4+
'development'
5+
'production'
6+
])
7+
param environment string = 'development'
8+
param prefix string = 'nfderpidl'
9+
param location string = resourceGroup().location
10+
11+
var appUniqueString = uniqueString(resourceGroup().name)
12+
// Storage account names can't have hypens
13+
var storagePrefix = replace(prefix, '-', '')
14+
15+
var functionAppName = '${prefix}func${appUniqueString}'
16+
var functionPlanName = '${prefix}funcplan'
17+
var functionStorageName = take('${storagePrefix}storage${appUniqueString}', 24)
18+
var storageAccountConnectionString = 'DefaultEndpointsProtocol=https;AccountName=${funcappstorage.name};AccountKey=${listKeys(funcappstorage.id, '2019-06-01').keys[0].value};EndpointSuffix=core.windows.net'
19+
var tags = {
20+
'AppName': 'derpidl-functions'
21+
'Environment': environment
22+
}
23+
24+
resource hostingPlan 'Microsoft.Web/serverfarms@2021-03-01' = {
25+
name: functionPlanName
26+
location: location
27+
tags: tags
28+
sku: {
29+
name: 'Y1'
30+
tier: 'Dynamic'
31+
}
32+
}
33+
34+
// Storage account for functions app
35+
resource funcappstorage 'Microsoft.Storage/storageAccounts@2021-09-01' = {
36+
name: functionStorageName
37+
kind: 'StorageV2'
38+
location: location
39+
tags: tags
40+
sku: {
41+
name: 'Standard_LRS'
42+
}
43+
properties: {
44+
allowBlobPublicAccess: false
45+
supportsHttpsTrafficOnly: true
46+
minimumTlsVersion: 'TLS1_2'
47+
}
48+
}
49+
50+
resource funcappsettings 'Microsoft.Web/sites/config@2021-03-01' = {
51+
name: 'appsettings'
52+
parent: funcapp
53+
properties: {
54+
AzureWebJobsStorage: storageAccountConnectionString
55+
FUNCTIONS_EXTENSION_VERSION: '~4'
56+
FUNCTIONS_WORKER_RUNTIME: 'dotnet'
57+
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING: storageAccountConnectionString
58+
WEBSITE_CONTENTSHARE: '${toLower(functionAppName)}876f'
59+
}
60+
}
61+
62+
resource funcapp 'Microsoft.Web/sites@2021-03-01' = {
63+
name: functionAppName
64+
kind: 'functionapp'
65+
location: location
66+
tags: tags
67+
properties: {
68+
httpsOnly: true
69+
serverFarmId: hostingPlan.id
70+
}
71+
}
72+
73+
output functionAppName string = funcapp.name
74+
output functionAppUrl string = 'https://${funcapp.properties.defaultHostName}'

0 commit comments

Comments
 (0)