-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathazure-deploy.sh
71 lines (59 loc) · 1.84 KB
/
azure-deploy.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
#!/bin/bash
set -euo pipefail
# Change this if you are using your own github repository
gitSource="https://github.com/Azure-Samples/azure-sql-db-who-am-i.git"
# Azure configuration
FILE=".env"
if [[ -f $FILE ]]; then
echo "loading from .env"
export $(egrep . $FILE | xargs -n1)
else
cat << EOF > .env
ResourceGroup=""
AppName=""
Location=""
ConnectionStrings__AzureSQL="Server=.database.windows.net;Database=;UID=;PWD="
EOF
echo "Enviroment file not detected."
echo "Please configure values for your environment in the created .env file"
echo "and run the script again."
echo "ConnectionStrings__AzureSQL: connection string to connect to desired Azure SQL database"
exit 1
fi
# Make sure connection string variable is set
if [[ -z "${ConnectionStrings__AzureSQL:-}" ]]; then
echo "ConnectionStrings__AzureSQL not found."
exit 1;
fi
echo "Creating Resource Group '$ResourceGroup'...";
az group create \
-n $ResourceGroup \
-l $Location
echo "Creating Application Service Plan '$AppName-plan'...";
az appservice plan create \
-g $ResourceGroup \
-n "$AppName-plan" \
--is-linux \
--sku B1
echo "Creating Web Application '$AppName'...";
az webapp create \
-g $ResourceGroup \
-n $AppName \
--plan "$AppName-plan" \
--runtime "DOTNETCORE:6.0" \
--deployment-source-url $gitSource \
--deployment-source-branch main
echo "Enabling System Managed Identity....";
az webapp identity assign \
-g $ResourceGroup \
-n $AppName
echo "Configuring Connection String...";
az webapp config connection-string set \
-g $ResourceGroup \
-n $AppName \
--settings AzureSQL=$ConnectionStrings__AzureSQL \
--connection-string-type=SQLAzure
echo "Getting hostname..."
url=`az webapp show -g $ResourceGroup -n $AppName --query "defaultHostName" -o tsv`
echo "WebApp deployed at: https://$url"
echo "Done."