Skip to content

Commit 5d2d2dc

Browse files
committed
VMs deploy doc added
VMs deploy template updated SQL deploy template
1 parent 76b6ec2 commit 5d2d2dc

16 files changed

Lines changed: 734 additions & 18 deletions

deploy/arm/eShopOnAzure.Deploy.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.6
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{151D2E53-A2C4-4D7D-83FE-D05416EBD58E}") = "eShopOnAzure.Deploy", "eShopOnAzure.Deploy\eShopOnAzure.Deploy.deployproj", "{642B3F2E-3011-4B1A-8D22-D35C11C44F05}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{642B3F2E-3011-4B1A-8D22-D35C11C44F05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{642B3F2E-3011-4B1A-8D22-D35C11C44F05}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{642B3F2E-3011-4B1A-8D22-D35C11C44F05}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{642B3F2E-3011-4B1A-8D22-D35C11C44F05}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#Requires -Version 3.0
2+
#Requires -Module AzureRM.Resources
3+
#Requires -Module Azure.Storage
4+
5+
Param(
6+
[string] [Parameter(Mandatory=$true)] $ResourceGroupLocation,
7+
[string] $ResourceGroupName = 'eShopOnAzure.Deploy',
8+
[switch] $UploadArtifacts,
9+
[string] $StorageAccountName,
10+
[string] $StorageContainerName = $ResourceGroupName.ToLowerInvariant() + '-stageartifacts',
11+
[string] $TemplateFile = 'azuredeploy.json',
12+
[string] $TemplateParametersFile = 'azuredeploy.parameters.json',
13+
[string] $ArtifactStagingDirectory = '.',
14+
[string] $DSCSourceFolder = 'DSC',
15+
[switch] $ValidateOnly
16+
)
17+
18+
try {
19+
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("VSAzureTools-$UI$($host.name)".replace(' ','_'), '3.0.0')
20+
} catch { }
21+
22+
$ErrorActionPreference = 'Stop'
23+
Set-StrictMode -Version 3
24+
25+
function Format-ValidationOutput {
26+
param ($ValidationOutput, [int] $Depth = 0)
27+
Set-StrictMode -Off
28+
return @($ValidationOutput | Where-Object { $_ -ne $null } | ForEach-Object { @(' ' * $Depth + ': ' + $_.Message) + @(Format-ValidationOutput @($_.Details) ($Depth + 1)) })
29+
}
30+
31+
$OptionalParameters = New-Object -TypeName Hashtable
32+
$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile))
33+
$TemplateParametersFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateParametersFile))
34+
35+
if ($UploadArtifacts) {
36+
# Convert relative paths to absolute paths if needed
37+
$ArtifactStagingDirectory = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $ArtifactStagingDirectory))
38+
$DSCSourceFolder = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $DSCSourceFolder))
39+
40+
# Parse the parameter file and update the values of artifacts location and artifacts location SAS token if they are present
41+
$JsonParameters = Get-Content $TemplateParametersFile -Raw | ConvertFrom-Json
42+
if (($JsonParameters | Get-Member -Type NoteProperty 'parameters') -ne $null) {
43+
$JsonParameters = $JsonParameters.parameters
44+
}
45+
$ArtifactsLocationName = '_artifactsLocation'
46+
$ArtifactsLocationSasTokenName = '_artifactsLocationSasToken'
47+
$OptionalParameters[$ArtifactsLocationName] = $JsonParameters | Select -Expand $ArtifactsLocationName -ErrorAction Ignore | Select -Expand 'value' -ErrorAction Ignore
48+
$OptionalParameters[$ArtifactsLocationSasTokenName] = $JsonParameters | Select -Expand $ArtifactsLocationSasTokenName -ErrorAction Ignore | Select -Expand 'value' -ErrorAction Ignore
49+
50+
# Create DSC configuration archive
51+
if (Test-Path $DSCSourceFolder) {
52+
$DSCSourceFilePaths = @(Get-ChildItem $DSCSourceFolder -File -Filter '*.ps1' | ForEach-Object -Process {$_.FullName})
53+
foreach ($DSCSourceFilePath in $DSCSourceFilePaths) {
54+
$DSCArchiveFilePath = $DSCSourceFilePath.Substring(0, $DSCSourceFilePath.Length - 4) + '.zip'
55+
Publish-AzureRmVMDscConfiguration $DSCSourceFilePath -OutputArchivePath $DSCArchiveFilePath -Force -Verbose
56+
}
57+
}
58+
59+
# Create a storage account name if none was provided
60+
if ($StorageAccountName -eq '') {
61+
$StorageAccountName = 'stage' + ((Get-AzureRmContext).Subscription.SubscriptionId).Replace('-', '').substring(0, 19)
62+
}
63+
64+
$StorageAccount = (Get-AzureRmStorageAccount | Where-Object{$_.StorageAccountName -eq $StorageAccountName})
65+
66+
# Create the storage account if it doesn't already exist
67+
if ($StorageAccount -eq $null) {
68+
$StorageResourceGroupName = 'ARM_Deploy_Staging'
69+
New-AzureRmResourceGroup -Location "$ResourceGroupLocation" -Name $StorageResourceGroupName -Force
70+
$StorageAccount = New-AzureRmStorageAccount -StorageAccountName $StorageAccountName -Type 'Standard_LRS' -ResourceGroupName $StorageResourceGroupName -Location "$ResourceGroupLocation"
71+
}
72+
73+
# Generate the value for artifacts location if it is not provided in the parameter file
74+
if ($OptionalParameters[$ArtifactsLocationName] -eq $null) {
75+
$OptionalParameters[$ArtifactsLocationName] = $StorageAccount.Context.BlobEndPoint + $StorageContainerName
76+
}
77+
78+
# Copy files from the local storage staging location to the storage account container
79+
New-AzureStorageContainer -Name $StorageContainerName -Context $StorageAccount.Context -ErrorAction SilentlyContinue *>&1
80+
81+
$ArtifactFilePaths = Get-ChildItem $ArtifactStagingDirectory -Recurse -File | ForEach-Object -Process {$_.FullName}
82+
foreach ($SourcePath in $ArtifactFilePaths) {
83+
Set-AzureStorageBlobContent -File $SourcePath -Blob $SourcePath.Substring($ArtifactStagingDirectory.length + 1) `
84+
-Container $StorageContainerName -Context $StorageAccount.Context -Force
85+
}
86+
87+
# Generate a 4 hour SAS token for the artifacts location if one was not provided in the parameters file
88+
if ($OptionalParameters[$ArtifactsLocationSasTokenName] -eq $null) {
89+
$OptionalParameters[$ArtifactsLocationSasTokenName] = ConvertTo-SecureString -AsPlainText -Force `
90+
(New-AzureStorageContainerSASToken -Container $StorageContainerName -Context $StorageAccount.Context -Permission r -ExpiryTime (Get-Date).AddHours(4))
91+
}
92+
}
93+
94+
# Create or update the resource group using the specified template file and template parameters file
95+
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force
96+
97+
if ($ValidateOnly) {
98+
$ErrorMessages = Format-ValidationOutput (Test-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
99+
-TemplateFile $TemplateFile `
100+
-TemplateParameterFile $TemplateParametersFile `
101+
@OptionalParameters)
102+
if ($ErrorMessages) {
103+
Write-Output '', 'Validation returned the following errors:', @($ErrorMessages), '', 'Template is invalid.'
104+
}
105+
else {
106+
Write-Output '', 'Template is valid.'
107+
}
108+
}
109+
else {
110+
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
111+
-ResourceGroupName $ResourceGroupName `
112+
-TemplateFile $TemplateFile `
113+
-TemplateParameterFile $TemplateParametersFile `
114+
@OptionalParameters `
115+
-Force -Verbose `
116+
-ErrorVariable ErrorMessages
117+
if ($ErrorMessages) {
118+
Write-Output '', 'Template deployment returned the following errors:', @(@($ErrorMessages) | ForEach-Object { $_.Exception.Message.TrimEnd("`r`n") })
119+
}
120+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<OutputPath>bin\$(Configuration)\</OutputPath>
7+
<DebugSymbols>false</DebugSymbols>
8+
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
9+
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
10+
<TargetRuntime>None</TargetRuntime>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj\</BaseIntermediateOutputPath>
12+
<BaseIntermediateOutputPath Condition=" !HasTrailingSlash('$(BaseIntermediateOutputPath)') ">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath>
13+
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath>
14+
<ProjectReferencesOutputPath Condition=" '$(ProjectReferencesOutputPath)' == '' ">$(IntermediateOutputPath)ProjectReferences</ProjectReferencesOutputPath>
15+
<ProjectReferencesOutputPath Condition=" !HasTrailingSlash('$(ProjectReferencesOutputPath)') ">$(ProjectReferencesOutputPath)\</ProjectReferencesOutputPath>
16+
<StageArtifacts Condition=" '$(StageArtifacts)' == '' ">true</StageArtifacts>
17+
</PropertyGroup>
18+
19+
<PropertyGroup>
20+
<DefineCommonItemSchemas>false</DefineCommonItemSchemas>
21+
<DefineCommonCapabilities>false</DefineCommonCapabilities>
22+
</PropertyGroup>
23+
24+
<ProjectExtensions>
25+
<ProjectCapabilities>
26+
<DeploymentProject />
27+
</ProjectCapabilities>
28+
</ProjectExtensions>
29+
30+
<ItemDefinitionGroup>
31+
<Content>
32+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
33+
</Content>
34+
<None>
35+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
36+
</None>
37+
<ProjectReference>
38+
<Private>false</Private>
39+
<Targets>Build</Targets>
40+
</ProjectReference>
41+
</ItemDefinitionGroup>
42+
43+
<Target Name="CreateManifestResourceNames" />
44+
45+
<PropertyGroup>
46+
<StageArtifactsDependsOn>
47+
_GetDeploymentProjectContent;
48+
_CalculateContentOutputRelativePaths;
49+
_GetReferencedProjectsOutput;
50+
_CalculateArtifactStagingDirectory;
51+
_CopyOutputToArtifactStagingDirectory;
52+
</StageArtifactsDependsOn>
53+
</PropertyGroup>
54+
55+
<Target Name="_CopyOutputToArtifactStagingDirectory">
56+
<Copy SourceFiles="@(DeploymentProjectContentOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)%(RelativePath)" />
57+
<Copy SourceFiles="@(BuildProjectReferencesOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)\%(ProjectName)\%(RecursiveDir)%(FileName)%(Extension)" />
58+
</Target>
59+
60+
<Target Name="_GetDeploymentProjectContent">
61+
<MSBuild Projects="$(MSBuildProjectFile)" Targets="ContentFilesProjectOutputGroup">
62+
<Output TaskParameter="TargetOutputs" ItemName="DeploymentProjectContentOutput" />
63+
</MSBuild>
64+
</Target>
65+
66+
<Target Name="_GetReferencedProjectsOutput">
67+
<PropertyGroup>
68+
<MsBuildProperties>Configuration=$(Configuration);Platform=$(Platform)</MsBuildProperties>
69+
</PropertyGroup>
70+
71+
<MSBuild Projects="@(ProjectReference)"
72+
BuildInParallel="$(BuildInParallel)"
73+
Properties="$(MsBuildProperties)"
74+
Targets="%(ProjectReference.Targets)" />
75+
76+
<ItemGroup>
77+
<BuildProjectReferencesOutput Include="%(ProjectReference.IncludeFilePath)">
78+
<ProjectName>$([System.IO.Path]::GetFileNameWithoutExtension('%(ProjectReference.Identity)'))</ProjectName>
79+
</BuildProjectReferencesOutput>
80+
</ItemGroup>
81+
</Target>
82+
83+
<Target Name="_CalculateArtifactStagingDirectory" Condition=" '$(ArtifactStagingDirectory)'=='' ">
84+
<PropertyGroup>
85+
<ArtifactStagingDirectory Condition=" '$(OutDir)'!='' ">$(OutDir)</ArtifactStagingDirectory>
86+
<ArtifactStagingDirectory Condition=" '$(ArtifactStagingDirectory)'=='' ">$(OutputPath)</ArtifactStagingDirectory>
87+
<ArtifactStagingDirectory Condition=" !HasTrailingSlash('$(ArtifactStagingDirectory)') ">$(ArtifactStagingDirectory)\</ArtifactStagingDirectory>
88+
<ArtifactStagingDirectory>$(ArtifactStagingDirectory)staging\</ArtifactStagingDirectory>
89+
<ArtifactStagingDirectory Condition=" '$(Build_StagingDirectory)'!='' AND '$(TF_Build)'=='True' ">$(Build_StagingDirectory)</ArtifactStagingDirectory>
90+
</PropertyGroup>
91+
</Target>
92+
93+
<!-- Appends each of the deployment project's content output files with metadata indicating its relative path from the deployment project's folder. -->
94+
<Target Name="_CalculateContentOutputRelativePaths"
95+
Outputs="%(DeploymentProjectContentOutput.Identity)">
96+
<PropertyGroup>
97+
<_OriginalIdentity>%(DeploymentProjectContentOutput.Identity)</_OriginalIdentity>
98+
<_RelativePath>$(_OriginalIdentity.Replace('$(MSBuildProjectDirectory)', ''))</_RelativePath>
99+
</PropertyGroup>
100+
101+
<ItemGroup>
102+
<DeploymentProjectContentOutput>
103+
<RelativePath>$(_RelativePath)</RelativePath>
104+
</DeploymentProjectContentOutput>
105+
</ItemGroup>
106+
</Target>
107+
108+
<Target Name="CoreCompile" />
109+
110+
<PropertyGroup>
111+
<StageArtifactsAfterTargets Condition=" '$(StageArtifacts)' == 'true' ">
112+
PrepareForRun
113+
</StageArtifactsAfterTargets>
114+
</PropertyGroup>
115+
116+
<Target Name="StageArtifacts" DependsOnTargets="$(StageArtifactsDependsOn)" AfterTargets="$(StageArtifactsAfterTargets)"/>
117+
118+
<!-- Custom target to clean up local deployment staging files -->
119+
<Target Name="DeleteBinObjFolders" BeforeTargets="Clean">
120+
<RemoveDir Directories="$(OutputPath)" />
121+
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
122+
</Target>
123+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|AnyCPU">
5+
<Configuration>Debug</Configuration>
6+
<Platform>AnyCPU</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|AnyCPU">
9+
<Configuration>Release</Configuration>
10+
<Platform>AnyCPU</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>642b3f2e-3011-4b1a-8d22-d35c11c44f05</ProjectGuid>
15+
</PropertyGroup>
16+
<PropertyGroup>
17+
<TargetFrameworkIdentifier>Deployment</TargetFrameworkIdentifier>
18+
<TargetFrameworkVersion>1.0</TargetFrameworkVersion>
19+
<PrepareForBuildDependsOn>
20+
</PrepareForBuildDependsOn>
21+
</PropertyGroup>
22+
<Import Condition=" Exists('Deployment.targets') " Project="Deployment.targets" />
23+
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
24+
<!-- vertag<:>start tokens<:>maj.min -->
25+
<Import Condition=" Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets') " Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets" />
26+
<!-- vertag<:>end -->
27+
<ItemGroup>
28+
<None Include="Deployment.targets">
29+
<Visible>False</Visible>
30+
</None>
31+
<Content Include="Deploy-AzureResourceGroup.ps1" />
32+
<Content Include="sqldeploy.json">
33+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
34+
</Content>
35+
<Content Include="sqldeploy.parameters.json" />
36+
</ItemGroup>
37+
<Target Name="GetReferenceAssemblyPaths" />
38+
</Project>

0 commit comments

Comments
 (0)