-
Notifications
You must be signed in to change notification settings - Fork 0
487 lines (428 loc) · 22.9 KB
/
continuous_delivery_qa.yml
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
name: CD QA Pipeline
on:
push:
branches:
- release/*
jobs:
setup-env-job:
if: ${{ github.repository != 'Azure/llmops-project-template' }}
runs-on: ubuntu-latest
environment: qa
outputs:
AZURE_APP_SERVICE_NAME: ${{ steps.config-env.outputs.AZURE_APP_SERVICE_NAME }}
AZURE_APP_SERVICE_PLAN_NAME: ${{ steps.config-env.outputs.AZURE_APP_SERVICE_PLAN_NAME }}
AZURE_CONTAINER_REGISTRY_NAME: ${{ steps.config-env.outputs.AZURE_CONTAINER_REGISTRY_NAME }}
AZURE_CONTAINER_REPOSITORY_NAME: ${{ steps.config-env.outputs.AZURE_CONTAINER_REPOSITORY_NAME }}
AZURE_LOCATION: ${{ steps.config-env.outputs.AZURE_LOCATION }}
AZURE_RESOURCE_GROUP: ${{ steps.config-env.outputs.AZURE_RESOURCE_GROUP }}
AZUREAI_RESOURCE_GROUP: ${{ steps.config-env.outputs.AZURE_RESOURCE_GROUP }}
AZUREAI_PROJECT_NAME: ${{ steps.config-env.outputs.AZUREAI_PROJECT_NAME }}
AZURE_SUBSCRIPTION_ID: ${{ steps.config-env.outputs.AZURE_SUBSCRIPTION_ID }}
AZURE_SEARCH_ENDPOINT: ${{ steps.config-env.outputs.AZURE_SEARCH_ENDPOINT }}
AZURE_OPENAI_CHAT_DEPLOYMENT: ${{ steps.config-env.outputs.AZURE_OPENAI_CHAT_DEPLOYMENT }}
AZURE_OPENAI_EMBEDDING_DEPLOYMENT: ${{steps.config-env.outputs.AZURE_OPENAI_EMBEDDING_DEPLOYMENT}}
AZURE_OPENAI_EMBEDDING_MODEL: ${{steps.config-env.outputs.AZURE_OPENAI_EMBEDDING_MODEL}}
AZURE_OPENAI_API_VERSION: ${{steps.config-env.outputs.AZURE_OPENAI_API_VERSION}}
AZURE_OPENAI_ENDPOINT: ${{steps.config-env.outputs.AZURE_OPENAI_ENDPOINT}}
AZURE_OPENAI_NAME: ${{steps.config-env.outputs.AZURE_OPENAI_NAME}}
PROMPTFLOW_WORKER_NUM: ${{steps.config-env.outputs.PROMPTFLOW_WORKER_NUM}}
PROMPTFLOW_SERVING_ENGINE: ${{steps.config-env.outputs.PROMPTFLOW_SERVING_ENGINE}}
steps:
- uses: actions/checkout@v4
- name: Provision qa environment
uses: ./.github/actions/config-env
id: config-env
with:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
MANUAL_PROVISIONING: ${{ vars.MANUAL_PROVISIONING }}
AZURE_DEPLOY_APP_SERVICE: true
env:
AZUREAI_PROJECT_NAME: ${{ vars.AZUREAI_PROJECT_NAME }}
AZURE_APP_SERVICE_NAME: ${{ vars.AZURE_APP_SERVICE_NAME }}
AZURE_APP_SERVICE_PLAN_NAME: ${{ vars.AZURE_APP_SERVICE_PLAN_NAME }}
AZURE_CONTAINER_REGISTRY_NAME: ${{ vars.AZURE_CONTAINER_REGISTRY_NAME }}
AZURE_CONTAINER_REPOSITORY_NAME: ${{ vars.AZURE_CONTAINER_REPOSITORY_NAME }}
AZURE_OPENAI_API_VERSION: ${{ vars.AZURE_OPENAI_API_VERSION }}
AZURE_OPENAI_CHAT_DEPLOYMENT: ${{ vars.AZURE_OPENAI_CHAT_DEPLOYMENT }}
AZURE_OPENAI_DEPLOYMENT: ${{ vars.AZURE_OPENAI_CHAT_DEPLOYMENT }}
AZURE_OPENAI_EMBEDDING_DEPLOYMENT: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT }}
AZURE_OPENAI_EMBEDDING_MODEL: ${{ vars.AZURE_OPENAI_EMBEDDING_MODEL }}
AZURE_OPENAI_ENDPOINT: ${{ vars.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_NAME: ${{ vars.AZURE_OPENAI_NAME }}
AZURE_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
AZUREAI_RESOURCE_GROUP: ${{ vars.AZURE_RESOURCE_GROUP }}
AZURE_SEARCH_ENDPOINT: ${{ vars.AZURE_SEARCH_ENDPOINT }}
LOAD_AZURE_SEARCH_SAMPLE_DATA: ${{ vars.LOAD_AZURE_SEARCH_SAMPLE_DATA }}
AZURE_SEARCH_NAME: ${{ vars.AZURE_SEARCH_NAME }}
PROMPTFLOW_SERVING_ENGINE: ${{ vars.PROMPTFLOW_SERVING_ENGINE }}
PROMPTFLOW_WORKER_NUM: ${{ vars.PROMPTFLOW_WORKER_NUM }}
AZURE_PRINCIPAL_ID: ${{ vars.AZURE_PRINCIPAL_ID }}
AZUREAI_HUB_NAME: ${{ vars.AZUREAI_HUB_NAME }}
AZURE_APP_INSIGHTS_NAME: ${{ vars.AZURE_APP_INSIGHTS_NAME }}
AZURE_KEY_VAULT_NAME: ${{ vars.AZURE_KEY_VAULT_NAME }}
AZURE_LOG_ANALYTICS_NAME: ${{ vars.AZURE_LOG_ANALYTICS_NAME }}
AZURE_STORAGE_ACCOUNT_NAME: ${{ vars.AZURE_STORAGE_ACCOUNT_NAME }}
qa-flow-evaluation:
needs: [setup-env-job]
runs-on: ubuntu-latest
environment: qa
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Login to Azure CLI
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: AI-Based quality evaluation
env:
AZURE_OPENAI_ENDPOINT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_ENDPOINT}}
AZURE_OPENAI_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_CHAT_DEPLOYMENT}}
AZUREAI_PROJECT_NAME: ${{needs.setup-env-job.outputs.AZUREAI_PROJECT_NAME}}
AZURE_OPENAI_API_VERSION: ${{needs.setup-env-job.outputs.AZURE_OPENAI_API_VERSION}}
AZURE_SUBSCRIPTION_ID: ${{needs.setup-env-job.outputs.AZURE_SUBSCRIPTION_ID}}
AZURE_RESOURCE_GROUP: ${{needs.setup-env-job.outputs.AZURE_RESOURCE_GROUP}}
AZURE_OPENAI_NAME: ${{needs.setup-env-job.outputs.AZURE_OPENAI_NAME}}
LOCATION: ${{needs.setup-env-job.outputs.AZURE_LOCATION}}
AZURE_LOCATION: ${{needs.setup-env-job.outputs.AZURE_LOCATION}}
AZURE_CONTAINER_REGISTRY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REGISTRY_NAME}}
AZURE_CONTAINER_REPOSITORY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REPOSITORY_NAME}}
AZURE_SEARCH_ENDPOINT: ${{needs.setup-env-job.outputs.AZURE_SEARCH_ENDPOINT}}
AZURE_OPENAI_CHAT_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_CHAT_DEPLOYMENT}}
AZURE_OPENAI_EMBEDDING_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_EMBEDDING_DEPLOYMENT}}
AZURE_OPENAI_EMBEDDING_MODEL: ${{needs.setup-env-job.outputs.AZURE_OPENAI_EMBEDDING_MODEL}}
PROMPTFLOW_WORKER_NUM: ${{needs.setup-env-job.outputs.PROMPTFLOW_WORKER_NUM}}
PROMPTFLOW_SERVING_ENGINE: ${{needs.setup-env-job.outputs.PROMPTFLOW_SERVING_ENGINE}}
AZURE_APP_SERVICE_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_NAME}}
AZURE_APP_SERVICE_PLAN_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_PLAN_NAME}}
run: |
echo "Run AI-Based flow evaluation"
echo "AZURE_RESOURCE_GROUP=${AZURE_RESOURCE_GROUP}"
echo "AZURE_OPENAI_NAME=${AZURE_OPENAI_NAME}"
export AZURE_OPENAI_API_KEY=$(az cognitiveservices account keys list --resource-group ${AZURE_RESOURCE_GROUP} --name ${AZURE_OPENAI_NAME} --query "key1" --output tsv)
python evaluations/qa_quality_eval.py
shell: bash
- name: Upload evaluation results
uses: actions/upload-artifact@v4
with:
name: flow-eval-results
path: qa_flow_quality_eval.json.json
qa-safety-evaluation:
needs: setup-env-job
runs-on: ubuntu-latest
environment: qa
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Login to Azure CLI
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: AI-Based safety evaluation
env:
AZUREAI_RESOURCE_GROUP: ${{needs.setup-env-job.outputs.AZURE_RESOURCE_GROUP}}
AZURE_LOCATION: ${{needs.setup-env-job.outputs.AZURE_LOCATION}}
AZURE_OPENAI_ENDPOINT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_ENDPOINT}}
AZURE_OPENAI_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_CHAT_DEPLOYMENT}}
AZUREAI_PROJECT_NAME: ${{needs.setup-env-job.outputs.AZUREAI_PROJECT_NAME}}
AZURE_OPENAI_API_VERSION: ${{needs.setup-env-job.outputs.AZURE_OPENAI_API_VERSION}}
AZURE_SUBSCRIPTION_ID: ${{needs.setup-env-job.outputs.AZURE_SUBSCRIPTION_ID}}
AZURE_RESOURCE_GROUP: ${{needs.setup-env-job.outputs.AZURE_RESOURCE_GROUP}}
AZURE_OPENAI_NAME: ${{needs.setup-env-job.outputs.AZURE_OPENAI_NAME}}
LOCATION: ${{needs.setup-env-job.outputs.AZURE_LOCATION}}
AZURE_CONTAINER_REGISTRY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REGISTRY_NAME}}
AZURE_CONTAINER_REPOSITORY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REPOSITORY_NAME}}
AZURE_SEARCH_ENDPOINT: ${{needs.setup-env-job.outputs.AZURE_SEARCH_ENDPOINT}}
AZURE_OPENAI_CHAT_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_CHAT_DEPLOYMENT}}
AZURE_OPENAI_EMBEDDING_DEPLOYMENT: ${{needs.setup-env-job.outputs.AZURE_OPENAI_EMBEDDING_DEPLOYMENT}}
AZURE_OPENAI_EMBEDDING_MODEL: ${{needs.setup-env-job.outputs.AZURE_OPENAI_EMBEDDING_MODEL}}
PROMPTFLOW_WORKER_NUM: ${{needs.setup-env-job.outputs.PROMPTFLOW_WORKER_NUM}}
PROMPTFLOW_SERVING_ENGINE: ${{needs.setup-env-job.outputs.PROMPTFLOW_SERVING_ENGINE}}
AZURE_APP_SERVICE_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_NAME}}
AZURE_APP_SERVICE_PLAN_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_PLAN_NAME}}
PREFIX: ${{ github.sha }}
run: |
echo "Run Automated Adversarial Testing"
export PYTHONPATH=./src:$PYTHONPATH
export AZURE_OPENAI_API_KEY=$(az cognitiveservices account keys list --resource-group ${AZURE_RESOURCE_GROUP} --name ${AZURE_OPENAI_NAME} --query "key1" --output tsv)
python evaluations/safety_eval.py
- name: Upload evaluation results
uses: actions/upload-artifact@v4
with:
name: adversarial-test
path: adversarial_test.json
- name: Upload evaluation results
uses: actions/upload-artifact@v4
with:
name: adversarial-test-w-jailbreak
path: adversarial_test_w_jailbreak.json
integration-testing:
needs: [setup-env-job, qa-flow-evaluation, qa-safety-evaluation]
runs-on: ubuntu-latest
environment: qa
steps:
- name: Integration Tests
run: |
echo "Run QA Integration Tests"
get-source-acr-and-repository:
needs: [setup-env-job, setup-env-job, integration-testing]
runs-on: ubuntu-latest
environment: dev
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_DEV_COLLECT_TELEMETRY: no
outputs:
SOURCE_REGISTRY: ${{ steps.get-vars.outputs.SOURCE_REGISTRY }}
steps:
- uses: actions/checkout@v4
- name: Install Azure Developer CLI
uses: Azure/[email protected]
- name: azd Login
shell: bash
run: |
info=$(echo $AZURE_CREDENTIALS | jq -r '.')
echo "::add-mask::$(echo $info | jq -r '.clientSecret')"
azd auth login \
--client-id "$(echo $info | jq -r '.clientId')" \
--client-secret "$(echo $info | jq -r '.clientSecret')" \
--tenant-id "$(echo $info | jq -r '.tenantId')"
- name: Get source repo vars
id: get-vars
shell: bash
run: |
echo "AZURE_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID"
echo "AZURE_LOCATION=$AZURE_LOCATION"
echo "azd init -e $AZURE_ENV_NAME -l $AZURE_LOCATION -s $AZURE_SUBSCRIPTION_ID"
azd init -e $AZURE_ENV_NAME -l $AZURE_LOCATION -s $AZURE_SUBSCRIPTION_ID
# Run azd env refresh and capture last deployment outputs
echo "🔶 | Run azd env refresh and capture outputs"
azd env refresh -e "$AZURE_ENV_NAME"
echo "🔶 | Get $AZURE_ENV_NAME environment variables"
# Get environment variable from the last deployment
AZURE_CONTAINER_REGISTRY_NAME=$(azd env get-values -e $AZURE_ENV_NAME | grep AZURE_CONTAINER_REGISTRY_NAME | cut -d'=' -f2 | tr -d '"' || true)
echo "SOURCE_REGISTRY=$AZURE_CONTAINER_REGISTRY_NAME" >> "$GITHUB_OUTPUT"
echo "SOURCE_REGISTRY=$AZURE_CONTAINER_REGISTRY_NAME"
import-image:
runs-on: ubuntu-latest
needs: [setup-env-job, get-source-acr-and-repository]
environment: qa
env:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
SOURCE_REGISTRY: ${{ needs.get-source-acr-and-repository.outputs.SOURCE_REGISTRY }}
AZURE_CONTAINER_REGISTRY_NAME: ${{ needs.setup-env-job.outputs.AZURE_CONTAINER_REGISTRY_NAME }}
AZURE_CONTAINER_REPOSITORY_NAME: ${{ needs.setup-env-job.outputs.AZURE_CONTAINER_REPOSITORY_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Azure CLI
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Check if image exists
id: check_image
run: |
if az acr repository show-tags -n $SOURCE_REGISTRY --repository $AZURE_CONTAINER_REPOSITORY_NAME --query "contains(@, 'develop-${{ github.sha }}')" | grep -q true; then
echo "✅ | Image exists in Dev ACR."
echo "IMAGE_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "❌ | Image does not exist. Building a new image."
echo "This should be done for bug fix scenarios only, don't forget to merge back to develop branch."
echo "IMAGE_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Get release version name
id: get_release_version
run: |
RELEASE_VERSION=${GITHUB_REF#refs/heads/release/}
echo "RELEASE_VERSION=$RELEASE_VERSION-rc" >> $GITHUB_ENV
echo "RELEASE_VERSION is $RELEASE_VERSION-rc"
## Happy path: Import image from dev registry
- name: Import image from dev registry
if: steps.check_image.outputs.IMAGE_EXISTS == 'true'
run: |
echo "Image already IMAGE_EXISTS. retag with release version and import to qa acr."
az acr import -n $AZURE_CONTAINER_REGISTRY_NAME \
--source $SOURCE_REGISTRY.azurecr.io/$AZURE_CONTAINER_REPOSITORY_NAME:develop-${{ github.sha }} \
--image $AZURE_CONTAINER_REPOSITORY_NAME:$RELEASE_VERSION-${{ github.sha }} --force
# in case ACR is in another subscription:
# az acr import -n myregistry --source sourcerepository:sourcetag -t targetrepository:targettag -r /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/sourceResourceGroup/providers/Microsoft.ContainerRegistry/registries/sourceRegistry
## Bug fix in release branch: needs to build a new image
- name: Setup Python
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install Promptflow CLI
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
run: |
python -m pip install --upgrade pip
pip install promptflow --upgrade
pf --version
- name: Install required dependencies
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
run: |
pip cache purge
pip install --upgrade pip setuptools
pip install -r src/requirements.txt
- name: Create flow docker files
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
run: |
# reference: https://github.com/microsoft/promptflow/tree/main/examples/tutorials/flow-deploy/azure-app-service
pf flow build --source src --output dist --format docker
- name: Build and push image
if: steps.check_image.outputs.IMAGE_EXISTS == 'false'
env:
AZURE_CONTAINER_REGISTRY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REGISTRY_NAME}}
AZURE_CONTAINER_REPOSITORY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REPOSITORY_NAME}}
run: |
echo "✅ Building docker image..."
path=dist
image_tag=$AZURE_CONTAINER_REPOSITORY_NAME:$RELEASE_VERSION-${{ github.sha }}
echo "Change working directory to $path"
cd "$path"
docker build -t "$image_tag" .
full_registry_name="$AZURE_CONTAINER_REGISTRY_NAME.azurecr.io"
echo "✅ Trying to login to $full_registry_name..."
az acr login -n "$full_registry_name"
acr_image_tag=$full_registry_name/$image_tag
echo "✅ ACR image tag: $acr_image_tag"
docker tag "$image_tag" "$acr_image_tag"
echo "✅ Start pushing image...$acr_image_tag"
docker push "$acr_image_tag"
deploy-flow:
runs-on: ubuntu-latest
needs: [setup-env-job, import-image]
environment: qa
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
AZURE_DEV_COLLECT_TELEMETRY: no
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Azure CLI
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Set az account
uses: azure/CLI@v2
with:
inlineScript: |
az account set --subscription $AZURE_SUBSCRIPTION_ID
- name: Deploy Flow
env:
AZURE_APP_SERVICE_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_NAME}}
AZURE_APP_SERVICE_PLAN_NAME: ${{needs.setup-env-job.outputs.AZURE_APP_SERVICE_PLAN_NAME}}
AZURE_CONTAINER_REGISTRY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REGISTRY_NAME}}
AZURE_CONTAINER_REPOSITORY_NAME: ${{needs.setup-env-job.outputs.AZURE_CONTAINER_REPOSITORY_NAME}}
AZURE_RESOURCE_GROUP: ${{needs.setup-env-job.outputs.AZURE_RESOURCE_GROUP}}
AZURE_SUBSCRIPTION_ID: ${{needs.setup-env-job.outputs.AZURE_SUBSCRIPTION_ID}}
shell: bash
run: |
# Deploy Flow
echo "🔶 | Deploying to Azure"
image_tag=$AZURE_CONTAINER_REPOSITORY_NAME:$RELEASE_VERSION-${{ github.sha }}
name="${AZURE_APP_SERVICE_NAME}"
service_plan_name="${AZURE_APP_SERVICE_PLAN_NAME}"
subscription="${AZURE_SUBSCRIPTION_ID}"
resource_group="${AZURE_RESOURCE_GROUP}"
registry_name="${AZURE_CONTAINER_REGISTRY_NAME}"
full_registry_name="${registry_name}.azurecr.io"
acr_image_tag=$full_registry_name/$image_tag
echo "Image Tag: $image_tag"
echo "ACR Image Tag: $acr_image_tag"
echo "App Service Name: $name"
echo "Service Plan Name: $service_plan_name"
echo "Subscription ID: $subscription"
echo "Resource Group: $resource_group"
echo "Registry Name: $registry_name"
echo "Full Registry Name: $full_registry_name"
function append_to_command {
command=$1
if [ -n "$subscription" ]; then
command="$command --subscription $subscription"
fi
if $verbose; then
command="$command --debug"
fi
echo "$command"
}
echo "🔶 | Trying to login to $registry_name..."
az acr login -n "$registry_name"
# Check if the container image exists
echo "🔶 | Checking if ${acr_image_tag} exists..."
set +e
image_exists=$(az acr repository show --name $registry_name --image ${acr_image_tag} --query "name" -o tsv > /dev/null 2>&1 && echo true || echo false)
set -e
if [ -z "$image_exists" ]; then
echo "❌ | $acr_image_tag does not exist"
exit 1
else
echo "✅ | $acr_image_tag exists"
fi
# Check if the app exists
echo "🔶 | Checking if the app exists..."
app_exists=$(az webapp show --name $name --resource-group $resource_group --query "name" -o tsv)
if [ -z "$app_exists" ]; then
# Create app
echo "🔶 | Creating $name app..."
command="az webapp create --name $name -p $service_plan_name --deployment-container-image-name $acr_image_tag --startup-file 'bash start.sh' -g $resource_group"
command=$(append_to_command "$command")
echo "$command"
eval "$command"
else
# Update app
echo "🔶 | Updating $name app..."
command="az webapp config container set --name $name --resource-group $resource_group --container-image-name $acr_image_tag"
command=$(append_to_command "$command")
echo "$command"
eval "$command"
fi
# Set Registry and ACR credentials
echo "🔶 | Setting ACR credentials in $registry_name registry..."
az acr update -n $registry_name --admin-enabled true
acr_username=$(az acr credential show --name $registry_name --query username --output tsv)
acr_password=$(az acr credential show --name $registry_name --query passwords[0].value --output tsv)
az webapp config container set --name $name --resource-group $resource_group --container-registry-user $acr_username --container-registry-password $acr_password
# Config environment variables
echo "🔶 | Config app $name env variables ..."
# Port default to 8080 corresponding to the DockerFile
command="az webapp config appsettings set -g $resource_group --name $name --settings USER_AGENT=promptflow-appservice WEBSITES_PORT=8080"
command=$(append_to_command "$command")
echo "$command"
eval "$command"
# Restarting app
echo "🔶 | Restarting app ...$name"
az webapp restart --name $name --resource-group $resource_group
echo "🔗 Please go to https://portal.azure.com/ to config environment variables of $name app at (Settings>Configuration) or (Settings>Environment variables)"
echo "Reach deployment logs at (Deployment>Deployment Central) and app logs at (Monitoring>Log stream)"
echo "🔗 Reach advanced deployment tools at https://$name.scm.azurewebsites.net/"
echo "🔗 Reach more details about app service at https://learn.microsoft.com/en-us/azure/app-service/"
- name: GitHub Summary Step
if: ${{ success() }}
run: |
echo "Deployment completed successfully! :rocket:" >> $GITHUB_STEP_SUMMARY
deep_link=https://portal.azure.com/#@/resource/subscriptions/$AZURE_SUBSCRIPTION_ID/resourceGroups/rg-$AZURE_ENV_NAME/overview
echo "🔗 [View Resources Deployed Here]($deep_link)" >> $GITHUB_STEP_SUMMARY