2016-01-16 03:05:52 +03:00
|
|
|
param (
|
2016-01-25 12:36:14 +03:00
|
|
|
[switch] [boolean] $azure
|
2016-01-16 03:05:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
Set-StrictMode -Version 2.0
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$ProgressPreference = "SilentlyContinue" # https://www.amido.com/powershell-win32-error-handle-invalid-0x6/
|
|
|
|
|
|
|
|
# Write-Host, Write-Error and Write-Warning do not function properly in Azure
|
|
|
|
# So this mostly uses Write-Output for now
|
|
|
|
$PublishToIIS = Resolve-Path "$PSScriptRoot\Publish-ToIIS.ps1"
|
|
|
|
$PublishToAzure = Resolve-Path "$PSScriptRoot\Publish-ToAzure.ps1"
|
|
|
|
|
2016-01-25 12:36:14 +03:00
|
|
|
function Login-ToAzure($azureConfig) {
|
|
|
|
$passwordKey = $env:TR_AZURE_PASSWORD_KEY
|
|
|
|
if (!$passwordKey) {
|
|
|
|
throw "Azure credentials require TR_AZURE_PASSWORD_KEY to be set."
|
|
|
|
}
|
|
|
|
$passwordKey = [Convert]::FromBase64String($passwordKey)
|
2016-04-28 15:35:22 +03:00
|
|
|
$password = $azureConfig.Password | ConvertTo-SecureString -Key $passwordKey
|
2016-01-25 12:36:14 +03:00
|
|
|
$credential = New-Object Management.Automation.PSCredential($azureConfig.UserName, $password)
|
2016-04-28 15:35:22 +03:00
|
|
|
|
2016-01-25 12:36:14 +03:00
|
|
|
"Logging to Azure as $($azureConfig.UserName)..." | Out-Default
|
|
|
|
Login-AzureRmAccount -Credential $credential | Out-Null
|
|
|
|
}
|
|
|
|
|
2016-01-16 03:05:52 +03:00
|
|
|
# Code ------
|
|
|
|
try {
|
|
|
|
$Host.UI.RawUI.WindowTitle = "Deploy TryRoslyn" # prevents title > 1024 char errors
|
|
|
|
|
|
|
|
Write-Output "Environment:"
|
|
|
|
Write-Output " Current Path: $(Get-Location)"
|
|
|
|
Write-Output " Script Root: $PSScriptRoot"
|
|
|
|
|
|
|
|
$sourceRoot = Resolve-Path "$PSScriptRoot\..\Source"
|
|
|
|
Write-Output " Source Root: $sourceRoot"
|
|
|
|
|
|
|
|
$sitesBuildRoot = Resolve-Path "$PSScriptRoot\..\!sites"
|
|
|
|
Write-Output " Sites Build Root: $sitesBuildRoot"
|
|
|
|
|
|
|
|
if ($azure) {
|
2016-04-24 07:28:30 +03:00
|
|
|
$azureConfigPath = ".\!Azure.config.json"
|
2016-01-25 12:36:14 +03:00
|
|
|
if (!(Test-Path $azureConfigPath)) {
|
|
|
|
throw "Path '$azureConfigPath' was not found."
|
|
|
|
}
|
|
|
|
$azureConfig = ConvertFrom-Json (Get-Content $azureConfigPath -Raw)
|
|
|
|
Login-ToAzure $azureConfig
|
2016-01-16 03:05:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$branchesJson = @()
|
|
|
|
Get-ChildItem $sitesBuildRoot | ? { $_ -is [IO.DirectoryInfo] } | % {
|
|
|
|
$branchFsName = $_.Name
|
|
|
|
|
|
|
|
$siteMainRoot = "$($_.FullName)\!site"
|
|
|
|
if (!(Test-Path $siteMainRoot) -or !(Get-ChildItem $siteMainRoot -Recurse | ? { $_ -is [IO.FileInfo] })) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Output ''
|
|
|
|
Write-Output "*** $_"
|
|
|
|
|
|
|
|
$siteMainRoot = Resolve-Path $siteMainRoot
|
|
|
|
$siteRoslynRoot = Resolve-Path "$($_.FullName)\!roslyn"
|
|
|
|
|
|
|
|
$branchInfo = ConvertFrom-Json ([IO.File]::ReadAllText("$siteRoslynRoot\!BranchInfo.json"))
|
|
|
|
|
2016-04-28 15:35:22 +03:00
|
|
|
$webAppName = "tr-b-$($branchFsName.ToLowerInvariant())"
|
2016-08-02 02:01:42 +03:00
|
|
|
if ($webAppName.Length -gt 63) {
|
|
|
|
$webAppName = $webAppName.Substring(0, 60) + "-01"; # no uniqueness check at the moment, we can add later
|
|
|
|
Write-Output "[WARNING] Name is too long, using '$webAppName'."
|
|
|
|
}
|
|
|
|
|
2016-01-16 03:05:52 +03:00
|
|
|
$iisSiteName = "$webAppName.tryroslyn.local"
|
|
|
|
$url = "http://$iisSiteName"
|
|
|
|
&$PublishToIIS -SiteName $iisSiteName -SourcePath $siteMainRoot
|
|
|
|
|
|
|
|
if ($azure) {
|
|
|
|
&$PublishToAzure `
|
2016-01-25 12:36:14 +03:00
|
|
|
-ResourceGroupName $($azureConfig.ResourceGroupName) `
|
2016-04-20 12:42:34 +03:00
|
|
|
-AppServicePlanName $($azureConfig.AppServicePlanName) `
|
2016-01-16 03:05:52 +03:00
|
|
|
-WebAppName $webAppName `
|
|
|
|
-CanCreateWebApp `
|
2016-01-25 21:26:52 +03:00
|
|
|
-CanStopWebApp `
|
2016-01-16 03:05:52 +03:00
|
|
|
-SourcePath $siteMainRoot `
|
|
|
|
-TargetPath "."
|
|
|
|
$url = "http://$($webAppName).azurewebsites.net"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Success!
|
2016-04-19 12:23:47 +03:00
|
|
|
$branchesJson += [ordered]@{
|
2016-04-28 15:35:22 +03:00
|
|
|
id = $branchFsName -replace '^dotnet-',''
|
2016-01-16 03:05:52 +03:00
|
|
|
name = $branchInfo.name
|
2016-04-24 07:28:30 +03:00
|
|
|
group = $branchInfo.repository
|
2016-01-16 03:05:52 +03:00
|
|
|
url = $url
|
|
|
|
commits = $branchInfo.commits
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-19 12:23:47 +03:00
|
|
|
$branchesFileName = "!branches.json"
|
|
|
|
Write-Output "Updating $branchesFileName..."
|
|
|
|
Set-Content "$sitesBuildRoot\$branchesFileName" $(ConvertTo-Json $branchesJson -Depth 100)
|
2016-01-29 11:24:23 +03:00
|
|
|
|
|
|
|
$brachesJsLocalRoot = "$sourceRoot\Web\wwwroot"
|
|
|
|
if (!(Test-Path $brachesJsLocalRoot)) {
|
|
|
|
New-Item -ItemType Directory -Path $brachesJsLocalRoot | Out-Null
|
2016-04-24 07:28:30 +03:00
|
|
|
}
|
|
|
|
Copy-Item "$sitesBuildRoot\$branchesFileName" "$brachesJsLocalRoot\$branchesFileName" -Force
|
2016-01-29 11:24:23 +03:00
|
|
|
|
2016-01-16 03:05:52 +03:00
|
|
|
if ($azure) {
|
|
|
|
&$PublishToAzure `
|
2016-01-25 12:36:14 +03:00
|
|
|
-ResourceGroupName $($azureConfig.ResourceGroupName) `
|
2016-04-21 12:46:13 +03:00
|
|
|
-AppServicePlanName $($azureConfig.AppServicePlanName) `
|
2016-01-16 03:05:52 +03:00
|
|
|
-WebAppName "tryroslyn" `
|
2016-04-19 12:23:47 +03:00
|
|
|
-SourcePath "$sitesBuildRoot\$branchesFileName" `
|
|
|
|
-TargetPath "wwwroot\$branchesFileName"
|
2016-01-16 03:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-Output "[ERROR] $_"
|
|
|
|
Write-Output 'Returning exit code 1'
|
|
|
|
exit 1
|
|
|
|
}
|