The goal of this lab is to take an existing web application and move it from a standard deployment using on premises web farms to a container infrastructure on Azure. This will enable a much more saleable environment with a lot less management. In this lab you will:
You will need a few things in your environment setup for this lab.
The source code for all three projects are in this repo. We will first pull it all down locally in our Azure Bash Shell.
Launch a new Azure Command Shell. You can either:
Pull down the source code locally. Run the following git command
git clone https://github.com/chadgms/2019AzureMigrateYourApps
If you do an ls command you should see the repo on your local shell
Now we get into the really exciting stuff! We have an existing code base for our two services and web front end. These steps will compile the code, put them in a docker container and put the container image into the container registry. Typically you would need Docker installed and configured. Azure Container Registry Service can do the build and containerization for us all on the cloud! We just need to point it to our source code.
In your Azure Cloud Shell, set an environment variable to the name of your Azure Container Registry (ACR). It is the name you put in the Registry Name property when you created the registry - (prefix)acr. (Do NOT use the full .azurecr.io UNC, only the name)
MYRG=<your Resource Group name>
MYACR=(prefix)acr
MYID=(prefix)
Run the following command to build the code and push the product service image to the ACR.
az acr build -t product-service:latest -r $MYACR ./src/product-service
When finished you can confirm that the container was deployed to ACR in the portal.
Build the inventory service and frontend containers.**
az acr build -t inventory-service:latest -r $MYACR ./src/inventory-service/InventoryService.Api
az acr build -t frontend-service:latest -r $MYACR ./src/frontend
Verify it exists in the ACR same as before
Now that we have compiled code in containers stored in the registry we now need to deploy them to a compute platform. In this lab we are going to use Azure Web App for Containers, but there are many ways to run containers in Azure. Your instructor should have explored other options. See reference links below for more information.
We now have web apps created for all our resources. The last thing we need to do is configure application environment variables like connections strings. When the services start up they can read the environment variables so we can make configurations at runtime.
The product service uses the NOSQL data that was in the on-premise MongoDB. We successfully migrated that data to Cosmos DB, so that is what we will configure our Product Service for.
Note: If you were unable to finish Lab 1 and do not have a CosmosDB with data in it. See the appendix at the end of this lab for a connection string to a shared instance you can use.
Click on resource groups-> (your resource group)
Click on your Cosmos DB Account
Click on the Connection String option in the left toolbar
Copy the Primary Connection String (NOT the primary password)
Click on resource groups -> (your resource group)
Click on your product service resource of type ‘App Service’
Click Configuration on the left nav bar
Here you will see some default application setting. We will add a few more.
Name: COLLECTION_NAME Value: inventory - > Press OK
Name: DB_CONNECTION_STRING Value: (paste in the Cosmos DB connection String)
IMPORTANT: We need to add the database name ‘tailwind’ to the connection string. You will see the server address:port and the the /?ssl flag like this:
...azure.com:10255/?ssl...
You add the tailwind database name between them like this:
..azure.com:10255/tailwind?ssl...
You should have two app settings something like this
Note: Connection strings can also be resolved from Key Vault using Key Vault references. We are not using Key Vault for this lab, but these are good references to review.
The inventory service needs to be pointed to the SQL Database that now lives in Azure SQL Azure
The last thing we need to do is to tell our front end web site the URL’s to our web services for product and inventory.
You can get the base URLs for inventory and product services by clicking on their overview page and looking at the URL property on the right hand side.
We will now set the Front End application settings using the Azure Cli: Copy the below code and replace the base URL placeholders with the URL’s of your services.
Note: If you closed the command window you may have lost the values for the initial environment variables we setup. You may need to redefine MYRG and MYID again.
az webapp config appsettings set --resource-group $MYRG --name "$MYID"frontend --settings INVENTORY_SERVICE_BASE_URL='<your inventory base url>' PRODUCT_SERVICE_BASE_URL='<your product service base url>'
That is is it! We are done migrating the data and deploying a modern application through containers. The last thing to do is to run the app and make sure it works! (Note: the web page will render pretty quickly, but the data may take 2-3 minutes to show up. If it takes longer than 3-4 minutes the we should start to debug)
Your web app should now be live! Congratulations!
If you could not complete Lab 1 and do not have either an Azure SQL Instance or Cosmos DB instance completed with data then you can use the connection strings below for your Inventory and Product services.
Inventory
Server=tcp:chad1558sqlserver.database.windows.net,1433;Initial Catalog=chad1558SQLDB;Persist Security Info=False;User ID=migrateadmin;Password=AzureMigrateTraining2019#;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
Product
mongodb://migapp2cosmosdb:k6GiFd3f09fgFs5Qefxs2ykJeNgRME2fRj1d4PDh0ZcEXlTwk0hLN2hnOpfLZ3sME4chXAkD4M6SAoogAUc1Jg==@migapp2cosmosdb.documents.azure.com:10255/tailwind?ssl=true&replicaSet=globaldb