2022-05-22 10:40:18 +00:00
|
|
|
#!/bin/sh
|
2022-05-22 10:56:06 +00:00
|
|
|
suhailregistry='suhailregistry'
|
2022-05-22 10:40:18 +00:00
|
|
|
mysql_service='mysql-db-f39m'
|
|
|
|
app_name='suhail742'
|
|
|
|
echo "Preparing the app"
|
|
|
|
echo "Creating docker images"
|
|
|
|
docker build ./src/fruitapp-backend -t fruitapp-backend
|
|
|
|
docker build ./src/fruitapp-frontend/ -f ./src/fruitapp-frontend/.docker/dev/Dockerfile -t fruitapp-frontend
|
|
|
|
echo 'starting the app'
|
|
|
|
az group create --name suhailgroup --location westeurope
|
|
|
|
az acr create --resource-group suhailgroup --name $suhailregistry --sku basic
|
|
|
|
az acr login --name $suhailregistry
|
|
|
|
docker tag fruitapp-backend:latest $suhailregistry.azurecr.io/fruitapp-backend:latest
|
|
|
|
docker tag fruitapp-frontend:latest $suhailregistry.azurecr.io/fruitapp-frontend:latest
|
|
|
|
docker push $suhailregistry.azurecr.io/fruitapp-backend:latest
|
|
|
|
docker push $suhailregistry.azurecr.io/fruitapp-frontend:latest
|
|
|
|
|
|
|
|
|
|
|
|
az appservice plan create --name myserviceplan -g suhailgroup --sku S1 --is-linux
|
|
|
|
az webapp create -g suhailgroup -p myserviceplan --name $app_name \
|
|
|
|
--multicontainer-config-type compose --multicontainer-config-file az-docker-compose.yml
|
|
|
|
|
|
|
|
principalId=$(az webapp identity assign --resource-group suhailgroup --name $app_name --query principalId --output tsv)
|
|
|
|
subscriptionId=$(az account show --query id --output tsv)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
az mysql server create -g suhailgroup --name $mysql_service --location eastus --admin-user adminuser --admin-password My5up3rStr0ngPaSw0rd! --sku-name B_Gen5_1 --version 5.7 --ssl-enforcement Disabled
|
|
|
|
|
|
|
|
myIp=$(curl -s api.ipify.org)
|
|
|
|
az mysql server firewall-rule create -g suhailgroup --server $mysql_service --name AllowMyIP --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
|
|
|
|
az mysql server firewall-rule create -g suhailgroup --server $mysql_service --name myIP --start-ip-address $myIp --end-ip-address $myIp
|
|
|
|
|
|
|
|
mysql -h $mysql_service.mysql.database.azure.com -u adminuser@$mysql_service -pMy5up3rStr0ngPaSw0rd! -e "create database main;"
|
|
|
|
|
|
|
|
az role assignment create --assignee $principalId \
|
|
|
|
--scope /subscriptions/$subscriptionId/resourceGroups/suhailgroup/providers/Microsoft.ContainerRegistry/registries/$suhailregistry \
|
|
|
|
--role acrpull
|
|
|
|
|
|
|
|
az webapp config appsettings set --name $app_name -g suhailgroup --settings SQLALCHEMY_DATABASE_URI='mysql://adminuser@$mysql_service:My5up3rStr0ngPaSw0rd!@$mysql_service.mysql.database.azure.com/main' \
|
|
|
|
MYSQL_USER='adminuser@$mysql_service' MYSQL_PASSWORD='My5up3rStr0ngPaSw0rd!' MYSQL_ROOT_PASSWORD='My5up3rStr0ngPaSw0rd!'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
az resource update --ids /subscriptions/$subscriptionId/resourceGroups/suhailgroup/providers/Microsoft.Web/sites/$app_name/config/web --set properties.acrUseManagedIdentityCreds=True
|
|
|
|
|
|
|
|
az webapp config container set --name $app_name -g suhailgroup --docker-registry-server-url https://$suhailregistry.azurecr.io
|
|
|
|
|
|
|
|
echo 'app started'
|
|
|
|
|
|
|
|
|
|
|
|
|