-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup-Environment.ps1
68 lines (59 loc) · 2.63 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 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" -SkipInfrastructure $false
.NOTES
Author: James Croft
#>
param
(
[Parameter(Mandatory = $true)]
[string]$DeploymentName,
[Parameter(Mandatory = $true)]
[string]$Location,
[Parameter(Mandatory = $true)]
[string]$SkipInfrastructure
)
function Set-ConfigurationFileVariable($configurationFile, $variableName, $variableValue) {
if (Select-String -Path $configurationFile -Pattern $variableName) {
(Get-Content $configurationFile) | Foreach-Object {
$_ -replace "$variableName = .*", "$variableName = $variableValue"
} | Set-Content $configurationFile
}
else {
Add-Content -Path $configurationFile -value "$variableName = $variableValue"
}
}
Write-Host "Starting environment setup..."
if ($SkipInfrastructure -eq '$false' -or -not (Test-Path -Path './infra/InfrastructureOutputs.json')) {
Write-Host "Deploying infrastructure..."
$InfrastructureOutputs = (./infra/Deploy-Infrastructure.ps1 `
-DeploymentName $DeploymentName `
-Location $Location)
}
else {
Write-Host "Skipping infrastructure deployment. Using existing outputs..."
$InfrastructureOutputs = Get-Content -Path './infra/InfrastructureOutputs.json' -Raw | ConvertFrom-Json
}
if (-not $InfrastructureOutputs) {
Write-Error "Infrastructure deployment outputs are not available. Exiting..."
exit 1
}
$ResourceGroupName = $InfrastructureOutputs.resourceGroupInfo.value.name
$OpenAIEndpoint = $InfrastructureOutputs.aiModelsInfo.value.openAIEndpoint
$Gpt4oModelDeploymentName = $InfrastructureOutputs.aiModelsInfo.value.gpt4oModelDeploymentName
Write-Host "Updating local settings..."
$ConfigurationFile = './src/StructuredOutputs/.env'
if (-not (Test-Path -Path $ConfigurationFile)) {
New-Item -Path $ConfigurationFile -ItemType File
}
Set-ConfigurationFileVariable -configurationFile $ConfigurationFile -variableName 'RESOURCE_GROUP_NAME' -variableValue $ResourceGroupName
Set-ConfigurationFileVariable -configurationFile $ConfigurationFile -variableName 'OPENAI_ENDPOINT' -variableValue $OpenAIEndpoint
Set-ConfigurationFileVariable -configurationFile $ConfigurationFile -variableName 'GPT4O_MODEL_DEPLOYMENT_NAME' -variableValue $Gpt4oModelDeploymentName