Updated the deployment script with an unique name for Service Bus in Azure.

This commit is contained in:
Franck Cornu 2016-10-24 17:14:30 -04:00
parent cbb191fb25
commit 6e819e07cb
2 changed files with 99 additions and 90 deletions

View File

@ -40,13 +40,13 @@ Login-AzureRmAccount
$GitPublishingUserName = "tempdeployuser" + [Guid]::NewGuid();
$GitPublishingUserPassword = "socketio123!"
$AzureSBNamespace = "SPFxSocketIOServiceBus";
$AzureWebAppName = "SPFxSocketIOWebApp"+[Guid]::NewGuid()
$AppServicePlanName = "SPFxSocketIOServicePlan"
$AzureSBNamespace = "ServiceBus" + [Guid]::NewGuid();
$AzureWebAppName = "WebApp" + [Guid]::NewGuid()
$AppServicePlanName = "ServicePlan"
$TemplateFilePath = ".\azure-deploy.json"
$AzureResourceGroupLocation = "East US2"
$AzureResourceGroupName = "SPFxSocketIODemo"
$AzureRmResourceGroupDeploymentName = "SPFxSocketIODemo"
$AzureRmResourceGroupDeploymentName = $AzureResourceGroupName
$ServerCodeFolderLocation = ".\server"
# Set the publishing user and password for the local Git deployment
@ -55,69 +55,71 @@ $PropertiesObject = @{
"publishingPassword" = $GitPublishingUserPassword;
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceId /providers/Microsoft.Web/publishingUsers/web -ApiVersion 2015-08-01 -Force
Try {
Write-Host -ForegroundColor Magenta "Creating the Azure resource Group [$AzureResourceGroupName]..."
New-AzureRmResourceGroup -Name $AzureResourceGroupName -Location $AzureResourceGroupLocation
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceId /providers/Microsoft.Web/publishingUsers/web -ApiVersion 2015-08-01 -Force
# Deploy the Azure Resource Group using an ARM template
# More information here: https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/#resources
Write-Host -ForegroundColor Magenta "Creating the Azure resource Group [$AzureResourceGroupName]..."
New-AzureRmResourceGroup -Name $AzureResourceGroupName -Location $AzureResourceGroupLocation
$TemplateParameters = @{
# Deploy the Azure Resource Group using an ARM template
# More information here: https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/#resources
$TemplateParameters = @{
"ServiceBusNameSpace"=$AzureSBNamespace;
"AppServicePlanName"= $AppServicePlanName;
"SiteName"=$AzureWebAppName;
"Location"=$AzureResourceGroupLocation
}
}
Write-Host -ForegroundColor Magenta "Deploying Azure resources using ARM template..."
Test-AzureRmResourceGroupDeployment -ResourceGroupName $AzureResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterObject $TemplateParameters
New-AzureRmResourceGroupDeployment -Name $AzureRmResourceGroupDeploymentName -ResourceGroupName $AzureResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterObject $TemplateParameters
Write-Host -ForegroundColor Green "Done!"
Write-Host -ForegroundColor Magenta "Deploying Azure resources using ARM template..."
Test-AzureRmResourceGroupDeployment -ResourceGroupName $AzureResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterObject $TemplateParameters
New-AzureRmResourceGroupDeployment -Name $AzureRmResourceGroupDeploymentName -ResourceGroupName $AzureResourceGroupName -TemplateFile $TemplateFilePath -TemplateParameterObject $TemplateParameters
Write-Host -ForegroundColor Green "Done!"
Write-Host -ForegroundColor Magenta "Updating Web Application settings..."
$CurrentNamespace = Get-AzureSBNamespace -Name $AzureSBNamespace
Write-Host -ForegroundColor Magenta "Updating Web Application settings..."
$CurrentNamespace = Get-AzureSBNamespace -Name $AzureSBNamespace
# Check if the namespace already exists or needs to be created
if ($CurrentNamespace) {
# Check if the namespace already exists or needs to be created
if ($CurrentNamespace) {
# Set the Web Applicatio settings
$AppSettings = New-Object Hashtable
$AppSettings["AZURE_SERVICEBUS_ACCESS_KEY"]=$CurrentNamespace.ConnectionString
# Set application settings and enable WebSockets
Set-AzureWebsite -Name $AzureWebAppName -AppSettings $AppSettings
}
Write-Host -ForegroundColor Green "Done!"
}
Write-Host -ForegroundColor Green "Done!"
# Deploy the code to the Web Application using Local Git
# Deploy the code to the Web Application using Local Git
# Note: the part below is only valid for this demo. In a real world situation, you may want link to your TFS/GitHub/BitBucket repository instead.
# See https://azure.microsoft.com/en-us/documentation/articles/app-service-deploy-local-git/ for more information
Write-Host -ForegroundColor Magenta "Deploying the Web Application Node JS code using Local Git..."
# Note: the part below is only valid for this demo. In a real world situation, you may want link to your TFS/GitHub/BitBucket repository instead.
# See https://azure.microsoft.com/en-us/documentation/articles/app-service-deploy-local-git/ for more information
Write-Host -ForegroundColor Magenta "Deploying the Web Application Node JS code using Local Git..."
# Go to the location where the code for the server is located and commit/push it to the local git repository of the web application.
Push-Location $ServerCodeFolderLocation
# Go to the location where the code for the server is located and commit/push it to the local git repository of the web application.
Push-Location $ServerCodeFolderLocation
# Remove previous git config if exists
if (Test-Path .git) {
# Remove previous git config if exists
if (Test-Path .git) {
Remove-Item -Recurse .git -Force
}
}
git init
git init
git add -A
git add -A
git commit -m "SPFx Socket IO Demo - Server code"
git commit -m "SPFx Socket IO Demo - Server code"
# Build the git clone URL with embbed password
$GitCloneURL = "https://$GitPublishingUserName" + ":$GitPublishingUserPassword@$AzureWebAppName.scm.azurewebsites.net:443/$AzureWebAppName.git"
# Build the git clone URL with embbed password
$GitCloneURL = "https://$GitPublishingUserName" + ":$GitPublishingUserPassword@$AzureWebAppName.scm.azurewebsites.net:443/$AzureWebAppName.git"
# Make sure there is no 502 error and the git URL is up and running (can take few seconds)
$Timeout = New-TimeSpan -Minutes 1
$sw = [Diagnostics.Stopwatch]::StartNew()
# Make sure there is no 502 error and the git URL is up and running (can take few seconds)
$Timeout = New-TimeSpan -Minutes 1
$sw = [Diagnostics.Stopwatch]::StartNew()
Write-Host -ForegroundColor Yellow "Wait for the git clone URL is up and running" -NoNewline
while ($sw.elapsed -lt $Timeout) {
Write-Host -ForegroundColor Yellow "Wait for the git clone URL is up and running" -NoNewline
while ($sw.elapsed -lt $Timeout) {
if ((Invoke-WebRequest -Uri $GitCloneURL).StatusCode -eq 200) {
@ -143,5 +145,12 @@ while ($sw.elapsed -lt $Timeout) {
Start-Sleep -Seconds 5
Write-Host -ForegroundColor Yellow "."
}
Write-Warning "The git clone URL timed out!"
} Catch {
$ErrorMessage = $_.Exception.Message
Write-Error $ErrorMessage
Exit
}
Write-Warning "The git clone URL timed out!"

View File

@ -80,7 +80,7 @@ Version|Date|Comments
It is recommended to deploy this solution on a test Azure subscription because by default, the script will override the local git deployment credentials configured for your subscription (for the web application provisioning).
If you want to set you own parameters, update the `Deploy-Solution.ps1` script and replace tokens with your desired configuration.
Notice that some values have to be unique within the whole Azure platform (for instance, the web application name and the deployment user name), that's why we use a random guid each time.
Notice that some values have to be unique within the whole Azure platform (for instance the web application name, the deployment user name, etc.), that's why we use a random guid each time.
```ps