-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (177 loc) Β· 9.39 KB
/
continuous_delivery_dev.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
name: CD Dev Pipeline
on:
workflow_run:
workflows: ["CI Pipeline"]
types:
- success
jobs:
setup-env-job:
if: ${{ github.repository != 'Azure/llmops-project-template' }}
runs-on: ubuntu-latest
environment: dev
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 }}
AZURE_SUBSCRIPTION_ID: ${{ steps.config-env.outputs.AZURE_SUBSCRIPTION_ID }}
steps:
- uses: actions/checkout@v4
- name: Provision dev 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_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: "false" # It's already populated during PR
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 }}
deploy-flow:
if: ${{ github.repository != 'Azure/llmops-project-template' }}
runs-on: ubuntu-latest
needs: [setup-env-job]
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 }}
VERBOSE: ${{ vars.VERBOSE }}
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}:develop-${{ 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
verbose=${VERBOSE:-false}
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" != false ]; 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