forked from microsoft/chat-copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-plugins.ps1
More file actions
113 lines (97 loc) · 3.63 KB
/
Copy pathdeploy-plugins.ps1
File metadata and controls
113 lines (97 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<#
.SYNOPSIS
Deploy CopilotChat's Plugins to Azure
#>
param(
[Parameter(Mandatory)]
[string]
# Subscription to which to make the deployment
$Subscription,
[Parameter(Mandatory)]
[string]
# Resource group to which to make the deployment
$ResourceGroupName,
[Parameter(Mandatory)]
[string]
# Name of the previously deployed Azure deployment
$DeploymentName,
[string]
# Path that contains the plugin packages to deploy
$PackagesPath = "$PSScriptRoot/out/plugins"
)
# Ensure $PackageFilePath exists
if (!(Test-Path $PackagesPath)) {
Write-Error "Package file '$PackagesPath' does not exist. Have you run 'package-plugins.ps1' yet?"
exit 1
}
# Get all the plugin packages
$pluginPackages = Get-ChildItem -Path $PackagesPath -Filter *.zip
if ($null -eq $pluginPackages) {
Write-Error "No plugin packages found in '$PackagesPath'. Have you run 'package-plugins.ps1' yet?"
exit 1
}
az account show --output none
if ($LASTEXITCODE -ne 0) {
Write-Host "Log into your Azure account"
az login --output none
}
az account set -s $Subscription
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Host "Getting Azure Function resource names"
$pluginDeploymentNames = $(
az deployment group show `
--name $DeploymentName `
--resource-group $ResourceGroupName `
--output json | ConvertFrom-Json
).properties.outputs.pluginNames.value
Write-Host "-----Found the following Azure Function names-----"
foreach ($pluginDeploymentName in $pluginDeploymentNames) {
Write-Host "$pluginDeploymentName"
}
Write-Host ""
# Find the Azure Function resource name for each plugin package
# before we deploy the plugins. This can minimize the risk of
# deploying to the wrong Azure Function resource.
Write-Host "---Matching plugins to Azure Function resources---"
$pluginDeploymentMatches = @{}
foreach ($pluginPackage in $pluginPackages) {
$pluginName = $pluginPackage.BaseName
Write-Host "Looking for the resource for '$pluginName'..."
# Check if the plugin name matches any of the Azure Function names we got from the deployment output
$matchedNumber = 0
$matchedDeployment = ""
foreach ($pluginDeploymentName in $pluginDeploymentNames) {
if ($pluginDeploymentName -match "function-.*$pluginName-plugin") {
$matchedNumber++
$matchedDeployment = $pluginDeploymentName
}
}
if ($matchedNumber -eq 0) {
Write-Error "Could not find Azure Function resource name for '$pluginName'."
Write-Error "Make sure the deployed Azure Function resource name matches the plugin zip package name."
exit 1
}
if ($matchedNumber -gt 1) {
Write-Error "Found multiple Azure Function resource names for '$pluginName'."
Write-Error "Make sure the deployed Azure Function resource name matches the plugin zip package name."
exit 1
}
Write-Host "Matched Azure Function resource name '$matchedDeployment' for '$pluginName'"
$pluginDeploymentMatches.Add($pluginPackage, $matchedDeployment)
}
Write-Host ""
Write-Host "-------Deploying plugins to Azure Functions-------"
foreach ($pluginDeploymentMatches in $pluginDeploymentMatches.GetEnumerator()) {
$pluginPackage = $pluginDeploymentMatches.Key
$pluginDeploymentName = $pluginDeploymentMatches.Value
Write-Host "Deploying '$pluginPackage' to Azure Function '$pluginDeploymentName'..."
az functionapp deployment source config-zip `
--resource-group $ResourceGroupName `
--name $pluginDeploymentName `
--src $pluginPackage
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}