Alper Silistre
Alper Silistre

Reputation: 167

How to re-deploy Azure Web App ARM template without resetting the deployed application

We are having difficulty to understand what's the best way to deploy Azure Web App ARM template for an existing application, without causing the deployed application being reset in the resource.

The scenario is we have ARM templates for resource creation, and we are deploying resources with the help of Azure yml pipeline. The two main resource we are deploying are:

ARM Template: https://gist.github.com/alpersilistre/54741b165365a55811ae87498dbd415b

The task that we use for this operation is AzureResourceGroupDeployment@2.

Then, we have another yml file to deploy a web application to this Azure Web app resource. We are first building and publishing a .NET app with DotNetCoreCLI build and publish comments, then in the following steps we are downloading the published artifact and doing a deployment with this AzureRMWebAppDeployment@4 task.

This flow works as expected. However, whenever we run our infrastructure pipeline and the ARM deployments run again, our application in the resource get reset, and we face with the default Azure App Service blue screen.

enter image description here

My questions, what's the way to prevent this?

I don't want my application to be reset when I run my infra pipeline. We don't set deploymentMode, so the default is Incremental. But still, every time we need to deploy our application again and this cause a downtime for us.

Upvotes: 1

Views: 712

Answers (1)

SiddheshDesai
SiddheshDesai

Reputation: 8167

I ran the below pipeline to deploy the Web app resource via your ARM template task and then Azure Web app source code to the deployed Web app and it was successful, Refer below:-

trigger:
- master

pool:
  vmImage: ubuntu-latest

  variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'
- task: AzureResourceManagerTemplateDeployment@3
  inputs:
      deploymentScope: 'Resource Group'
      azureResourceManagerConnection: '<subscription>'
      subscriptionId: '<sub-id>'
      action: 'Create Or Update Resource Group'
      resourceGroupName: 'siliconrg'
      location: 'Australia East'
      templateLocation: 'Linked artifact'
      csmFile: '$(System.DefaultWorkingDirectory)/WebArm.json'
      deploymentMode: 'Incremental'
      overrideParameters: '-applicationName "silicon-webapp451" -environment "Windows"'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'


- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: '<subscription>'
    appType: 'webApp'
    WebAppName: 'silicon-webapp451-Windows'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'

Output:-

Web app resource deployed:-

enter image description here

Web app page loaded successfully:-

enter image description here

Now, I ran the pipeline again by replacing the applicationName and environment names to the new desired environment and the new web application was deployed successfully without loading the Default page:-

enter image description here

overrideParameters: '-applicationName "valley-webapp461" -environment "Windows"'

Changed the web app name in AzureRmWebAppDeploy task to match the new web app and environment name like below:-

WebAppName: 'valley-webapp461-Windows'

enter image description here

Output:-

enter image description here

enter image description here

enter image description here

My Azure DevOps repository:-

enter image description here

enter image description here

As a workaround you can add Deployment slot parameter in your ARM template and deploy 2 slots one for staging and another one for Production and deploy your Web app in staging first and check if the deployment is succeeded then deploy it in Production slot.

Upvotes: 0

Related Questions