Azure Resource Manager helps automate the provisioning of plenty of resources in Azure.
In this lab, you will create the neccessary assets to run the CustomerReviews website and its automatic moderation with Cognitives Services. You will also add images to populate the CustomerReviews website.
In this hands-on lab, you will learn how to:
- Create Azure Services required for [lab 02](../02 - Visual Studio) and [lab 03](../03 - Continuous Delivery)
- Storage account, CosmosDb, Cognitives Services, Application Service, Azure Functions
- Deploy the CustomerReviews website
- Create images in a blob storage and documents in Cosmos DB
The following are required to complete this hands-on lab:
- An active Microsoft Azure subscription. If you don't have one, sign up for a free trial.
- An active GitHub account. If you don't have one, sign up for free. (optional)
This hands-on lab includes the following exercises:
- Exercise 1: Create an Azure Cloud Shell (PowerShell)
- Exercise 2: Clone GitHub repository
- Exercise 3: Create services with Azure Resource Manager template
- Exercise 4: Add images to CustomerReviews site (Reset data)
Estimated time to complete this lab: 30 minutes.
The first step in .... In this exercise, you will create .....
-
Open the Azure Portal in your browser. If you are asked to log in, do so using your Microsoft account.
-
Click on the Cloud Shell button at the top of the page
The Cloud Shell will appear at the bottom of the page
-
Click PowerShell (Windows)
-
Select your subscription, and Click on Create storage. This will create a new storage account for you and create a file share to persist files.
-
Your Azure Cloud Shell wil be ready within a few minutes. Make sure you choose Powershell. You can swith between Bash and Powershell in the dropdown list
The Azure Cloud Shell is a window container. A new one will be started with your CloudDrive mapped as a volume. And you will be connected to your current Azure subscription. has been created and you have added three containers to the storage account created for it. The next step is to get code from this repo.
Once you have created an Azure Cloud Shell, you can use Powershell, commands, and some other SDK or application installed on it. In this exercise, you will clone the git repo into a persistent volume CloudDrive. This will allow you to get all the scripts necessary to create the assets.
-
Type these commands to navigate to your CloudDrive and clone this git repository.
Copy and paste in Azure Cloud Shell
- Windows:
Ctrl-insert
to copy andShift-insert
to paste. Right-click dropdown can also enable copy/paste.- FireFox/IE may not support clipboard permissions properly.
- Mac OS:
Cmd-c
to copy andCmd-v
to paste. Right-click dropdown can also enable copy/paste.
cd git clone --depth 1 --single-branch https://github.com/azugfr/functions-customer-reviews.git
-depth 1 --single-branch options will limit download to the tip of master branch. The full history will not be downloaded.
- Windows:
-
Type this command to navigate inside the repo and list content.
cd .\functions-customer-reviews\ ls
The folders doc and Media contain images and instructions for differents labs and demo. The Source folder contains source code of the sample. The Provision folder contains the scripts to create assets required for [lab 02](../02 - Visual Studio) and [lab 03](../03 - Continuous Delivery). The Reset folder contains the scripts to clean up and pre filled images.
The next step is to create the assets that the Customer Reviews solution relies on.
The Provision
folder contains an Azure Resource Manager template file Provision\assets\template.json. This file describe all the to be created Azure assets:
- Storage account
- CosmosDB is the evolution of DocumentDB. DocumentDB is still the name use in the template for asset name and variables.
- Cognitives Services Computer Vision (Image analysis)
- Cognitives Services Content Moderator (Text analysis)
- Azure Web Site
- Application Insights and a specific dashboard "Reviews Insights"
- Azure Function App
In this exercise, you will create these assets.
-
In the Azure Cloud Shell, type this command to open the
parameters.json
file invim
.vim ./Provision/assets/parameters.json
vim
essentials : quick reference cardx
to delete charactersi
to insert charactersEsc
to get out of insertin mode:qn
to save and exit!:q
to exit without saving
-
Select first letter of UNIQUE SMALL VALUE, type
x
to delete letters, repeat to keep only quotation marks. -
Type
i
and enter a small unique value . This will be used for all asset names (cognitive services, storage accounts, web app and service plan, CosmosDB) so make sure it's unique, only use lower case characters, type between 4 - 12 alphamerical characters.yourunique2135 will likely not work as another one will probably have been taken by another user. I did.
-
Type
Esc
to quit insert mode. Type:wq
to save and quitvim
. -
Type this command, and copy your SubscriptionId. Select it and type
Ctrl-insert
az account list
Under Azure: folder you can browse all assets of your current connected subscription like in a filesystem.
-
Type these commands to launch the script that will create the assets.
cd .\Provision\assets\ .\deploy.ps1
Use this values for each prompted variables:
- subscriptionId: Paste your copied SubscriptionId value from the previous step. Type
Shift-Insert
- resourceGroupName: customerreview
- deploymentName: customerreview
- subscriptionId: Paste your copied SubscriptionId value from the previous step. Type
-
After a few seconds, type region: West Europe
regions available for all assets: East US, South Central US, North Europe, West Europe, Southeast Asia, West US 2
-
Wait a few minutes. Return to Azure portal, click to Resource groups > Overview > customerreview to follow assets provisioning.
At the end, the log should look like this one:
-
Open a new browser tab. Type this url http://your_unique_namesite.azurewebsites.net
Site can take a few more minutes to be deployed by Kudu from this repo. This document page explains how to do it.
Web site deploying
Web site is ready. But still empty and need some images.
The assets are now all deployed and running. Now it's time to add some samples images to the web site.
Your website is configured to get images from CosmosDB collections that you created in Exercise 3. These collections are not set, thus the Error on the web site. The Reset
folder contains the scripts to set access to your CosmosDB and storage account. In this exercise, you will set collections, upload images to the CosmosDB, and reset any previous data.
-
In the Azure Cloud Shell, Type these commands.
cd ../Reset/ .\SetConfigXmlParameters.ps1 -resourceGroup customerreview -uniqueKey your_unique_name
!Warning! replace your_unique_name by the value you used in Exercise 3
!Warning! you might also replace customerreview by the resourceGroup name you used -
Type this command.
vim config.xml
Make sure all uppercase values are replaced by values. DocumentDbKey must not be empty. If it's stay empty, you might have started
SetConfigParameters.ps1
when pasting the command. It's common. You can resetconfig.xml
file by typing:
git checkout .\config.xml
-
Type
!:q
to exitvim
without saving.Type!:q
to exitvim
without saving. -
Type this command
./setup/reset.azure.ps1 config.xml
There may be some errors during cleaning as there are no collection in CosmosDB set yet.
-
Open a new browser tab. Type this url http://your_unique_namesite.azurewebsites.net
You may need to force a refresh of the content, type
Ctrl-F5
.
In this hands-on lab you learned how to:
- Create assets with Azure Resource Manager templates
- Execute PowerShell and Command srcipts in Azure Cloud Shell
- Use Azure Web Apps and deployment engine (Kudu) to automate build and deploy of a Web site from a GitHub repo.
This is just one example of how you can leverage Azure Resource Managemeer and Azure Cloud Shell to automate infrastructure. Experiment with other Azure Resource Manager templates to learn more about Azure Services and provisionning to identify additional ways in which they can aid your research or business.