Search code examples
azureazure-devopsazure-pipelinesazure-rm-templateazure-bot-service

How to deploy a bot framework app to azure using a zip file and an ARM template?


We're trying to deploy a prebuilt bot artefact into tenants via ARM deployments kicked off with REST APIs. We're struggling to replicate the actions of a gui based deployment from vs code / visual studio given that all the docs use the az cli. A manual deploy ends up with an app that includes dlls at the top level whereas our current route doesn't include the built dlls.

Our pipeline for producing our bot artifact is:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: AzureCLI@2
  inputs:
    azureSubscription: 'GoSmarter Azure Service Connection'
    scriptType: 'ps'
    scriptLocation: 'scriptPath'
    scriptPath: 'az-Prepare.ps1'

Where az-Prepare.ps1 includes az bot prepare-deploy --lang Csharp --code-dir $codeDirectory --proj-file-path $projectFileName to produce the zip of the bot app so that we can put it into blob storage for use in the ARM template.

We then use an MSDeploy ARM resource to deploy this zip file as part of a bigger provisioning step.

    {
      "name": "MSDeploy",
      "type": "extensions",
      "location": "[variables('resourcesLocation')]",
      "apiVersion": "2015-08-01",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', variables('webAppName'))]"
      ],
      "tags": {
        "displayName": "deployArchive"
      },
      "properties": {
        "packageUri": "[concat(variables('source'),'qnabotarchive.zip',parameters('SasToken'))]",
        "dbType": "None",
        "connectionString": ""
      }
    }

We tried setting the Kudu App Setting for triggering builds to true but this doesn't seem to apply to MSDeploy provided zips so doesn't do a promotion of the dlls.

        {
          "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
          "value": "true"
        }

Does anyone know what the right way is to configure the build, the app and/or the ARM template for the bot deployment to provide the dlls at the top level?


Solution

  • In the end, we opted for using dotnet core commands to build the bot solution.

    steps:
    - task: NuGetToolInstaller@1
    
    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'
    
    - task: DotNetCoreCLI@2
      inputs:
        command: 'build'
        projects: '$(project)'
        arguments: '--configuration $(BuildConfiguration) -p:langversion=latest'
      displayName: "Build solution"
    
    - task: DotNetCoreCLI@2
      displayName: "Publish Build Output"
      inputs:
        command: 'publish'
        publishWebProjects: true
        arguments: '--configuration $(BuildConfiguration) -p:langversion=latest --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: false
    
    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
    
    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/QnABot/*'
        includeRootFolder: true
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/Chatbots/qnabotarchive.zip'
        replaceExistingArchive: true