【问题标题】:How do I transfer my build output files to an Azure VM using PowerShell DSC?如何使用 PowerShell DSC 将生成输出文件传输到 Azure VM?
【发布时间】:2014-12-19 07:27:23
【问题描述】:

我一直在玩弄 DSC,我认为它是一个很棒的平台。我做了一些测试来自动部署我们的 TFS 构建输出并自动安装 Web 应用程序并配置环境。

这相对容易,因为我可以使用内部网络上的文件共享将我的放置文件夹路径传递给 DSC 脚本,并使用配置中的相对路径来选择我们的每个模块。

我现在的问题是如何将其扩展到 Azure 虚拟机。我们希望创建这些脚本以自动部署到托管在 Azure 上的 QA 和生产服务器。由于它们不在我们的域中,我不能再使用File 资源来传输文件,但同时我想要完全相同的功能:我想以某种方式将配置指向我们的构建输出文件夹并将文件从那里复制到虚拟机。

有没有什么方法可以轻松地从这些远程计算机上运行的配置中复制放置文件夹文件,而无需共享相同的网络和域?我成功地将虚拟机配置为使用证书通过 https 接受 DSC 调用,我刚刚发现 the Azure PowerShell cmdlets enable you to upload a configuration to Azure storage and run it in the VMs automatically(这似乎比我所做的要好得多)但我仍然不知道如何访问我的构建运行配置脚本时从虚拟机内部输出。

【问题讨论】:

  • Release Management 的 DSC 实现将生成输出放在 Azure 存储帐户中。你考虑过这样做吗?
  • @DanielMann 我不知道 RM 这样做了,很有趣。它是否记录在某处?这就是我可能最终会做的事情,现在我想了想。我只需要将我的 drop 文件添加到以某种方式发布到 azure storage 的 zip 中,然后我就不需要直接访问 drop 了。我想远离新管道,因为它们支持部署任务......这对我来说还不够,我需要在工作流上运行任意操作,就像我在另一个问题中提到的那样,例如将我的 android apk 部署到 google play。
  • 我认为它没有在任何地方记录,但大概是使用 Azure SDK 将二进制文件从构建 drop/RM 服务器推送到 Azure 存储,然后在部署目标上执行某些操作以下载二进制文件从 Azure 存储。 Azure API 绝对可以做到这一点,因此只需将您自己的 API 组合在一起即可。

标签: deployment azure-storage file-transfer azure-virtual-machine dsc


【解决方案1】:

我最终使用 Publish-AzureVMDscExtension cmdlet 创建了一个本地 zip 文件,将我的构建输出附加到 zip,然后发布 zip,类似于这些行:

function Publish-AzureDscConfiguration
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory)]
        [string] $ConfigurationPath
    )

    Begin{}
    Process
    {
        $zippedConfigurationPath = "$ConfigurationPath.zip";

        Publish-AzureVMDscConfiguration -ConfigurationPath:$ConfigurationPath -ConfigurationArchivePath:$zippedConfigurationPath -Force

        $tempFolderName = [System.Guid]::NewGuid().ToString();
        $tempFolderPath = "$env:TEMP\$tempFolderName";
        $dropFolderPath = "$tempFolderPath\BuildDrop";

        try{
            Write-Verbose "Creating temporary folder and symbolic link to build outputs at '$tempFolderPath' ...";
            New-Item -ItemType:Directory -Path:$tempFolderPath;
            New-Symlink -LiteralPath:$dropFolderPath -TargetPath:$PWD;
            Invoke-Expression ".\7za a $tempFolderPath\BuildDrop.zip $dropFolderPath -r -x!'7za.exe' -x!'DscDeployment.ps1'";

            Write-Verbose "Adding component files to DSC package in '$zippedConfigurationPath'...";
            Invoke-Expression ".\7za a $zippedConfigurationPath $dropFolderPath.zip";
        }
        finally{
            Write-Verbose "Removing symbolic link and temporary folder at '$tempFolderPath'...";
            Remove-ReparsePoint -Path:$dropFolderPath;
            Remove-Item -Path:$tempFolderPath -Recurse -Force;
        }
        Publish-AzureVMDscConfiguration -ConfigurationPath:$zippedConfigurationPath -Force
    }
    End{}
}

通过在 Azure 使用的 zip 中使用 zip,我可以访问 PowerShell DSC 扩展的工作目录(在 DSCWork 文件夹中)中的内部内容。我尝试直接将放置文件夹添加到 zip 中(不先压缩它),但随后 DSC 扩展将文件夹复制到模块路径,认为它是一个模块。

我对这个解决方案还不完全满意,我有a few problems already,但在我看来它是有道理的,应该可以正常工作。

【讨论】:

    猜你喜欢
    • 2021-01-11
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多