-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-webapp.sh
133 lines (106 loc) · 4.8 KB
/
deploy-webapp.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
RESOURCE_GROUP=rg-dotnet-passwordless
POSTGRESQL_HOST=postgres-passwordless
DATABASE_NAME=checklist
POSTGRESQL_FQDN=${POSTGRESQL_HOST}.postgres.database.azure.com
LOCATION=eastus
MYSQL_HOST=mysql-passwordless
MYSQL_FQDN=${MYSQL_HOST}.mysql.database.azure.com
MSSQL_HOST=mssql-passwordless
MSSQL_FQDN=${MSSQL_HOST}.database.azure.com
APPSERVICE_PSQL=dotnet-passwordless-pgsql
APPSERVICE_MYSQL=dotnet-passwordless-mysql
APPSERVICE_MSSQL=dotnet-passwordless-mssql
APPSERVICE_PLAN="asp-dotnetpasswordless"
# Create a resource group
az group create --name $RESOURCE_GROUP --location $LOCATION
# Create app service plan
az appservice plan create --name $APPSERVICE_PLAN --resource-group $RESOURCE_GROUP --location $LOCATION --sku B1 --is-linux
az webapp create \
--name $APPSERVICE_PSQL \
--resource-group $RESOURCE_GROUP \
--plan $APPSERVICE_PLAN \
--runtime "DOTNETCORE:6.0"
az webapp create \
--name $APPSERVICE_MYSQL \
--resource-group $RESOURCE_GROUP \
--plan $APPSERVICE_PLAN \
--runtime "DOTNETCORE:6.0"
az webapp create \
--name $APPSERVICE_MSSQL \
--resource-group $RESOURCE_GROUP \
--plan $APPSERVICE_PLAN \
--runtime "DOTNETCORE:6.0"
cd Passwordless.WebAPI.PgSql
dotnet build
# Get current user
USER=$(az account show --query user.name -o tsv)
# Get connections string
CONNSTRING="Server=${POSTGRESQL_HOST}.postgres.database.azure.com;Database=${DATABASE_NAME};Port=5432;User Id=${USER}@${POSTGRESQL_HOST};Ssl Mode=Require;Trust Server Certificate=true"
ASPNETCORE_ENVIRONMENT=Deployment
echo "{\"ConnectionStrings\":{\"AZURE_POSTGRESQL_CONNECTIONSTRING\":\"${CONNSTRING}\"}}" >appsettings.Deployment.json
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
az webapp connection create postgres \
--resource-group $RESOURCE_GROUP \
--name $APPSERVICE_PSQL \
--tg $RESOURCE_GROUP \
--server $POSTGRESQL_HOST \
--database $DATABASE_NAME \
--client-type dotnet \
--system-identity
cd ..
# MYSQL
cd Passwordless.WebAPI.MySql
dotnet build
# Get connections string
# "Server=mysql-passwordless.mysql.database.azure.com;Database=checklist;User [email protected];Port=3306;SSL Mode=Required;Allow Public Key Retrieval=True;Connection Timeout=30"
CONNSTRING="Server=${MYSQL_HOST}.mysql.database.azure.com;Database=${DATABASE_NAME};User ID=${USER};Port=3306;SSL Mode=Required;Allow Public Key Retrieval=True;Connection Timeout=30"
ASPNETCORE_ENVIRONMENT=Deployment
echo "{\"ConnectionStrings\":{\"AZURE_MYSQL_CONNECTIONSTRING\":\"${CONNSTRING}\"}}" >appsettings.Deployment.json
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
az webapp connection create mysql-flexible \
--resource-group $RESOURCE_GROUP \
--name $APPSERVICE_MYSQL \
--tg $RESOURCE_GROUP \
--server $MYSQL_HOST \
--database $DATABASE_NAME \
--client-type dotnet \
--system-identity
dotnet publish -c Release -o publish
cd publish
zip -r app.zip .
az webapp deploy -g $RESOURCE_GROUP --name $APPSERVICE_MYSQL --src-path ./app.zip --clean true
echo 'Remember changing the connection string with include "Trust Server Certificate=true"'
# SQL SERVER
cd Passwordless.WebAPI.MsSql
dotnet build
# Get connections string
# "Server=mysql-passwordless.mysql.database.azure.com;Database=checklist;User [email protected];Port=3306;SSL Mode=Required;Allow Public Key Retrieval=True;Connection Timeout=30"
CONNSTRING="Server=tcp:${MSSQL_HOST}.database.windows.net;Database=checklist;Authentication=Active Directory Default;TrustServerCertificate=True"
ASPNETCORE_ENVIRONMENT=Deployment
echo "{\"ConnectionStrings\":{\"AZURE_MSSQL_CONNECTIONSTRING\":\"${CONNSTRING}\"}}" >appsettings.Deployment.json
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
az webapp connection create sql \
--resource-group $RESOURCE_GROUP \
--name $APPSERVICE_MSSQL \
--tg $RESOURCE_GROUP \
--server $MSSQL_HOST \
--database $DATABASE_NAME \
--client-type dotnet \
--system-identity
dotnet publish -c Release -o publish
cd publish
zip -r app.zip .
az webapp deploy -g $RESOURCE_GROUP --name $APPSERVICE_MSSQL --src-path ./app.zip --clean true
echo 'Remember changing the connection string with include "Trust Server Certificate=true"'
# webapp connection doesn't work for SQL Server
# az webapp connection create sql --resource-group rg-dotnet-passwordless --name dotnet-passwordless-mssql --tg rg-dotnet-passwordless --server mssql-passwordless --database checklist --client-type dotnet --system-identity
sqlcmd -S $MSSQL_HOST.database.windows.net -d $DATABASE_NAME -U $USER -G -l 30