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,93 +55,102 @@ $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 = @{
"ServiceBusNameSpace"=$AzureSBNamespace;
"AppServicePlanName"= $AppServicePlanName;
"SiteName"=$AzureWebAppName;
"Location"=$AzureResourceGroupLocation
}
# 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 "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
# 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!"
# 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..."
# 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-Item -Recurse .git -Force
}
git init
git add -A
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"
# 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) {
if ((Invoke-WebRequest -Uri $GitCloneURL).StatusCode -eq 200) {
Write-Host "`n"
git remote add azure $GitCloneURL 2>&1 | %{ "$_" }
# We force the push to overwrite remote with local files avoiding update conflicts (don't use this in production)
git push azure master --force 2>&1 | %{ "$_" }
# Update URLs in the client side code according to the web app name
Pop-Location
$files = @(".\client\config\config.json",".\client\src\webparts\realTimeNewsFeed\components\RealTimeNewsFeed.tsx")
$files | ForEach-Object { (Get-Content $_) -replace 'https:\/\/(\S*)\.azurewebsites\.net', "https://$AzureWebAppName.azurewebsites.net" | Set-Content $_ }
Write-Host -ForegroundColor Green "Done!"
return
$TemplateParameters = @{
"ServiceBusNameSpace"=$AzureSBNamespace;
"AppServicePlanName"= $AppServicePlanName;
"SiteName"=$AzureWebAppName;
"Location"=$AzureResourceGroupLocation
}
Start-Sleep -Seconds 5
Write-Host -ForegroundColor Yellow "."
}
Write-Warning "The git clone URL timed out!"
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
# 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!"
# 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..."
# 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-Item -Recurse .git -Force
}
git init
git add -A
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"
# 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) {
if ((Invoke-WebRequest -Uri $GitCloneURL).StatusCode -eq 200) {
Write-Host "`n"
git remote add azure $GitCloneURL 2>&1 | %{ "$_" }
# We force the push to overwrite remote with local files avoiding update conflicts (don't use this in production)
git push azure master --force 2>&1 | %{ "$_" }
# Update URLs in the client side code according to the web app name
Pop-Location
$files = @(".\client\config\config.json",".\client\src\webparts\realTimeNewsFeed\components\RealTimeNewsFeed.tsx")
$files | ForEach-Object { (Get-Content $_) -replace 'https:\/\/(\S*)\.azurewebsites\.net', "https://$AzureWebAppName.azurewebsites.net" | Set-Content $_ }
Write-Host -ForegroundColor Green "Done!"
return
}
Start-Sleep -Seconds 5
Write-Host -ForegroundColor Yellow "."
}
Write-Warning "The git clone URL timed out!"
} Catch {
$ErrorMessage = $_.Exception.Message
Write-Error $ErrorMessage
Exit
}

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