-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Azure.LinuxWebApp.Docker/Azure.LinuxWebApp.Docker.deployproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|AnyCPU"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>AnyCPU</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|AnyCPU"> | ||
<Configuration>Release</Configuration> | ||
<Platform>AnyCPU</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>bab5e760-ebed-41a4-808c-3b151a84f82e</ProjectGuid> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworkIdentifier>Deployment</TargetFrameworkIdentifier> | ||
<TargetFrameworkVersion>1.0</TargetFrameworkVersion> | ||
<PrepareForBuildDependsOn> | ||
</PrepareForBuildDependsOn> | ||
</PropertyGroup> | ||
<Import Condition=" Exists('Deployment.targets') " Project="Deployment.targets" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" /> | ||
<!-- vertag<:>start tokens<:>maj.min --> | ||
<Import Condition=" Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets') " Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Deployment\1.1\DeploymentProject.targets" /> | ||
<!-- vertag<:>end --> | ||
<ItemGroup> | ||
<Content Include="azuredeploy.json" /> | ||
<Content Include="azuredeploy.parameters.json" /> | ||
<None Include="Deployment.targets"> | ||
<Visible>False</Visible> | ||
</None> | ||
<Content Include="Deploy-AzureResourceGroup.ps1" /> | ||
</ItemGroup> | ||
<Target Name="GetReferenceAssemblyPaths" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#Requires -Version 3.0 | ||
#Requires -Module AzureRM.Resources | ||
#Requires -Module Azure.Storage | ||
|
||
Param( | ||
[string] [Parameter(Mandatory=$true)] $ResourceGroupLocation, | ||
[string] $ResourceGroupName = 'Azure.WebAppLinux.Docker', | ||
[switch] $UploadArtifacts, | ||
[string] $StorageAccountName, | ||
[string] $StorageContainerName = $ResourceGroupName.ToLowerInvariant() + '-stageartifacts', | ||
[string] $TemplateFile = 'azuredeploy.json', | ||
[string] $TemplateParametersFile = 'azuredeploy.parameters.json', | ||
[string] $ArtifactStagingDirectory = '.', | ||
[string] $DSCSourceFolder = 'DSC', | ||
[switch] $ValidateOnly | ||
) | ||
|
||
Import-Module Azure -ErrorAction SilentlyContinue | ||
|
||
try { | ||
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("VSAzureTools-$UI$($host.name)".replace(" ","_"), "2.9.5") | ||
} catch { } | ||
|
||
Set-StrictMode -Version 3 | ||
|
||
function Format-ValidationOutput { | ||
param ($ValidationOutput, [int] $Depth = 0) | ||
Set-StrictMode -Off | ||
return @($ValidationOutput | Where-Object { $_ -ne $null } | ForEach-Object { @(" " * $Depth + $_.Code + ": " + $_.Message) + @(Format-ValidationOutput @($_.Details) ($Depth + 1)) }) | ||
} | ||
|
||
$OptionalParameters = New-Object -TypeName Hashtable | ||
$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile)) | ||
$TemplateParametersFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateParametersFile)) | ||
|
||
if ($UploadArtifacts) { | ||
# Convert relative paths to absolute paths if needed | ||
$ArtifactStagingDirectory = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $ArtifactStagingDirectory)) | ||
$DSCSourceFolder = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $DSCSourceFolder)) | ||
|
||
Set-Variable ArtifactsLocationName '_artifactsLocation' -Option ReadOnly -Force | ||
Set-Variable ArtifactsLocationSasTokenName '_artifactsLocationSasToken' -Option ReadOnly -Force | ||
|
||
$OptionalParameters.Add($ArtifactsLocationName, $null) | ||
$OptionalParameters.Add($ArtifactsLocationSasTokenName, $null) | ||
|
||
# Parse the parameter file and update the values of artifacts location and artifacts location SAS token if they are present | ||
$JsonContent = Get-Content $TemplateParametersFile -Raw | ConvertFrom-Json | ||
$JsonParameters = $JsonContent | Get-Member -Type NoteProperty | Where-Object {$_.Name -eq "parameters"} | ||
|
||
if ($JsonParameters -eq $null) { | ||
$JsonParameters = $JsonContent | ||
} | ||
else { | ||
$JsonParameters = $JsonContent.parameters | ||
} | ||
|
||
$JsonParameters | Get-Member -Type NoteProperty | ForEach-Object { | ||
$ParameterValue = $JsonParameters | Select-Object -ExpandProperty $_.Name | ||
|
||
if ($_.Name -eq $ArtifactsLocationName -or $_.Name -eq $ArtifactsLocationSasTokenName) { | ||
$OptionalParameters[$_.Name] = $ParameterValue.value | ||
} | ||
} | ||
|
||
# Create DSC configuration archive | ||
if (Test-Path $DSCSourceFolder) { | ||
$DSCSourceFilePaths = @(Get-ChildItem $DSCSourceFolder -File -Filter "*.ps1" | ForEach-Object -Process {$_.FullName}) | ||
foreach ($DSCSourceFilePath in $DSCSourceFilePaths) { | ||
$DSCArchiveFilePath = $DSCSourceFilePath.Substring(0, $DSCSourceFilePath.Length - 4) + ".zip" | ||
Publish-AzureRmVMDscConfiguration $DSCSourceFilePath -OutputArchivePath $DSCArchiveFilePath -Force -Verbose | ||
} | ||
} | ||
|
||
# Create a storage account name if none was provided | ||
if($StorageAccountName -eq "") { | ||
$subscriptionId = ((Get-AzureRmContext).Subscription.SubscriptionId).Replace('-', '').substring(0, 19) | ||
$StorageAccountName = "stage$subscriptionId" | ||
} | ||
|
||
$StorageAccount = (Get-AzureRmStorageAccount | Where-Object{$_.StorageAccountName -eq $StorageAccountName}) | ||
|
||
# Create the storage account if it doesn't already exist | ||
if($StorageAccount -eq $null){ | ||
$StorageResourceGroupName = "ARM_Deploy_Staging" | ||
New-AzureRmResourceGroup -Location "$ResourceGroupLocation" -Name $StorageResourceGroupName -Force | ||
$StorageAccount = New-AzureRmStorageAccount -StorageAccountName $StorageAccountName -Type 'Standard_LRS' -ResourceGroupName $StorageResourceGroupName -Location "$ResourceGroupLocation" | ||
} | ||
|
||
$StorageAccountContext = (Get-AzureRmStorageAccount | Where-Object{$_.StorageAccountName -eq $StorageAccountName}).Context | ||
|
||
# Generate the value for artifacts location if it is not provided in the parameter file | ||
$ArtifactsLocation = $OptionalParameters[$ArtifactsLocationName] | ||
if ($ArtifactsLocation -eq $null) { | ||
$ArtifactsLocation = $StorageAccountContext.BlobEndPoint + $StorageContainerName | ||
$OptionalParameters[$ArtifactsLocationName] = $ArtifactsLocation | ||
} | ||
|
||
# Copy files from the local storage staging location to the storage account container | ||
New-AzureStorageContainer -Name $StorageContainerName -Context $StorageAccountContext -Permission Container -ErrorAction SilentlyContinue *>&1 | ||
|
||
$ArtifactFilePaths = Get-ChildItem $ArtifactStagingDirectory -Recurse -File | ForEach-Object -Process {$_.FullName} | ||
foreach ($SourcePath in $ArtifactFilePaths) { | ||
$BlobName = $SourcePath.Substring($ArtifactStagingDirectory.length + 1) | ||
Set-AzureStorageBlobContent -File $SourcePath -Blob $BlobName -Container $StorageContainerName -Context $StorageAccountContext -Force -ErrorAction Stop | ||
} | ||
|
||
# Generate the value for artifacts location SAS token if it is not provided in the parameter file | ||
$ArtifactsLocationSasToken = $OptionalParameters[$ArtifactsLocationSasTokenName] | ||
if ($ArtifactsLocationSasToken -eq $null) { | ||
# Create a SAS token for the storage container - this gives temporary read-only access to the container | ||
$ArtifactsLocationSasToken = New-AzureStorageContainerSASToken -Container $StorageContainerName -Context $StorageAccountContext -Permission r -ExpiryTime (Get-Date).AddHours(4) | ||
$ArtifactsLocationSasToken = ConvertTo-SecureString $ArtifactsLocationSasToken -AsPlainText -Force | ||
$OptionalParameters[$ArtifactsLocationSasTokenName] = $ArtifactsLocationSasToken | ||
} | ||
} | ||
|
||
# Create or update the resource group using the specified template file and template parameters file | ||
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop | ||
|
||
$ErrorMessages = @() | ||
if ($ValidateOnly) { | ||
$ErrorMessages = Format-ValidationOutput (Test-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName ` | ||
-TemplateFile $TemplateFile ` | ||
-TemplateParameterFile $TemplateParametersFile ` | ||
@OptionalParameters ` | ||
-Verbose) | ||
} | ||
else { | ||
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) ` | ||
-ResourceGroupName $ResourceGroupName ` | ||
-TemplateFile $TemplateFile ` | ||
-TemplateParameterFile $TemplateParametersFile ` | ||
@OptionalParameters ` | ||
-Force -Verbose ` | ||
-ErrorVariable ErrorMessages | ||
$ErrorMessages = $ErrorMessages | ForEach-Object { $_.Exception.Message.TrimEnd("`r`n") } | ||
} | ||
if ($ErrorMessages) | ||
{ | ||
"", ("{0} returned the following errors:" -f ("Template deployment", "Validation")[[bool]$ValidateOnly]), @($ErrorMessages) | ForEach-Object { Write-Output $_ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputPath>bin\$(Configuration)\</OutputPath> | ||
<DebugSymbols>false</DebugSymbols> | ||
<SkipCopyBuildProduct>true</SkipCopyBuildProduct> | ||
<AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences> | ||
<TargetRuntime>None</TargetRuntime> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj\</BaseIntermediateOutputPath> | ||
<BaseIntermediateOutputPath Condition=" !HasTrailingSlash('$(BaseIntermediateOutputPath)') ">$(BaseIntermediateOutputPath)\</BaseIntermediateOutputPath> | ||
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\</IntermediateOutputPath> | ||
<ProjectReferencesOutputPath Condition=" '$(ProjectReferencesOutputPath)' == '' ">$(IntermediateOutputPath)ProjectReferences</ProjectReferencesOutputPath> | ||
<ProjectReferencesOutputPath Condition=" !HasTrailingSlash('$(ProjectReferencesOutputPath)') ">$(ProjectReferencesOutputPath)\</ProjectReferencesOutputPath> | ||
<StageArtifacts Condition=" '$(StageArtifacts)' == '' ">true</StageArtifacts> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<DefineCommonItemSchemas>false</DefineCommonItemSchemas> | ||
<DefineCommonCapabilities>false</DefineCommonCapabilities> | ||
</PropertyGroup> | ||
|
||
<ProjectExtensions> | ||
<ProjectCapabilities> | ||
<DeploymentProject /> | ||
</ProjectCapabilities> | ||
</ProjectExtensions> | ||
|
||
<ItemDefinitionGroup> | ||
<Content> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<None> | ||
<CopyToOutputDirectory>Never</CopyToOutputDirectory> | ||
</None> | ||
<ProjectReference> | ||
<Private>false</Private> | ||
<Targets>Build</Targets> | ||
</ProjectReference> | ||
</ItemDefinitionGroup> | ||
|
||
<Target Name="CreateManifestResourceNames" /> | ||
|
||
<PropertyGroup> | ||
<StageArtifactsDependsOn> | ||
_GetDeploymentProjectContent; | ||
_CalculateContentOutputRelativePaths; | ||
_GetReferencedProjectsOutput; | ||
_CalculateArtifactStagingDirectory; | ||
_CopyOutputToArtifactStagingDirectory; | ||
</StageArtifactsDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="_CopyOutputToArtifactStagingDirectory"> | ||
<Copy SourceFiles="@(DeploymentProjectContentOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)%(RelativePath)" /> | ||
<Copy SourceFiles="@(BuildProjectReferencesOutput)" DestinationFiles="$(ArtifactStagingDirectory)\$(MSBuildProjectName)\%(ProjectName)\%(RecursiveDir)%(FileName)%(Extension)" /> | ||
</Target> | ||
|
||
<Target Name="_GetDeploymentProjectContent"> | ||
<MSBuild Projects="$(MSBuildProjectFile)" Targets="ContentFilesProjectOutputGroup"> | ||
<Output TaskParameter="TargetOutputs" ItemName="DeploymentProjectContentOutput" /> | ||
</MSBuild> | ||
</Target> | ||
|
||
<Target Name="_GetReferencedProjectsOutput"> | ||
<PropertyGroup> | ||
<MsBuildProperties>Configuration=$(Configuration);Platform=$(Platform)</MsBuildProperties> | ||
</PropertyGroup> | ||
|
||
<MSBuild Projects="@(ProjectReference)" | ||
BuildInParallel="$(BuildInParallel)" | ||
Properties="$(MsBuildProperties)" | ||
Targets="%(ProjectReference.Targets)" /> | ||
|
||
<ItemGroup> | ||
<BuildProjectReferencesOutput Include="%(ProjectReference.IncludeFilePath)"> | ||
<ProjectName>$([System.IO.Path]::GetFileNameWithoutExtension('%(ProjectReference.Identity)'))</ProjectName> | ||
</BuildProjectReferencesOutput> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="_CalculateArtifactStagingDirectory" Condition=" '$(ArtifactStagingDirectory)'=='' "> | ||
<PropertyGroup> | ||
<ArtifactStagingDirectory Condition=" '$(OutDir)'!='' ">$(OutDir)</ArtifactStagingDirectory> | ||
<ArtifactStagingDirectory Condition=" '$(ArtifactStagingDirectory)'=='' ">$(OutputPath)</ArtifactStagingDirectory> | ||
<ArtifactStagingDirectory Condition=" !HasTrailingSlash('$(ArtifactStagingDirectory)') ">$(ArtifactStagingDirectory)\</ArtifactStagingDirectory> | ||
<ArtifactStagingDirectory>$(ArtifactStagingDirectory)staging\</ArtifactStagingDirectory> | ||
<ArtifactStagingDirectory Condition=" '$(Build_StagingDirectory)'!='' AND '$(TF_Build)'=='True' ">$(Build_StagingDirectory)</ArtifactStagingDirectory> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<!-- Appends each of the deployment project's content output files with metadata indicating its relative path from the deployment project's folder. --> | ||
<Target Name="_CalculateContentOutputRelativePaths" | ||
Outputs="%(DeploymentProjectContentOutput.Identity)"> | ||
<PropertyGroup> | ||
<_OriginalIdentity>%(DeploymentProjectContentOutput.Identity)</_OriginalIdentity> | ||
<_RelativePath>$(_OriginalIdentity.Replace('$(MSBuildProjectDirectory)', ''))</_RelativePath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<DeploymentProjectContentOutput> | ||
<RelativePath>$(_RelativePath)</RelativePath> | ||
</DeploymentProjectContentOutput> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="CoreCompile" /> | ||
|
||
<PropertyGroup> | ||
<StageArtifactsAfterTargets Condition=" '$(StageArtifacts)' == 'true' "> | ||
PrepareForRun | ||
</StageArtifactsAfterTargets> | ||
</PropertyGroup> | ||
|
||
<Target Name="StageArtifacts" DependsOnTargets="$(StageArtifactsDependsOn)" AfterTargets="$(StageArtifactsAfterTargets)"/> | ||
|
||
<!-- Custom target to clean up local deployment staging files --> | ||
<Target Name="DeleteBinObjFolders" BeforeTargets="Clean"> | ||
<RemoveDir Directories="$(OutputPath)" /> | ||
<RemoveDir Directories="$(BaseIntermediateOutputPath)" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
}, | ||
"variables": { | ||
}, | ||
"resources": [ | ||
], | ||
"outputs": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{151D2E53-A2C4-4D7D-83FE-D05416EBD58E}") = "Azure.LinuxWebApp.Docker", "Azure.LinuxWebApp.Docker\Azure.LinuxWebApp.Docker.deployproj", "{BAB5E760-EBED-41A4-808C-3B151A84F82E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{BAB5E760-EBED-41A4-808C-3B151A84F82E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BAB5E760-EBED-41A4-808C-3B151A84F82E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BAB5E760-EBED-41A4-808C-3B151A84F82E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BAB5E760-EBED-41A4-808C-3B151A84F82E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |