Search code examples
azureazure-devopsazure-storagegitlab-ci.yml

How to add an Azure File share as a volume in Azure Pipeline


I'm using Azure Devops to build and push a docker container to the container registry.

I need to enable persistent storage. So I've created a file system and a fileshare. How would I now go about adding this file share to the resulting web app container when it's deployed? Say at a path of /var/www/html/shared_storage

My yml file for the pipeline is:

trigger:
- master

resources:
- repo: self

variables:
  dockerRegistryServiceConnection: 'xxxx'
  imageRepository: 'xxx'
  containerRegistry: 'xxx.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  vmImageName: 'ubuntu-latest'
  
  - stage: Build_Master
    condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
    displayName: Build master
    jobs:
    - job: Build
      displayName: Build
      pool:
        vmImage: $(vmImageName)
      steps:
      - task: Docker@2
        displayName: Build and push an image to container registry
        inputs:
          command: buildAndPush
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            master

I was hoping I could specify the connection details and then provide something like: volumes shared_storage:/var/www/html/shared_storage

But I can't seem to find any documentation for this.


Solution

  • You can mount a storage account to an Azure Web App for Containers using the following Azure CLI command:

    az webapp config storage-account add --resource-group MyResourceGroup --name MyUniqueApp \
      --custom-id CustomId --storage-type AzureFiles \
      --account-name MyStorageAccount --share-name MyShare \
      --access-key MyAccessKey --mount-path /path/to/mount
    

    Additionally, if using a Web App, in the Azure portal you can go to Configuration->path mappings and add a 'Storage Mount' to a filesystem in there.