Skip to content

Commit 5b20563

Browse files
refactor: Update YAML configurations and enhance service hooks for API and webapp
1 parent eacfc19 commit 5b20563

File tree

4 files changed

+111
-269
lines changed

4 files changed

+111
-269
lines changed

azure.yaml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# # yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
2-
# metadata:
3-
# template: [email protected]
4-
environment:
5-
name: conversation-knowledge-mining
6-
location: eastus
71
name: conversation-knowledge-mining
82

93
requiredVersions:
@@ -12,6 +6,42 @@ requiredVersions:
126
metadata:
137
148

9+
infra:
10+
provider: bicep
11+
path: infra
12+
module: main
13+
parameters: infra/main.parameters.json
14+
15+
services:
16+
api:
17+
project: ./src/api
18+
language: py
19+
host: appservice
20+
hooks:
21+
prepackage:
22+
windows:
23+
shell: pwsh
24+
continueOnError: false
25+
run: pwsh ../../infra/scripts/package_webapp.ps1
26+
posix:
27+
shell: sh
28+
continueOnError: false
29+
run: bash ../../infra/scripts/package_webapp.sh
30+
webapp:
31+
project: ./src/App/deploy
32+
language: js
33+
host: appservice
34+
hooks:
35+
prepackage:
36+
windows:
37+
shell: pwsh
38+
continueOnError: false
39+
run: pwsh ../../../infra/scripts/package_frontend.ps1
40+
posix:
41+
shell: sh
42+
continueOnError: false
43+
run: bash ../../../infra/scripts/package_frontend.sh
44+
1545
hooks:
1646
postprovision:
1747
windows:
@@ -32,4 +62,4 @@ hooks:
3262
echo "bash ./infra/scripts/process_sample_data.sh"
3363
shell: sh
3464
continueOnError: false
35-
interactive: true
65+
interactive: true

azure_custom.yaml

Lines changed: 57 additions & 255 deletions
Original file line numberDiff line numberDiff line change
@@ -1,278 +1,80 @@
1-
name: conversation-knowledge-mining-custom
1+
name: conversation-knowledge-mining
22

33
requiredVersions:
44
azd: ">= 1.18.0"
55

66
metadata:
77
88

9-
environment:
10-
name: conversation-knowledge-mining
11-
location: japaneast
12-
139
infra:
1410
provider: bicep
1511
path: infra
1612
module: main
1713
parameters: infra/main.parameters.json
1814

19-
hooks:
20-
preprovision:
21-
windows:
22-
shell: pwsh
23-
interactive: true
24-
continueOnError: false
25-
run: |
26-
$ErrorActionPreference = 'Stop'
27-
28-
Write-Host "[preprovision] Preparing ACR and building local images..." -ForegroundColor Cyan
29-
30-
try { az account show | Out-Null } catch { Write-Error "Azure CLI not logged in. Run 'az login' first."; exit 1 }
31-
32-
$location = $env:AZURE_LOCATION
33-
if (-not $location) { $location = 'japaneast' }
34-
$envName = $env:AZURE_ENV_NAME
35-
if (-not $envName) { $envName = 'conversation-knowledge-mining' }
36-
37-
$env:AZURE_LOCATION = $location
38-
azd env set AZURE_LOCATION $location | Out-Null
39-
$env:AZURE_ENV_NAME = $envName
40-
azd env set AZURE_ENV_NAME $envName | Out-Null
41-
42-
$acrRg = "rg-$envName-acr"
43-
if ((az group exists -n $acrRg) -ne 'true') {
44-
Write-Host "Creating resource group $acrRg in $location" -ForegroundColor Yellow
45-
az group create -n $acrRg -l $location | Out-Null
46-
}
47-
48-
$acrNameBase = 'kmcontainerreg'
49-
$acrName = $acrNameBase
50-
if ((az acr check-name --name $acrNameBase --query nameAvailable -o tsv) -ne 'true') {
51-
$suffix = Get-Random -Maximum 99999
52-
$acrName = "$acrNameBase$suffix"
53-
Write-Host "Base ACR name unavailable. Using $acrName" -ForegroundColor Yellow
54-
}
55-
56-
$acrShowName = az acr show -n $acrName -g $acrRg --only-show-errors --query name -o tsv 2>$null
57-
if ($acrShowName -ne $acrName) {
58-
Write-Host "Creating ACR $acrName" -ForegroundColor Yellow
59-
az acr create -n $acrName -g $acrRg -l $location --sku Basic --only-show-errors | Out-Null
60-
$acrServer = ''
61-
for ($i = 0; $i -lt 30; $i++) {
62-
$acrServer = az acr show -n $acrName --query loginServer -o tsv 2>$null
63-
if ($acrServer) { break }
64-
Start-Sleep -Seconds 5
65-
}
66-
if (-not $acrServer) { Write-Error "ACR $acrName did not become ready (no loginServer)"; exit 1 }
67-
}
68-
69-
az acr update -n $acrName --admin-enabled true | Out-Null
70-
$acrServer = az acr show -n $acrName --query loginServer -o tsv
71-
$acrCreds = az acr credential show -n $acrName --only-show-errors | ConvertFrom-Json
72-
if (-not $acrCreds -or -not $acrCreds.passwords -or $acrCreds.passwords.Count -lt 1) {
73-
Write-Error "ACR credentials unavailable."; exit 1
74-
}
75-
$acrUser = $acrCreds.username
76-
$acrPass = $acrCreds.passwords[0].value
77-
78-
$tag = "latest_waf_{0}" -f ((Get-Date).ToString("yyyy-MM-dd_HHmm"))
79-
$env:AZURE_ENV_IMAGETAG = $tag
80-
$env:AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT = $acrServer
81-
$env:AZURE_ENV_ACR_USERNAME = $acrUser
82-
$env:AZURE_ENV_ACR_PASSWORD = $acrPass
83-
84-
azd env set AZURE_ENV_IMAGETAG $tag | Out-Null
85-
azd env set AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT $acrServer | Out-Null
86-
azd env set AZURE_ENV_ACR_USERNAME $acrUser | Out-Null
87-
azd env set AZURE_ENV_ACR_PASSWORD $acrPass | Out-Null
88-
89-
Write-Host "Using registry: $acrServer" -ForegroundColor Cyan
90-
Write-Host "Image tag: $tag" -ForegroundColor Cyan
91-
92-
Write-Host "Building API image (km-api:$tag) via ACR Build" -ForegroundColor Yellow
93-
$repoRoot = (Get-Location).Path
94-
$apiCtx = Join-Path $repoRoot 'src\api'
95-
$apiDockerfile = Join-Path $apiCtx 'ApiApp.Dockerfile'
96-
if (-not (Test-Path $apiDockerfile)) { Write-Error "API Dockerfile not found at $apiDockerfile"; exit 1 }
97-
$apiBuildSucceeded = $true
98-
az acr build -r $acrName -t "km-api:$tag" -f $apiDockerfile $apiCtx
99-
if ($LASTEXITCODE -ne 0) { $apiBuildSucceeded = $false }
100-
if (-not $apiBuildSucceeded) {
101-
Write-Warning "ACR build failed for km-api. Falling back to local Docker build & push."
102-
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Write-Error "Docker is not installed or not in PATH for local fallback."; exit 1 }
103-
az acr login -n $acrName | Out-Null
104-
docker build -f $apiDockerfile -t "$acrServer/km-api:$tag" $apiCtx
105-
docker push "$acrServer/km-api:$tag"
106-
}
107-
108-
Write-Host "Building Frontend image (km-app:$tag) via ACR Build" -ForegroundColor Yellow
109-
$feCtx = Join-Path $repoRoot 'src\App'
110-
$feDockerfile = Join-Path $feCtx 'WebApp.Dockerfile'
111-
if (-not (Test-Path $feDockerfile)) { Write-Error "Frontend Dockerfile not found at $feDockerfile"; exit 1 }
112-
$feBuildSucceeded = $true
113-
az acr build -r $acrName -t "km-app:$tag" -f $feDockerfile $feCtx
114-
if ($LASTEXITCODE -ne 0) { $feBuildSucceeded = $false }
115-
if (-not $feBuildSucceeded) {
116-
Write-Warning "ACR build failed for km-app. Falling back to local Docker build & push."
117-
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Write-Error "Docker is not installed or not in PATH for local fallback."; exit 1 }
118-
az acr login -n $acrName | Out-Null
119-
docker build -f $feDockerfile -t "$acrServer/km-app:$tag" $feCtx
120-
docker push "$acrServer/km-app:$tag"
121-
}
122-
123-
Write-Host "[preprovision] Images built & pushed. Proceeding to provision..." -ForegroundColor Green
124-
125-
posix:
126-
shell: sh
127-
interactive: true
128-
continueOnError: false
129-
run: |
130-
set -euo pipefail
131-
echo "[preprovision] Preparing ACR and building local images..."
132-
az account show >/dev/null || { echo "Run 'az login' first"; exit 1; }
133-
: "${AZURE_LOCATION:=japaneast}"
134-
: "${AZURE_ENV_NAME:=conversation-knowledge-mining}"
135-
azd env set AZURE_LOCATION "$AZURE_LOCATION" >/dev/null
136-
azd env set AZURE_ENV_NAME "$AZURE_ENV_NAME" >/dev/null
137-
acr_rg="rg-${AZURE_ENV_NAME}-acr"
138-
az group create -n "$acr_rg" -l "$AZURE_LOCATION" >/dev/null 2>&1 || true
139-
acr_name_base="kmcontainerreg"
140-
name_ok=$(az acr check-name --name "$acr_name_base" --query nameAvailable -o tsv)
141-
if [ "$name_ok" != "true" ]; then
142-
suffix=$(printf "%05d" $(shuf -i 0-99999 -n 1))
143-
acr_name="${acr_name_base}${suffix}"
144-
echo "Base ACR name unavailable. Using $acr_name"
145-
else
146-
acr_name="$acr_name_base"
147-
fi
148-
az acr show -n "$acr_name" -g "$acr_rg" >/dev/null 2>&1 || az acr create -n "$acr_name" -g "$acr_rg" -l "$AZURE_LOCATION" --sku Basic >/dev/null
149-
az acr update -n "$acr_name" --admin-enabled true >/dev/null
150-
acr_server=$(az acr show -n "$acr_name" --query loginServer -o tsv)
151-
acr_user=$(az acr credential show -n "$acr_name" --query username -o tsv)
152-
acr_pass=$(az acr credential show -n "$acr_name" --query passwords[0].value -o tsv)
153-
tag="latest_waf_$(date +%Y-%m-%d_%H%M)"
154-
export AZURE_ENV_IMAGETAG="$tag"
155-
export AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT="$acr_server"
156-
export AZURE_ENV_ACR_USERNAME="$acr_user"
157-
export AZURE_ENV_ACR_PASSWORD="$acr_pass"
158-
azd env set AZURE_ENV_IMAGETAG "$tag" >/dev/null
159-
azd env set AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT "$acr_server" >/dev/null
160-
azd env set AZURE_ENV_ACR_USERNAME "$acr_user" >/dev/null
161-
azd env set AZURE_ENV_ACR_PASSWORD "$acr_pass" >/dev/null
162-
echo "Using registry: $acr_server"
163-
echo "Image tag: $tag"
164-
echo "Building API image (km-api:$tag) via ACR Build"
165-
api_ctx="$(pwd)/src/api"
166-
api_df="$api_ctx/ApiApp.Dockerfile"
167-
[ -f "$api_df" ] || { echo "API Dockerfile not found at $api_df"; exit 1; }
168-
if ! az acr build -r "$acr_name" -t "km-api:$tag" -f "$api_df" "$api_ctx"; then
169-
echo "ACR build failed for km-api. Falling back to local Docker build & push."
170-
command -v docker >/dev/null 2>&1 || { echo "Docker not installed for local fallback."; exit 1; }
171-
az acr login -n "$acr_name" >/dev/null
172-
docker build -f "$api_df" -t "$acr_server/km-api:$tag" "$api_ctx"
173-
docker push "$acr_server/km-api:$tag"
174-
fi
175-
176-
echo "Building Frontend image (km-app:$tag) via ACR Build"
177-
fe_ctx="$(pwd)/src/App"
178-
fe_df="$fe_ctx/WebApp.Dockerfile"
179-
[ -f "$fe_df" ] || { echo "Frontend Dockerfile not found at $fe_df"; exit 1; }
180-
if ! az acr build -r "$acr_name" -t "km-app:$tag" -f "$fe_df" "$fe_ctx"; then
181-
echo "ACR build failed for km-app. Falling back to local Docker build & push."
182-
command -v docker >/dev/null 2>&1 || { echo "Docker not installed for local fallback."; exit 1; }
183-
az acr login -n "$acr_name" >/dev/null
184-
docker build -f "$fe_df" -t "$acr_server/km-app:$tag" "$fe_ctx"
185-
docker push "$acr_server/km-app:$tag"
186-
fi
187-
echo "[preprovision] Images built & pushed. Proceeding to provision..."
15+
services:
16+
api:
17+
project: ./src/api
18+
language: py
19+
host: appservice
20+
webapp:
21+
project: ./src/App
22+
language: js
23+
host: appservice
24+
dist: ./build
25+
hooks:
26+
prepackage:
27+
windows:
28+
shell: pwsh
29+
continueOnError: false
30+
run: |
31+
Write-Host "=== React Build Starting ===" -ForegroundColor Cyan
32+
Write-Host "Current directory: $(Get-Location)" -ForegroundColor Yellow
33+
$apiUrl = azd env get-value API_APP_URL
34+
if (-not $apiUrl) {
35+
Write-Error "API_APP_URL not found. Run 'azd provision' first."
36+
exit 1
37+
}
38+
Write-Host "Setting REACT_APP_API_BASE_URL=$apiUrl" -ForegroundColor Yellow
39+
$env:REACT_APP_API_BASE_URL = $apiUrl
40+
Write-Host "Installing dependencies..." -ForegroundColor Cyan
41+
npm install
42+
Write-Host "Building React app..." -ForegroundColor Cyan
43+
npm run build
44+
Write-Host "=== React Build Complete ===" -ForegroundColor Green
45+
posix:
46+
shell: sh
47+
continueOnError: false
48+
run: |
49+
echo "=== React Build Starting ==="
50+
echo "Current directory: $(pwd)"
51+
apiUrl=$(azd env get-value API_APP_URL)
52+
if [ -z "$apiUrl" ]; then
53+
echo "ERROR: API_APP_URL not found. Run 'azd provision' first."
54+
exit 1
55+
fi
56+
echo "Setting REACT_APP_API_BASE_URL=$apiUrl"
57+
export REACT_APP_API_BASE_URL="$apiUrl"
58+
echo "Installing dependencies..."
59+
npm install
60+
echo "Building React app..."
61+
npm run build
62+
echo "=== React Build Complete ==="
18863
64+
hooks:
18965
postprovision:
19066
windows:
19167
shell: pwsh
192-
interactive: true
19368
continueOnError: false
69+
interactive: true
19470
run: |
195-
$ErrorActionPreference = 'Stop'
196-
197-
Write-Host "[postprovision] Configuring App Services to use ACR credentials..." -ForegroundColor Cyan
198-
199-
$rg = $env:RESOURCE_GROUP_NAME
200-
$acrServer = $env:AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT
201-
$acrUser = $env:AZURE_ENV_ACR_USERNAME
202-
$acrPass = $env:AZURE_ENV_ACR_PASSWORD
203-
204-
if (-not $rg) { Write-Warning "RESOURCE_GROUP_NAME not set; skipping ACR appsettings."; exit 0 }
205-
if (-not $acrServer -or -not $acrUser -or -not $acrPass) { Write-Warning "ACR env vars missing; skipping appsettings."; exit 0 }
206-
207-
$webAppName = ([uri]$env:WEB_APP_URL).Host.Split('.')[0]
208-
$apiAppName = ([uri]$env:API_APP_URL).Host.Split('.')[0]
209-
210-
foreach ($appName in @($webAppName, $apiAppName)) {
211-
if (-not $appName) { continue }
212-
Write-Host "Updating appsettings for $appName" -ForegroundColor Yellow
213-
az webapp config appsettings set -g $rg -n $appName --settings "DOCKER_REGISTRY_SERVER_URL=https://$acrServer" "DOCKER_REGISTRY_SERVER_USERNAME=$acrUser" "DOCKER_REGISTRY_SERVER_PASSWORD=$acrPass" | Out-Null
214-
}
215-
216-
# Ensure container images are updated to the freshly built tag
217-
if ($acrServer -and $env:AZURE_ENV_IMAGETAG) {
218-
$tag = $env:AZURE_ENV_IMAGETAG
219-
if ($apiAppName) {
220-
Write-Host "Setting API container image to $acrServer/km-api:$tag" -ForegroundColor Yellow
221-
az webapp config container set -g $rg -n $apiAppName --docker-custom-image-name "$acrServer/km-api:$tag" | Out-Null
222-
az webapp restart -g $rg -n $apiAppName | Out-Null
223-
$apiFx = az webapp config container show -g $rg -n $apiAppName --query linuxFxVersion -o tsv
224-
Write-Host "API linuxFxVersion: $apiFx" -ForegroundColor Green
225-
}
226-
if ($webAppName) {
227-
Write-Host "Setting Web container image to $acrServer/km-app:$tag" -ForegroundColor Yellow
228-
az webapp config container set -g $rg -n $webAppName --docker-custom-image-name "$acrServer/km-app:$tag" | Out-Null
229-
az webapp restart -g $rg -n $webAppName | Out-Null
230-
$webFx = az webapp config container show -g $rg -n $webAppName --query linuxFxVersion -o tsv
231-
Write-Host "Web linuxFxVersion: $webFx" -ForegroundColor Green
232-
}
233-
} else {
234-
Write-Warning "AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT or AZURE_ENV_IMAGETAG missing; skipping container image update."
235-
}
236-
237-
Write-Host "[postprovision] App Services configured for private ACR." -ForegroundColor Green
238-
71+
Write-Host "Web app URL: $env:WEB_APP_URL" -ForegroundColor Cyan
72+
Write-Host "`nRun: bash ./infra/scripts/process_sample_data.sh" -ForegroundColor Yellow
23973
posix:
24074
shell: sh
241-
interactive: true
24275
continueOnError: false
76+
interactive: true
24377
run: |
244-
set -euo pipefail
245-
echo "[postprovision] Configuring App Services to use ACR credentials..."
246-
rg="${RESOURCE_GROUP_NAME:-}"
247-
acr_server="${AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT:-}"
248-
acr_user="${AZURE_ENV_ACR_USERNAME:-}"
249-
acr_pass="${AZURE_ENV_ACR_PASSWORD:-}"
250-
[ -z "$rg" ] && echo "RESOURCE_GROUP_NAME not set; skipping." && exit 0
251-
[ -z "$acr_server" ] || [ -z "$acr_user" ] || [ -z "$acr_pass" ] && echo "ACR env vars missing; skipping." && exit 0
252-
web_app_name=$(echo "$WEB_APP_URL" | sed -E 's#https?://([^/]+)/?.*#\1#' | cut -d'.' -f1)
253-
api_app_name=$(echo "$API_APP_URL" | sed -E 's#https?://([^/]+)/?.*#\1#' | cut -d'.' -f1)
254-
for app in "$web_app_name" "$api_app_name"; do
255-
[ -z "$app" ] && continue
256-
echo "Updating appsettings for $app"
257-
az webapp config appsettings set -g "$rg" -n "$app" --settings \
258-
DOCKER_REGISTRY_SERVER_URL="https://$acr_server" \
259-
DOCKER_REGISTRY_SERVER_USERNAME="$acr_user" \
260-
DOCKER_REGISTRY_SERVER_PASSWORD="$acr_pass" >/dev/null
261-
done
262-
# Ensure container images are updated to the freshly built tag
263-
if [ -n "$acr_server" ] && [ -n "${AZURE_ENV_IMAGETAG:-}" ]; then
264-
tag="$AZURE_ENV_IMAGETAG"
265-
if [ -n "$api_app_name" ]; then
266-
echo "Setting API container image to $acr_server/km-api:$tag"
267-
az webapp config container set -g "$rg" -n "$api_app_name" --docker-custom-image-name "$acr_server/km-api:$tag" >/dev/null
268-
az webapp restart -g "$rg" -n "$api_app_name" >/dev/null
269-
fi
270-
if [ -n "$web_app_name" ]; then
271-
echo "Setting Web container image to $acr_server/km-app:$tag"
272-
az webapp config container set -g "$rg" -n "$web_app_name" --docker-custom-image-name "$acr_server/km-app:$tag" >/dev/null
273-
az webapp restart -g "$rg" -n "$web_app_name" >/dev/null
274-
fi
275-
else
276-
echo "AZURE_ENV_CONTAINER_REGISTRY_ENDPOINT or AZURE_ENV_IMAGETAG missing; skipping container image update."
277-
fi
278-
echo "[postprovision] App Services configured for private ACR."
78+
echo "Web app URL: $WEB_APP_URL"
79+
echo ""
80+
echo "Run: bash ./infra/scripts/process_sample_data.sh"

0 commit comments

Comments
 (0)