-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup-Environment.ps1
68 lines (59 loc) · 2.46 KB
/
Setup-Environment.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
<#
.SYNOPSIS
Deploys the infrastructure and applications required to run the solution.
.PARAMETER DeploymentName
The name of the deployment.
.PARAMETER Location
The location of the deployment.
.PARAMETER IsLocal
Whether the deployment is for a local development environment or complete Azure deployment.
.PARAMETER SkipInfrastructure
Whether to skip the infrastructure deployment. Requires InfrastructureOutputs.json to exist in the infra directory.
.EXAMPLE
.\Setup-Environment.ps1 -DeploymentName 'my-deployment' -Location 'eastus' -IsLocal $true -SkipInfrastructure $false
.NOTES
Author: James Croft
#>
param
(
[Parameter(Mandatory = $true)]
[string]$DeploymentName,
[Parameter(Mandatory = $true)]
[string]$Location,
[Parameter(Mandatory = $true)]
[string]$IsLocal,
[Parameter(Mandatory = $true)]
[string]$SkipInfrastructure
)
Write-Host "Starting environment setup..."
if ($SkipInfrastructure -eq '$false' || -not (Test-Path -Path './infra/InfrastructureOutputs.json')) {
Write-Host "Deploying infrastructure..."
$InfrastructureOutputs = (./infra/Deploy-Infrastructure.ps1 `
-DeploymentName $DeploymentName `
-Location $Location `
-ErrorAction Stop)
}
else {
Write-Host "Skipping infrastructure deployment. Using existing outputs..."
$InfrastructureOutputs = Get-Content -Path './infra/InfrastructureOutputs.json' -Raw | ConvertFrom-Json
}
$OpenAIEndpoint = $InfrastructureOutputs.outputs.value.openAIEndpoint
$OpenAIVisionCompletionDeployment = $InfrastructureOutputs.outputs.value.gpt4oDeploymentName
$StorageAccountName = $InfrastructureOutputs.outputs.value.storageAccountName
Write-Host "Updating local settings..."
$LocalSettingsPath = './src/AIDocumentPipeline/local.settings.json'
$LocalSettings = Get-Content -Path $LocalSettingsPath -Raw | ConvertFrom-Json
$LocalSettings.Values.OPENAI_ENDPOINT = $OpenAIEndpoint
$LocalSettings.Values.OPENAI_VISION_COMPLETION_DEPLOYMENT = $OpenAIVisionCompletionDeployment
$LocalSettings.Values.INVOICES_STORAGE_ACCOUNT_NAME = $StorageAccountName
$LocalSettings | ConvertTo-Json | Out-File -FilePath $LocalSettingsPath -Encoding utf8
if ($IsLocal -eq '$true') {
Write-Host "Starting local environment..."
docker-compose up
}
else {
Write-Host "Deploying AI Document Pipeline app..."
./infra/apps/AIDocumentPipeline/Deploy-App.ps1 `
-InfrastructureOutputsPath './infra/InfrastructureOutputs.json' `
-ErrorAction Stop
}