Skip to content

Commit a4127d8

Browse files
Adding Azure Functions Support
1 parent 9946335 commit a4127d8

File tree

8 files changed

+165
-0
lines changed

8 files changed

+165
-0
lines changed

PSModuleDevelopment/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22
##
3+
- Upd: Template: PSFProject added Azure Functions Project CI/CD integration
4+
5+
## 2.2.6.62 (April 30th, 2019)
36
- New: Get-PSMDArgumentCompleter - Lists registered argument completers on PS5+
47
- New: Template: PSFLoggingProvider - Creates a custom logfile logging provider for module specific logging.
58
- Upd: Template: PSFTest - Adding test against module tags with whitespace
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "2.0"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"IsEncrypted": false,
3+
"Values": {
4+
"FUNCTIONS_WORKER_RUNTIME": "powershell",
5+
"AzureWebJobsStorage": "--connection string for storage account---"
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<#
2+
This is the globl profile file for the Azure Function.
3+
This file will have been executed first, before any function runs.
4+
Use this to create a common execution environment,
5+
but keep in mind that the profile execution time is added to the function startup time for ALL functions.
6+
#>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Azure Function Resources
2+
3+
This folder is used to store Azure Function specific meta data and resources.
4+
5+
This folder is also used to allow the user to easily create a custom function-specific configuration, for exanmple in order to change the trigger settings.
6+
7+
To specify custom, 'Per Function' configuration json, just place the desired configuration file as 'functionname.json' into this folder (it does not matter if it is the PowerShell function name or the condensed version used for publishing on Azure).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Import-Module "$PSScriptRoot\Modules\þnameþ\þnameþ.psd1" -Scope Global
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Setting up the release pipeline:
2+
3+
## Preliminary
4+
5+
Setting up a release pipeline, set the trigger to do continuous integration against the master branch only.
6+
In Stage 1 set up a tasksequence:
7+
8+
## 1) PowerShell Task: Prerequisites
9+
10+
Have it execute `vsts-prerequisites.ps1`
11+
12+
## 2) PowerShell Task: Validate
13+
14+
Have it execute `vsts-prerequisites.ps1`
15+
16+
## 3) PowerShell Task: Build
17+
18+
Have it execute `vsts-build.ps1`.
19+
The task requires two parameters:
20+
21+
- `-LocalRepo`
22+
- `-WorkingDirectory $(System.DefaultWorkingDirectory)/_þnameþ`
23+
24+
## 4) Publish Test Results
25+
26+
Configure task to pick up nunit type of tests (rather than the default junit).
27+
Configure task to execute, even if previous steps failed or the task sequence was cancelled.
28+
29+
## 5) PowerShell Task: Package Function
30+
31+
Have it execute `vsts-packageFunction.ps1`
32+
33+
## 6) Azure Function AppDeploy
34+
35+
Configure to publish to the correct function app.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
2+
<#
3+
.SYNOPSIS
4+
Packages a Azure Functions project, ready to release.
5+
6+
.DESCRIPTION
7+
Packages a Azure Functions project, ready to release.
8+
Should be part of the release pipeline, after ensuring validation.
9+
10+
Look into the 'AzureFunctionRest' template for generating functions for the module if you do.
11+
12+
.PARAMETER WorkingDirectory
13+
The root folder to work from.
14+
15+
.PARAMETER Repository
16+
The name of the repository to use for gathering dependencies from.
17+
#>
18+
param (
19+
$WorkingDirectory = "$($env:SYSTEM_DEFAULTWORKINGDIRECTORY)\_þnameþ",
20+
21+
$Repository = 'PSGallery'
22+
)
23+
24+
$moduleName = 'þnameþ'
25+
26+
# Prepare Paths
27+
Write-PSFMessage -Level Host -Message "Creating working folders"
28+
$moduleRoot = Join-Path -Path $WorkingDirectory -ChildPath 'publish'
29+
$workingRoot = New-Item -Path $WorkingDirectory -Name 'working' -ItemType Directory
30+
$modulesFolder = New-Item -Path $workingRoot.FullName -Name Modules -ItemType Directory
31+
32+
# Fill out the modules folder
33+
Write-PSFMessage -Level Host -Message "Transfering built module data into working directory"
34+
Copy-Item -Path "$moduleRoot\$moduleName" -Destination $modulesFolder.FullName -Recurse -Force
35+
foreach ($dependency in (Import-PowerShellDataFile -Path "$moduleRoot\$moduleName\$moduleName.psd1").RequiredModules)
36+
{
37+
$param = @{
38+
Repository = $Repository
39+
Name = $dependency.ModuleName
40+
Path = $modulesFolder.FullName
41+
}
42+
if ($dependency -is [string]) { $param['Name'] = $dependency }
43+
if ($dependency.RequiredVersion)
44+
{
45+
$param['RequiredVersion'] = $dependency.RequiredVersion
46+
}
47+
Write-PSFMessage -Level Host -Message "Preparing Dependency: $($param['Name'])"
48+
Save-Module @param
49+
}
50+
51+
# Generate function configuration
52+
Write-PSFMessage -Level Host -Message 'Generating function configuration'
53+
foreach ($functionName in (Get-ChildItem -Path "$($moduleRoot)\$moduleName\functions" -Recurse -Filter '*.ps1'))
54+
{
55+
Write-PSFMessage -Level Host -Message " Processing function: $functionName"
56+
$condensedName = $functionName.BaseName -replace '-', ''
57+
$functionFolder = New-Item -Path $workingRoot.FullName -Name $condensedName -ItemType Directory
58+
59+
Set-Content -Path "$($functionFolder.FullName)\function.json" -Value @"
60+
{
61+
"entryPoint": "$($functionName.BaseName)",
62+
"scriptFile": "../Modules/$($moduleName)/$($moduleName).psm1",
63+
"bindings": [
64+
{
65+
"authLevel": "function",
66+
"type": "httpTrigger",
67+
"direction": "in",
68+
"name": "Request",
69+
"methods": [
70+
"get",
71+
"post"
72+
]
73+
},
74+
{
75+
"type": "http",
76+
"direction": "out",
77+
"name": "Response"
78+
}
79+
],
80+
"disabled": false
81+
}
82+
"@
83+
# Implement overrides where specified by the user
84+
if (Test-Path -Path "$($WorkingDirectory)\azFunctionResources\$($functionName.BaseName).json")
85+
{
86+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\$($functionName.BaseName).json" -Destination "$($functionFolder.FullName)\function.json" -Force
87+
}
88+
if (Test-Path -Path "$($WorkingDirectory)\azFunctionResources\$($condensedName).json")
89+
{
90+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\$($condensedName).json" -Destination "$($functionFolder.FullName)\function.json" -Force
91+
}
92+
}
93+
94+
# Transfer common files
95+
Write-PSFMessage -Level Host -Message "Transfering core function data"
96+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\host.json" -Destination "$($workingroot.FullName)\"
97+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\local.settings.json" -Destination "$($workingroot.FullName)\"
98+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\profile.ps1" -Destination "$($workingroot.FullName)\"
99+
Copy-Item -Path "$($WorkingDirectory)\azFunctionResources\root.psm1" -Destination "$($workingroot.FullName)\"
100+
101+
# Zip It
102+
Write-PSFMessage -Level Host -Message "Creating function archive in '$($WorkingDirectory)\$moduleName.zip'"
103+
Compress-Archive -Path "$($workingroot.FullName)\*" -DestinationPath "$($WorkingDirectory)\$moduleName.zip" -Force

0 commit comments

Comments
 (0)