Question:
You are a developer tasked with deploying a new .NET web application using on Microsoft Azure. Your first task is to create a new resource group myResourceGroup located in the South Central US region. Following that, you need to establish a deployment user for the web application. You are then required to create myAppServicePlan App Service plan within a Linux environment that is cost-efficient. The web application should be created within this resource group and App Service plan, using .NET as its runtime. You are also required to configure the application settings to set the deployment branch to main. Lastly, you are provided with a sample application from GitHub: https://github.com/Azure-Samples/App-Service-Troubleshoot-Azure-Monitor. You need to clone this application, rename the default branch to main, add the Azure remote repository using the URL from the webapp create command, and push the code to the Azure repository. How would you accomplish these tasks using Azure CLI commands?
Answer:
# Create a new resource group in the South Central US region
az group create --name myResourceGroup --location "South Central US"
# Set up a deployment user for the web application
az webapp deployment user set --user-name <username> --password <password>
# Create an App Service plan with a Linux environment. The SKU B1 is chosen for its cost efficiency.
az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku B1 --is-linux
# Create the web application within the resource group and the App Service plan, using .NET as its runtime
az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name MyApp --runtime "DOTNET|6.0" --deployment-local-git
# Capture the Git URL from the output of the previous command
git_url=$(az webapp show --name MyApp --resource-group myResourceGroup --query gitUrl --output tsv)
# Configure the application settings to set the deployment branch to 'main'
az webapp config appsettings set --name MyApp --resource-group myResourceGroup --settings DEPLOYMENT_BRANCH='main'
# Clone the sample application from GitHub
git clone https://github.com/Azure-Samples/App-Service-Troubleshoot-Azure-Monitor
# Navigate into the cloned repository
cd App-Service-Troubleshoot-Azure-Monitor
# Rename the default branch to 'main'
git branch -m main
# Add the Azure remote repository using the URL from the webapp create command
git remote add azure $git_url
# Push the code to the Azure repository
git push azure main