azure - 从单个管道和存储库部署多个 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
可以做得更好。我将如何为节点快递服务器和反应应用程序做这件事?
理想情况下,我可以启动这两个应用程序,它们将在域上运行,如下所示:
- thisproject.domain.com/app
- thisproject.domain.com/project
真的不确定最好的方法,我对像这样的天蓝色管道非常业余。
解决方案
您可以使用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 示例的更多信息
推荐阅读
- sql - 是否有 PL/SQL 函数来计算超类型的 n 个子类型的数量?
- java - 如何索引大量排列?
- laravel - 收到此错误;“响应内容必须是实现 __toString() 的字符串或对象,给出的“布尔值”。”
- c# - 使用 Visual Studio 2019 for Mac 和 React-Native Android 模拟器验证 HTTPS 连接失败
- javascript - file.getOwner() 返回“DriveUser”值,而不是谷歌应用脚本中文件的实际所有者
- visual-studio - 如何在 bazel 中为 Visual Studio 指定 c++17?
- python - 对每个 ID 的关联 ID 求和布尔值并将其分配给 ID
- java - Android 上的 UDP 数据接收慢
- bash - 仅从 TSV 文件的双引号字符串中删除制表符?
- powershell - 点击登录按钮