Skip to content

Commit 5d9c2d5

Browse files
authored
Merge pull request #12 from Azure-Samples/feat/avatar-to-sk
[FIX] Fixing Avatar
2 parents ea8947a + 18dcd84 commit 5d9c2d5

File tree

22 files changed

+978
-264
lines changed

22 files changed

+978
-264
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (-not $imageVersion) {
1414
Set-Location -Path $gitRepositoryAddress
1515

1616
# Read the .env file. You might want to add this.
17-
$envFile = Get-Content "src\backend\.env"
17+
$envFile = Get-Content "src\.env"
1818

1919
# # Extract the username and password from the .env file
2020
$usernameLine = $envFile | Where-Object { $_ -match "^ACR_USER = " }

.conf/infra.ps1

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
# Caminho do .env
4+
$envFilePath = "src\.env"
5+
6+
# Função para extrair variável do .env
7+
function Get-EnvValue($name) {
8+
return (Get-Content $envFilePath | Where-Object { $_ -match "^$name\s*=" }) -replace '.*=\s*"?([^"]+)"?', '$1'
9+
}
10+
11+
# Variáveis do .env
12+
$sub = Get-EnvValue 'SUBSCRIPTION_ID'
13+
$location = Get-EnvValue 'LOCATION'
14+
$rgName = Get-EnvValue 'RESOURCE_GROUP'
15+
$vnetName = Get-EnvValue 'VNET_NAME'
16+
$subnetName = Get-EnvValue 'MANAGEMENT_SUBNET_NAME'
17+
18+
# Definir subscription atual
19+
Write-Host "✅ Subscription: $sub"
20+
az account set --subscription $sub
21+
22+
# Lista de contas de IA e seus parâmetros de restauração
23+
$accounts = @(
24+
@{ Name = Get-EnvValue 'AZURE_OPENAI_ACCOUNT_NAME'; Param = 'openAiRestore' },
25+
@{ Name = Get-EnvValue 'AZURE_SPEECH_ACCOUNT_NAME'; Param = 'speechRestore' },
26+
@{ Name = Get-EnvValue 'AZURE_VISION_ACCOUNT_NAME'; Param = 'visionRestore' },
27+
@{ Name = Get-EnvValue 'AZURE_DOC_ACCOUNT_NAME'; Param = 'docRestore' }
28+
)
29+
30+
# Detecta e configura restore
31+
$restoreParams = @{}
32+
33+
foreach ($acct in $accounts) {
34+
$name = $acct.Name
35+
$param = $acct.Param
36+
37+
# Obter todos os soft-deletados na região e filtrar pelo nome
38+
$deleted = az cognitiveservices account list-deleted `
39+
--output json | ConvertFrom-Json
40+
41+
$match = $deleted | Where-Object { $_.name -eq $name }
42+
43+
if ($match) {
44+
Write-Host "🔁 Soft-deleted: $name. Adding '$param=true'"
45+
$restoreParams[$param] = $true
46+
} else {
47+
$restoreParams[$param] = $false
48+
}
49+
}
50+
51+
Write-Host "🔧 Parâmetros de restauração: $($restoreParams | Out-String)"
52+
53+
# Garante que endpoint esteja no subnet
54+
function Set-CognitiveServicesEndpoint {
55+
Write-Host "🔧 Verificando endpoint Microsoft.CognitiveServices..."
56+
$endpoints = az network vnet subnet show `
57+
--resource-group $rgName `
58+
--vnet-name $vnetName `
59+
--name $subnetName `
60+
--query "serviceEndpoints[].service" -o tsv
61+
62+
if (-not ($endpoints -contains 'Microsoft.CognitiveServices')) {
63+
Write-Host "🔁 Adicionando endpoint Microsoft.CognitiveServices..."
64+
az network vnet subnet update `
65+
--resource-group $rgName `
66+
--vnet-name $vnetName `
67+
--name $subnetName `
68+
--service-endpoints Microsoft.CognitiveServices | Out-Null
69+
}
70+
}
71+
72+
# Inicia deploy principal
73+
function Deploy-MainTemplate {
74+
$paramArgs = @("rgName=$rgName", "location=$location")
75+
foreach ($kvp in $restoreParams.GetEnumerator()) {
76+
$paramArgs += "$($kvp.Key)=$($kvp.Value)"
77+
}
78+
79+
# Montar a string de parâmetros
80+
$joinedParams = $paramArgs -join ' '
81+
82+
# Montar e imprimir o comando antes de executar
83+
$command = "az deployment sub create --location $location --template-file .\infra\main.bicep --parameters $joinedParams --verbose --debug"
84+
Write-Host "🔧 Executando comando:"
85+
Write-Host $command
86+
87+
# Capturar a saída do comando
88+
$output = & az deployment sub create `
89+
--location $location `
90+
--template-file ".\infra\main.bicep" `
91+
--parameters $paramArgs
92+
93+
return $output
94+
}
95+
96+
try {
97+
Write-Host "🚀 Iniciando deploy da infraestrutura principal..."
98+
Set-CognitiveServicesEndpoint
99+
$result = Deploy-MainTemplate
100+
Write-Host "🔧 Resultado do deploy: $($result | Out-String)"
101+
if (($null -ne $result | Out-String | Select-String 'ERROR')) {
102+
throw "❌ Deploy returned ERROR in output"
103+
}
104+
Write-Host "✅ Deploy finalizado com sucesso!"
105+
} catch {
106+
Write-Host "❌ Falha no deploy: $_"
107+
Write-Host "📋 Listando operações com erro..."
108+
az deployment operation sub list `
109+
--name main `
110+
--query "[?properties.provisioningState=='Failed']" `
111+
--output table
112+
exit 1
113+
} finally {
114+
Write-Host "⚙️ Script finalizado em $(Get-Date -Format o)"
115+
}

.conf/linters copy.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$rootFolder = (Get-Item -Path "$PSScriptRoot\..\src").FullName
2+
try {
3+
Set-Location -Path $rootFolder
4+
} catch {
5+
Write-Host "Error changing directory: $_"
6+
}
7+
8+
$configurationFile = Join-Path -Path $rootFolder -ChildPath "\pyproject.toml"
9+
$appDirectory = Join-Path -Path $rootFolder -ChildPath "\app"
10+
11+
isort --sp=$configurationFile $rootFolder
12+
black --config $configurationFile $rootFolder
13+
pylint --rcfile=$configurationFile $appDirectory
File renamed without changes.

.py-conf/export-requirements.ps1

Lines changed: 0 additions & 8 deletions
This file was deleted.

infra/main.bicep

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
//-----------------------------------------------
2+
// main.bicep – subscription‑scope entry point
3+
//-----------------------------------------------
4+
targetScope = 'subscription'
5+
6+
/*───────────────────────────
7+
1. Core deployment inputs
8+
───────────────────────────*/
9+
@minLength(1)
10+
@maxLength(64)
11+
param rgName string
12+
13+
@allowed([
14+
'eastus', 'eastus2', 'westus', 'westus2', 'westcentralus'
15+
'northeurope', 'francecentral', 'switzerlandnorth', 'switzerlandwest'
16+
'uksouth', 'australiaeast', 'eastasia', 'southeastasia'
17+
'centralindia', 'jioindiawest', 'japanwest', 'koreacentral'
18+
])
19+
param location string
20+
21+
@allowed([ 'dev', 'test', 'prod' ])
22+
param environment string = 'dev'
23+
24+
param keyVaultName string = 'tutor-kv'
25+
param subscriptionId string = subscription().subscriptionId
26+
27+
/* ACR settings */
28+
@minLength(5)
29+
@maxLength(50)
30+
param acrName string = 'tutoracr'
31+
var acrLoginServer = '${acrName}.azurecr.io'
32+
33+
/*--------- OpenAI ---------*/
34+
param openAiAccountName string = 'tutor-openai'
35+
param openAiCustomDomain string = 'openai-ctr'
36+
param deployOpenAiAccount bool = true
37+
param openAiRestore bool = false
38+
param openAiModelDeployment string = 'tutor-4o'
39+
40+
@allowed([ 'gpt-4o', 'gpt-4o-mini' ])
41+
param openAiModelName string = 'gpt-4o'
42+
param openAiModelVersion string = '2024-11-20'
43+
param openAiCapacity int = 80
44+
45+
param speechAccountName string = 'tutor-speech'
46+
param speechCustomDomain string = 'speech-ctr'
47+
param deploySpeechAccount bool = true
48+
param speechRestore bool = false
49+
50+
51+
/*──────────── Resources ────────────*/
52+
resource tutorRG 'Microsoft.Resources/resourceGroups@2021-04-01' = {
53+
name: rgName
54+
location: location
55+
}
56+
57+
resource keyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = {
58+
scope: tutorRG
59+
name: keyVaultName
60+
}
61+
62+
/*──────── VNet (returns containerAppsSubnetId) ────────*/
63+
module vnetModule './modules/vnet.bicep' = {
64+
name: 'deployVnet'
65+
scope: tutorRG
66+
params: {
67+
location: location
68+
envType: environment
69+
keyVaultReference: keyVault.name
70+
}
71+
}
72+
73+
/*──────── Log Analytics ────────*/
74+
module logAnalyticsModule './modules/loga.bicep' = {
75+
name: 'deployLogAnalytics'
76+
scope: tutorRG
77+
params: {
78+
workspaceName: 'tutor-loganalytics'
79+
location: location
80+
retentionInDays: 30
81+
environment: environment
82+
keyVaultReference: keyVault.name
83+
subscriptionId: subscriptionId
84+
}
85+
}
86+
87+
/*──────── ACR ────────*/
88+
module acrModule './modules/acr.bicep' = {
89+
name: 'deployContainerRegistry'
90+
scope: tutorRG
91+
params: {
92+
location: location
93+
environment: environment
94+
keyVaultReference: keyVault.name
95+
subscriptionId: subscriptionId
96+
acrName: acrName
97+
sku: 'Standard'
98+
}
99+
}
100+
101+
/*──────── Cosmos DB (unchanged) ────────*/
102+
module cosmosDbModule './modules/cosmos.bicep' = {
103+
name: 'deployCosmosDb'
104+
scope: tutorRG
105+
params: {
106+
cosmosDbName: 'tutor-cosmosdb'
107+
location: location
108+
resourceGroupLocation: tutorRG.location
109+
environment: environment
110+
keyVaultReference: keyVault.name
111+
subscriptionId: subscriptionId
112+
}
113+
}
114+
115+
/*──────── Container Apps env + first app ────────*/
116+
module containerAppsEnvModule './modules/aca.bicep' = {
117+
name: 'deployContainerAppsEnv'
118+
scope: tutorRG
119+
params: {
120+
location: location
121+
infrastructureSubnetId: vnetModule.outputs.containerAppsSubnetId
122+
logAnalyticsWorkspaceName: logAnalyticsModule.outputs.workspaceName
123+
envType: environment
124+
containerAppName: 'tutor-api'
125+
containerAppImage: '${acrLoginServer}/api:latest'
126+
acrLoginServer: acrLoginServer
127+
}
128+
}
129+
130+
/*──────── Azure OpenAI ────────*/
131+
module openAiModule './modules/aoai.bicep' = {
132+
name: 'deployAzureOpenAI'
133+
scope: tutorRG
134+
params: {
135+
aiServiceAccountName: openAiAccountName
136+
deployAccount: deployOpenAiAccount
137+
restore: openAiRestore
138+
location: location
139+
customSubDomainName: openAiCustomDomain
140+
subnetId: vnetModule.outputs.containerAppsSubnetId
141+
modelDeploymentName: openAiModelDeployment
142+
modelName: openAiModelName
143+
modelVersion: openAiModelVersion
144+
capacity: openAiCapacity
145+
tags: { project: 'TheTutor', environment: environment }
146+
}
147+
}
148+
149+
/*──────── Speech Services ────────*/
150+
module speechModule './modules/speech.bicep' = {
151+
name: 'deploySpeech'
152+
scope: tutorRG
153+
params: {
154+
speechAccountName: speechAccountName
155+
deployAccount: deploySpeechAccount
156+
restore: speechRestore
157+
location: location
158+
customSubDomainName: speechCustomDomain
159+
subnetId: vnetModule.outputs.openAiSubnetId
160+
tags: { project: 'TheTutor', environment: environment }
161+
}
162+
}
163+
164+
// =================================================================
165+
// Module: Azure Static Web App (enforces HTTPS and CORS policies)
166+
// =================================================================
167+
module staticWebApp './modules/staticwapp.bicep' = {
168+
name: 'deployStaticWebApp'
169+
scope: tutorRG
170+
params: {
171+
location: location
172+
repositoryUrl: 'https://github.com/Azure-Samples/tutor.git'
173+
environment: environment
174+
keyVaultReference: keyVault.name
175+
}
176+
}

0 commit comments

Comments
 (0)