Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

node.js - Azure DevOps Pipeline for QnA Bot

I am trying to get a build and release pipeline for the this sample chatbot -> https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/javascript_nodejs/49.qnamaker-all-features

I already have all the infrastructure resources in place. I plan to automate this later. But the for the moment I just need to deploy the code. Can I get some help on this?

The Azure Project has the Repo with the code checked in.

What does the Build Pipeline need to look like?

  1. I think I need to do an npm install for packages
  2. generate the web.config using az bot prepare-deploy --code-dir "." --lang Javascript
  3. generate a zip file.

What does the Release Pipeline need to look like?

  1. I think I neeed to run az webapp deployment source config-zip --resource-group "" --name "" --src "<zipfile_from_build>"

This is how far I have gotten:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js 10.x'

- script: |
    npm install
  displayName: 'Install all modules'

Any help appreciated!

Thanks in advance, Jake.

UPDATE: Here is my final yaml

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
     npm install
  displayName: 'npm install and build'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.SourcesDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: myTestBot'
  inputs:
    ConnectedServiceName: 'Release-Service-Connection'  
    azureSubscription: 'subscriptionName'
    WebAppName: 'BotName'
    ResourceGroupName: 'rgName'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    WebConfigParameters: '-Handler iisnode -NodeStartFile index.js -appType node' 
question from:https://stackoverflow.com/questions/65946687/azure-devops-pipeline-for-qna-bot

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is not need to generate the web.config using az bot. Azure App Service deploy task can generate the web.config automatic. You can check out below examples.

trigger:
- main
pool:
  vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
     npm install
  displayName: 'npm install and build'

  #generate zip package using archivefile task.
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'Build.SourcesDirectory'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
  
  #publish artifacts to azure devops server to be used in Release pipeline.
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Please check out the example Build, test, and deploy JavaScript and Node.js apps for more information.

Before creating Release pipeline. You need to create an azure Resource Manager service connection to connect your Azure subscription to Azure devops. See this thread for an example.

Then you can create release pipeline, Add the artifacts published by above build pipeline as the pipeline Artifacts resource. And add stages. Using Azure App Service deploy task in the release pipeline.

You can configure the Azure App Service deploy task to generate web.config. Also see here for more information.

enter image description here

You can also check out the example in this blog.

Actually you can directly use the Azure App Service deploy in the build pipeline without creating release pipeline.

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'samples/javascript_nodejs/49.qnamaker-all-features'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
  
- task: AzureRmWebAppDeployment@4
  displayName: 'Azure App Service Deploy: leviwebApp'
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    WebAppName: leviwebApp
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    WebConfigParameters: '-Handler iisnode -NodeStartFile index.js -appType node'

Above method using build/release pipeline and deployment task is the general way to deploy to azure app service.

However, you can also write az cli commnads in the azure cli task in the build pipeline to deploy to azure app service. See below example:

 ....
- script: |
    cd samples/javascript_nodejs/49.qnamaker-all-features
    npm install
    
  displayName: 'npm install and build'

- task: AzureCLI@2
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: 'az bot prepare-deploy --code-dir "." --lang Javascript'
   
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'Build.SourcesDirectory'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
- task: AzureCLI@2
  inputs:
    azureSubscription: 'azure Resource Manager service connection'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: 'az webapp deployment source config-zip --resource-group "<resource-group-name>" --name "<name-of-web-app>" --src "<project-zip-path>"'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...