2

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

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

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

有没有什么方法可以从这些远程计算机上运行的配置中轻松复制放置文件夹文件,而无需共享相同的网络和域?我成功地将虚拟机配置为使用证书通过 https 接受 DSC 调用,我刚刚发现Azure PowerShell cmdlet 使您能够将配置上传到 Azure 存储并在虚拟机中自动运行(这似乎比我做的要好得多) 但我仍然不知道在运行配置脚本时如何从虚拟机内部访问我的构建输出。

4

1 回答 1

1

我最终使用Publish-AzureVMDscExtensioncmdlet 创建了一个本地 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 扩展将文件夹复制到模块路径,认为它是一个模块。

我对这个解决方案还不完全满意,而且我已经遇到了一些问题,但在我看来这是有道理的,应该可以正常工作。

于 2014-10-30T13:05:10.053 回答