通过VSTS在Azure部署中包括节点模块 [英] Include node modules in azure deployment via VSTS

查看:77
本文介绍了通过VSTS在Azure部署中包括节点模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个azure应用程序服务,我需要将其部署为VSTS中的发布定义的一部分. 为了提供一些上下文,它是一个ASP.NET MVC应用程序,并使用Angular2.它还具有package.json文件.我有一个VSTS构建定义,其中包括一个"npm install"任务,用于安装package.json中的所有依赖项,因此我不需要检入所有节点模块.在构建结束时,文件被删除到没有node_modules文件夹的共享中.

I have an azure app service which I need to deploy through as part of a release definition in VSTS. To provide some context, it is a ASP.NET MVC app and uses Angular 2. It also has a package.json file. I have a VSTS build definition which includes a 'npm install' task to install all dependencies from package.json, so that I don't need to check in all the node modules. At the end of the build the files are dropped to a share without the node_modules folder.

我有一个相应的发布定义以进行Web部署,以构建为Azure.但是,我不确定如何在azure计算机上获取node_modules文件夹. 有人可以针对这种情况提供帮助或提供建议吗?我希望可以通过某种方式将软件包npm安装在生产机器上.

I have a corresponding release definition to web deploy that build to azure. However, I am not sure how to get the node_modules folder on the azure machine. Can someone help or provide suggestions for this scenario? I was hoping the packages can be npm installed on the prod machine in some way.

推荐答案

您可以通过在PowerShell中使用Kudu API来实现.例如(package.json在wwwroot文件夹中)

You can do it by using Kudu API with PowerShell. For example (package.json is in wwwroot folder)

  1. 添加Azure PowerShell步骤/任务(脚本参数:-resourceGroupName VS-starain2-Group -webAppName tempappstarain -dir"site \ wwwroot"-命令"npm install")

PowerShell脚本:

PowerShell script:

param(
    [string]$resourceGroupName,
    [string]$webAppName,
    [string]$slotName="", 
    [string]$dir,
    [string]$command
)

function Get-AzureRmWebAppPublishingCredentials($resourceGroupName, $webAppName, $slotName = $null){
    if ([string]::IsNullOrWhiteSpace($slotName)){
        $resourceType = "Microsoft.Web/sites/config"
        $resourceName = "$webAppName/publishingcredentials"
    }
    else{
        $resourceType = "Microsoft.Web/sites/slots/config"
        $resourceName = "$webAppName/$slotName/publishingcredentials"
    }
    $publishingCredentials = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType $resourceType -ResourceName $resourceName -Action list -ApiVersion 2015-08-01 -Force
    Write-Host $publishingCredentials   
    return $publishingCredentials
}
function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName, $slotName = $null){
    $publishingCredentials = Get-AzureRmWebAppPublishingCredentials $resourceGroupName $webAppName $slotName
    Write-Host $publishingCredentials.Properties.PublishingUserName
    Write-Host $publishingCredentials.Properties.PublishingPassword
    return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}

function RunCommand($dir,$command,$resourceGroupName, $webAppName, $slotName = $null){
    $kuduApiAuthorisationToken = Get-KuduApiAuthorisationHeaderValue $resourceGroupName $webAppName $slotName
    $kuduApiUrl="https://$webAppName.scm.azurewebsites.net/api/command"
    $Body = 
      @{
      "command"=$command;
       "dir"=$dir
       } 
    $bodyContent=@($Body) | ConvertTo-Json
    Write-Host $bodyContent
     Invoke-RestMethod -Uri $kuduApiUrl `
                        -Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
                        -Method POST -ContentType "application/json" -Body $bodyContent
}

RunCommand $dir $command $resourceGroupName $webAppName

相关文章:您还可以只使用Azure App Service Deploy(将步骤/任务选择3. *版本,不要选中使用Web Deploy发布")来将node_module文件夹和文件部署到azure Web应用程序.程序包或查找器:[node_module文件夹路径])

You also can just deploy node_module folder and files to azure web app by using Azure App Service Deploy (Select 3.* version of step/task, do not check Publish using Web Deploy option. Package or foder: [node_module folder path])

这篇关于通过VSTS在Azure部署中包括节点模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆