-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeploy-App.ps1
73 lines (53 loc) · 3.03 KB
/
Deploy-App.ps1
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
<#
.SYNOPSIS
Builds and deploys the AI Document Pipeline Azure Functions app to a Container App in an existing Azure environment.
.DESCRIPTION
This script initiates the deployment of the app.bicep template to the current default Azure subscription,
determined by the Azure CLI. The infra/Deploy-Infrastructure.ps1 script must be run first to deploy the
core infrastructure to the Azure subscription required by this script.
Follow the instructions in the DeploymentGuide.md file at the root of this project to understand what this
script will deploy to your Azure subscription, and the step-by-step on how to run it.
.PARAMETER InfrastructureOutputsPath
The path to the deployments outputs file from the infra/Deploy-Infrastructure.ps1 script.
.EXAMPLE
.\Deploy-App.ps1 -InfrastructureOutputsPath "../../InfrastructureOutputs.json"
.NOTES
Author: James Croft
#>
param
(
[Parameter(Mandatory = $true)]
[string]$InfrastructureOutputsPath
)
$InfrastructureOutputs = Get-Content -Path $InfrastructureOutputsPath -Raw | ConvertFrom-Json
$Location = $InfrastructureOutputs.resourceGroupInfo.value.location
$ResourceGroupName = $InfrastructureOutputs.resourceGroupInfo.value.name
$WorkloadName = $InfrastructureOutputs.resourceGroupInfo.value.workloadName
$ContainerRegistryName = $InfrastructureOutputs.containerRegistryInfo.value.name
$CompletionModelDeploymentName = $InfrastructureOutputs.aiServicesInfo.value.modelDeploymentName
$ContainerName = "ai-document-pipeline"
$ContainerVersion = (Get-Date -Format "yyMMddHHmm")
$ContainerImageName = "${ContainerName}:${ContainerVersion}"
$AzureContainerImageName = "${ContainerRegistryName}.azurecr.io/${ContainerImageName}"
Push-Location -Path $PSScriptRoot
Write-Host "Starting ${ContainerName} deployment..."
az --version
Write-Host "Building ${ContainerImageName} image..."
az acr login --name $ContainerRegistryName
docker build -t $ContainerImageName -f ../../../src/AIDocumentPipeline/Dockerfile ../../../src/AIDocumentPipeline/.
Write-Host "Pushing ${ContainerImageName} image to Azure..."
docker tag $ContainerImageName $AzureContainerImageName
docker push $AzureContainerImageName
Write-Host "Deploying Azure Container Apps for ${ContainerName}..."
$DeploymentOutputs = (az deployment group create --name ai-document-pipeline-app --resource-group $ResourceGroupName --template-file './app.bicep' `
--parameters '../../main.parameters.json' `
--parameters workloadName=$WorkloadName `
--parameters location=$Location `
--parameters containerImageName=$ContainerImageName `
--parameters openAICompletionModelName=$CompletionModelDeploymentName `
--query properties.outputs -o json) | ConvertFrom-Json
$DeploymentOutputs | ConvertTo-Json | Out-File -FilePath './AppOutputs.json' -Encoding utf8
Write-Host "Cleaning up old ${ContainerName} images in Azure Container Registry..."
az acr run --cmd "acr purge --filter '${ContainerName}:.*' --untagged --ago 1h" --registry $ContainerRegistryName /dev/null
Pop-Location
return $DeploymentOutputs