Scenarios and samples for Mounting Azure Storage as a local share in a container app in App Service
Published Oct 28 2021 06:36 PM 7,623 Views
Microsoft

Developers can mount Azure Files as a directory share in Linux App Service (source code and custom Linux container), Windows containerand Windows Code (Preview)

The benefits of custom-mounted storage include:

  • Configure persistent storage for your App Service app and manage the storage separately.
  • Make static content like video and images readily available for your App Service app.
  • Write application log files or archive older application log to Azure File shares.
  • Share content across multiple apps or with other Azure services.

Let’s try to understand custom mounted storage benefits listed above using a real-life business scenario explained below:

 

  • Department A of a company uploads images to a file share using a web app hosted on Azure App Services for windows containers.
  • Department B of the same company performs actions like watermarking, resizing of the images uploaded by department A using a web app hosted on Azure App Services for Linux.
  • Azure SQL and Azure Storage File share are accessible only within the Azure VNET

 

Diagram below depicts sample deployment architecture for the scenario mentioned above:

 

 

blog_arch.png

 

<<Please note that the steps provided below are suited for successful deployment and execution of sample web applications provided as part of this blog. You should make necessary modifications as per your web application code and configuration requirements>>

 

Step 1: Create Azure Storage account, Create Azure App services Web App (Windows Container), Create Azure SQL Database, Configure an Azure File Share as a local share for your Web App and Configure Regional VNET integration

 

  1. Create an Azure App Services Web App for Windows Container (https://docs.microsoft.com/en-us/azure/app-service/quickstart-custom-container?tabs=dotnet&pivots=co... )
  2. Create an Azure SQL Database (https://docs.microsoft.com/en-us/azure/azure-sql/database/single-database-create-quickstart?tabs=azu... )
  3. Setup Regional VNET Integration for private connectivity between web app and database (https://docs.microsoft.com/en-us/azure/architecture/example-scenario/private-web-app/private-web-app )
  4. Deploy your web app code to Azure App Services web app for Windows Container created in step 1. Sample Source code for Image Upload Application is available at byosCPUplDwn/byosWinContUpload at master · gsethgit/byosCPUplDwn (github.com) and the sample app is available at https://gsethbyosblogwcont.azurewebsites.net
  5. Create Azure Storage Account & an Azure Files share and Setup Private Endpoint (https://docs.microsoft.com/en-us/azure/storage/common/storage-private-endpoints )
  6. Configure Azure Files share created in step 5 as local share for you Image Upload (Windows Container) web app(https://docs.microsoft.com/en-us/azure/app-service/configure-connect-to-azure-storage?tabs=portal&pi... )

 

If you want to use Azure Portal for custom mount configuration then refer to Azure How-To YouTube video  which guides you on how to mount custom storage in Azure App services and configure Private endpoint connection between your web app and Azure Storage files mount   How to mount Azure Storage as a local share in a container app in App Service | Azure Portal Series ...

 

            You can also mount custom storage for your web app using below mentioned Azure Cli commands:

 

az webapp config storage-account add --resource-group <group-name> --name <app-name> --custom-id <custom-id> --storage-type AzureFiles --share-name <share-name> --account-name <storage-account-name> --access-key "<access-key>" --mount-path <mount-path-directory>

 

Sample::: az webapp config storage-account add --resource-group sampleresourcegroup --name sampleapp1 --custom-id customblogstore --storage-type AzureFiles --share-name blogshare --account-name samplestorageaccountname --access-key "samplestorageaccountkey" --mount-path /blogstore

 

Verify your configuration by running the following command:

 

az webapp config storage-account list –resource-group <resource-group> --name <app-name>

 

Sample ::: az webapp config storage-account list –resource-group sampleresourcegroup --name sampleapp1

 

Important::: We also need to provide mount path in both the sample application code provided . Now there are 2 ways to provide value of mount path app setting for the sample applications :

 

1) Using an app setting in appsettings.json file

 

gauravseth_1-1635543610975.png

 

2) Using Azure Portal to Create an "Application Setting " for your web app (Configure apps in the portal - Azure App Service | Microsoft Docs

 

gauravseth_0-1635543420568.png

 

*** Important

  • If you define "uploadPath” App Setting in both the places as shown above then the value of "uploadPath" provided in the Azure Portal will override the value provided in appsettings.json file.
  • App setting is named "uploadPath" for successful execution of sample code provided as part of this blog. You may choose any name for the app setting for your web application

 

Step 2: Create Azure App services Web App (Linux) and Configure an Azure File Share as a local share for your Web App

 

  1. Create an Azure App Services Web App for Linux (https://docs.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore?tabs=net50&pivots=developme... )
  2. Deploy your web app code to Azure App Services web app for Linux created in step 1. Sample Source code for Image Processing Application is available at byosCPUplDwn/byosLinuxImageWTM at master · gsethgit/byosCPUplDwn (github.com) and the sample app is available at https://gsethbyosbloglinux.azurewebsites.net/
  3. Configure Azure Files share created above as local share for you Image Processing (Linux) web app (https://docs.microsoft.com/en-us/azure/app-service/configure-connect-to-azure-storage?tabs=portal&pi... )

 

*** Mount same Azure File Share for both the web apps for content sharing between these sample web applications provided with this blog

 

Sample::: az webapp config storage-account add --resource-group sampleresourcegroup --name sampleapp2 --custom-id customblogstore --storage-type AzureFiles --share-name blogshare --account-name samplestorageaccountname --access-key "samplestorageaccountkey" --mount-path /blogstore

 

Verify your configuration by running the following command:

 

az webapp config storage-account list –resource-group <resource-group> --name <app-name>

 

Sample ::: az webapp config storage-account list –resource-group sampleresourcegroup --name sampleapp2

 

Important::: We also need to provide mount path in both the sample application code provided . Now there are 2 ways to provide value of mount path app setting for the sample applications :

 

1) Using an app setting in appsettings.json file

 

gauravseth_1-1635543610975.png

 

2) Using Azure Portal to Create an "Application Setting " for your web app (Configure apps in the portal - Azure App Service | Microsoft Docs

 

gauravseth_0-1635543420568.png

 

*** Important

  • If you define "uploadPath” App Setting in both the places as shown above then the value of "uploadPath" provided in the Azure Portal will override the value provided in appsettings.json file.
  • App setting is named "uploadPath" for successful execution of sample code provided as part of this blog. You may choose any name for the app setting for your web applications

 

There are many different scenarios that can be enabled using the sample described above and the apps that are producing and consuming the content may be developed in technology of your choice including legacy frameworks enabling wide variety of app dev scenarios on Azure App Services ex: Invoice processing, Image processing, Content publishing to name a few.

 

As you can see that the content stored on same custom mounted storage can be shared across multiple web apps hosted within Azure App services and even across other Azure services like Azure VMS’s etc. while ensuring secure end to end access to your content across these Azure resources via Azure VNET integration.

Co-Authors
Version history
Last update:
‎Apr 27 2022 01:27 PM
Updated by: