首页 > 解决方案 > 从单个管道和存储库部署多个 Web 应用程序

问题描述

目前我的回购有两个节点项目:./server./client

我想运行管道来安装这两个依赖项,然后在部署到“单个”代理/vm/子域时,我希望能够同时运行这两个依赖项。

  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool: 
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:            
          - task: AzureWebApp@1
            displayName: 'Azure Web App Deploy: tomyserver'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              appName: $(webAppName)
              runtimeStack: 'NODE|10.10'
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
              startUpCommand: 'cd server; yarn run startnode;'

我已将整个 repo 工件复制到 vm 中,目前仅部署用于服务器。它是如上所述的单一设置。我想扩展 startUpCommand 'cd server; yarn run startnode;'cd ../client; yarn run start可以做得更好。我将如何为节点快递服务器和反应应用程序做这件事?

理想情况下,我可以启动这两个应用程序,它们将在域上运行,如下所示:

真的不确定最好的方法,我对像这样的天蓝色管道非常业余。

标签: azureazure-devopsazure-pipelines

解决方案


您可以使用Kudu api来执行cd ../client; yarn run start命令。

为了调用 kudu api,您需要在 AzureWebApp 任务之后添加一个 azure powershell 任务以在下面的内联脚本中运行。

在您的工件部署到 azure Web 应用程序之后。您可以通过访问来检查您的 azure Web 应用程序部署环境https://{{YOUR-APP-NAME}}.scm.azurewebsites.net/api/zip/site/{{FOLDER}}

$apiCommand您可以通过访问上面的站点并决定执行目录来检查您的 azure web 部署文件夹。通常是dir="D:\home\site\wwwroot".

steps:
- task: AzurePowerShell@4
  displayName: 'Azure PowerShell script: InlineScript' 
  inputs:    
    azureSubscription: '<...>'
    ScriptType: InlineScript
    Inline: |
     $ResGroupName = "<..>"
     $WebAppName = "<..>"

     # Get publishing profile for web application
     $WebApp = Get-AzWebApp -Name $WebAppName -ResourceGroupName $ResGroupName
     [xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp

     # Create Base64 authorization header
     $username = $publishingProfile.publishData.publishProfile[0].userName
     $password = $publishingProfile.publishData.publishProfile[0].userPWD
     $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
     $apiBaseUrl = "https://$($WebApp.Name).scm.azurewebsites.net/api/command"

     $apiCommand = @{
              command = 'powershell.exe -command "cd client; yarn run start"'
              dir="D:\home\site\wwwroot"
         }
     Invoke-RestMethod -Uri $apiBaseUrl -Headers @{"Authorization"="Basic $base64AuthInfo";"If-Match"="*"} -Method POST -ContentType "application/json" -Body (ConvertTo-Json $apiCommand)

    azurePowerShellVersion: LatestVersion

  enabled: false

上面的脚本从 Azure Web App 的发布配置文件中获取用户名和密码。调用kudu api执行命令需要用户名和密码。用户名和密码也可以在 azure 门户上检索(在 azure 门户上下载 Azure Web App 的发布配置文件)。

上述脚本中的 api 命令指示该命令在 azure Web 应用程序部署环境中执行。在上面的示例中,该命令将执行cd client; yarn run start以启动客户端应用程序。

请在此处查看有关kudu api 示例的更多信息


推荐阅读