This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
deploy_cache_manager.sh
151 lines (133 loc) · 6.73 KB
/
deploy_cache_manager.sh
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
#!/bin/bash
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
source ./InfrastructureDeployment/setup_env.sh
az account set --subscription $AZURE_SUBSCRIPTION_ID
if [ $? -ne 0 ]
then
echo "Could not set subscription $AZURE_SUBSCRIPTION_ID."
echo "deploy_aks.sh failed"
exit $?
fi
echo "Creating the Azure Function Apps."
if "$DEPLOY_CACHE_MANAGER_FUNCTION_APP" = "true"
then
echo "Creating the cache manager Azure Function App."
echo "az functionapp create --name $CACHE_MANAGER_FUNCTION_APP_NAME --storage-account $FUNCTION_STORAGE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --plan $FUNCTION_APP_NAME-plan --deployment-container-image-name $CACHE_MANAGER_IMAGE --app-insights $APP_INSIGHTS_RESOURCE_NAME "
az functionapp create --name $CACHE_MANAGER_FUNCTION_APP_NAME --storage-account $FUNCTION_STORAGE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --plan $FUNCTION_APP_NAME-plan --deployment-container-image-name $CACHE_MANAGER_IMAGE --app-insights $APP_INSIGHTS_RESOURCE_NAME
if [ $? -ne 0 ]
then
echo "Could not create the $CACHE_MANAGER_FUNCTION_APP_NAME cache manager Azure Function App."
echo "deploy_cache_manager.sh failed"
exit $?
fi
storageConnectionString=$(az storage account show-connection-string --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --name $FUNCTION_STORAGE_NAME --query connectionString --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $FUNCTION_STORAGE_NAME storage connection string."
echo "deploy_cache_manager.sh failed"
exit $?
fi
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings AzureWebJobsStorage=${storageConnectionString}
if [ $? -ne 0 ]
then
echo "Could not set $CACHE_MANAGER_FUNCTION_APP_NAME application settings."
echo "deploy_cache_manager.sh failed"
exit $?
fi
if [[ "$TRANSPORT_TYPE" = "eventgrid" ]]
then
# Get Event Grid Topic URI
topic_uri=$(az eventgrid topic show -n $EVENT_GRID_TOPIC_NAME -g $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query endpoint --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME event grid topic URI."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Assign Event Grid Topic URI
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "EVENT_GRID_TOPIC_URI=${topic_uri}"
if [ $? -ne 0 ]
then
echo "Could not set $CACHE_MANAGER_FUNCTION_APP_NAME event grid topic URI."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Get Event Grid Topic key
topic_key=$(az eventgrid topic key list -n $EVENT_GRID_TOPIC_NAME -g $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query key1 --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME Event Grid topic key."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Assign Event Grid Key
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "EVENT_GRID_KEY=${topic_key}"
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME Event Grid key."
echo "deploy_cache_manager.sh failed"
exit $?
fi
fi
if [[ "$TRANSPORT_TYPE" = "queue" ]]
then
servicebus_connection_string=$(az servicebus namespace authorization-rule keys list --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --namespace-name $SERVICEBUS_NAMESPACE --name RootManageSharedAccessKey --query primaryConnectionString --output tsv)
# Assign SERVICE_BUS_CONNECTION_STRING
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "SERVICE_BUS_CONNECTION_STRING=${servicebus_connection_string}"
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME Event Grid key."
echo "deploy_cache_manager.sh failed"
exit $?
fi
fi
# Get Redis URI detail.
redis_uri_detail=($(az redis show --name $AZURE_CACHE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query [hostName,sslPort] --output tsv))
if [ $? -ne 0 ]
then
echo "Could not get the $AZURE_CACHE_NAME Redis URI connection string."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Get Redis access key.
redis_key=$(az redis list-keys --name $AZURE_CACHE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query primaryKey --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $AZURE_CACHE_NAME Redis access key."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Assign the Redis info to an App Setting in the Web App
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "REDIS_GENERAL_TIMEOUT=15000" "REDIS_SYNC_TIMEOUT=15000" "REDIS_CONNECTION_STRING=${redis_uri_detail[0]}:${redis_uri_detail[1]},password=$redis_key,ssl=True,abortConnect=False"
if [ $? -ne 0 ]
then
echo "Could assign the $CACHE_MANAGER_FUNCTION_APP_NAME Redis connection string."
echo "deploy_cache_manager.sh failed"
exit $?
fi
# Assign REDIS_SYNC_TIMEOUT
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "REDIS_SYNC_TIMEOUT=$REDIS_SYNC_TIMEOUT"
if [ $? -ne 0 ]
then
echo "Could not set REDIS_SYNC_TIMEOUT."
echo "deploy_backend_queue_function.sh failed"
exit $?
fi
# Assign REDIS_ASYNC_TIMEOUT
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "REDIS_ASYNC_TIMEOUT=$REDIS_ASYNC_TIMEOUT"
if [ $? -ne 0 ]
then
echo "Could not set REDIS_ASYNC_TIMEOUT."
echo "deploy_backend_queue_function.sh failed"
exit $?
fi
# Assign REDIS_GENERAL_TIMEOUT
az functionapp config appsettings set --name $CACHE_MANAGER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "REDIS_GENERAL_TIMEOUT=$REDIS_GENERAL_TIMEOUT"
if [ $? -ne 0 ]
then
echo "Could not set REDIS_GENERAL_TIMEOUT."
echo "deploy_backend_queue_function.sh failed"
exit $?
fi
fi