-
Notifications
You must be signed in to change notification settings - Fork 1
/
azdevops-keda.ps1
73 lines (60 loc) · 2.71 KB
/
azdevops-keda.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
69
70
71
72
73
# az cli code is taken from the docs:
#https://docs.microsoft.com/en-us/azure/container-apps/microservices-dapr-azure-resource-manager?tabs=bash#setup
#uncomment for the first time only
# az login
# az upgrade
# az extension add --source "https://workerappscliextension.blob.core.windows.net/azure-cli-extension/containerapp-0.2.0-py2.py3-none-any.whl"
# az provider register --namespace Microsoft.Web
$scriptPath = $PSScriptRoot
$SUBSCRIPTION_ID = "xxxxxxxxxxxx"
$RESOURCE_GROUP = "xxxxxxxxxxxx"
$LOCATION = "brazilsouth"
$CONTAINERAPPS_ENVIRONMENT = "xxxxxxxxxxxx"
$LOG_ANALYTICS_WORKSPACE = "xxxxxxxxxxxx"
$ORG_NAME = "xxxxxxxxxxxx"
$AZP_TOKEN = "****************" #for poc reasons use a full scoped PAT, then can use the same PAT for all the resources
$AZP_POOL = "ACA"
$AZP_URL = "https://dev.azure.com/$ORG_NAME"
#registry is expected to already exist
$REGISTRY_ENDPOINT = "xxxxxxxxxxxx.azurecr.io"
$REGISTRY_ADMIN= "xxxxxxxxxxxx"
$REGISTRY_SECRET=""****************""
# uncomment this if you want to override vars with local vars for development
# you need to add a file 'variables.dev.ps1' to the folder 'container-app'
#. "$scriptPath/variables.dev.ps1"
# select subscription
az account set --subscription $SUBSCRIPTION_ID
# create resource group
# az group create `
# --name $RESOURCE_GROUP `
# --location "$LOCATION"
# log analytics workspace
az monitor log-analytics workspace create `
--resource-group $RESOURCE_GROUP `
--workspace-name $LOG_ANALYTICS_WORKSPACE
$LOG_ANALYTICS_WORKSPACE_CLIENT_ID = (az monitor log-analytics workspace show --query customerId -g $RESOURCE_GROUP -n $LOG_ANALYTICS_WORKSPACE --out tsv)
$LOG_ANALYTICS_WORKSPACE_CLIENT_SECRET = (az monitor log-analytics workspace get-shared-keys --query primarySharedKey -g $RESOURCE_GROUP -n $LOG_ANALYTICS_WORKSPACE --out tsv)
# container app environement
az containerapp env create `
--name $CONTAINERAPPS_ENVIRONMENT `
--resource-group $RESOURCE_GROUP `
--logs-workspace-id $LOG_ANALYTICS_WORKSPACE_CLIENT_ID `
--logs-workspace-key $LOG_ANALYTICS_WORKSPACE_CLIENT_SECRET `
--location "$LOCATION"
# create pool in azdo
$AZP_POOLID = (& "$scriptPath/azdevops-pool.ps1" -OrgName $ORG_NAME -PAT $AZP_TOKEN -PoolName $AZP_POOL).id
# container app
az deployment group create `
--resource-group $RESOURCE_GROUP `
--template-file "$scriptPath/aca-keda.json" `
--parameters `
environment_name="$CONTAINERAPPS_ENVIRONMENT" `
location="brazilsouth" `
azp_url="$AZP_URL" `
azp_token="$AZP_TOKEN" `
azp_pool="$AZP_POOL" `
azp_poolId="$AZP_POOLID" `
registryEndpoint=$REGISTRY_ENDPOINT `
registryUserName=$REGISTRY_ADMIN `
registrySecret=$REGISTRY_SECRET `
registryImage="$REGISTRY_ENDPOINT/adoagent:latest"