forked from dddwa/ddd-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added deployment files using Azure ARM
- Loading branch information
Showing
5 changed files
with
310 additions
and
1 deletion.
There are no files selected for viewing
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
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,20 @@ | ||
$ErrorActionPreference = "Stop" | ||
|
||
$privateParamsFile = "$PSScriptRoot\local.private.json" | ||
if (-not (Test-Path $privateParamsFile)) { | ||
Copy-Item "$PsScriptRoot\local.private.template.json" $privateParamsFile | ||
Write-Warning "Please update information in $privateParamsFile" | ||
exit 1 | ||
} | ||
|
||
$fields = ConvertFrom-Json ([System.IO.File]::ReadAllText($privateParamsFile)) | ||
$fieldsAsHashTable = @{} | ||
$fields.psobject.properties | ForEach-Object { $fieldsAsHashTable[$_.Name] = $_.Value } | ||
|
||
$profile = Select-AzureRmProfile -Path "$PSScriptRoot\profile.json" -ErrorAction SilentlyContinue | ||
if (-not $profile.Context) { | ||
Login-AzureRmAccount -TenantId $TenantId | Out-Null | ||
Save-AzureRmProfile -Path "$PSScriptRoot\profile.json" | ||
} | ||
|
||
& $PSScriptRoot\Deploy.ps1 -AlreadyLoggedIn @fieldsAsHashTable |
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,72 @@ | ||
Param ( | ||
[string] | ||
[Parameter(ParameterSetName = "SpecifyServicePrincipal", Mandatory = $true)] | ||
$ServicePrincipalId, | ||
|
||
[string] | ||
[Parameter(ParameterSetName = "SpecifyServicePrincipal", Mandatory = $true)] | ||
$ServicePrincipalPassword, | ||
|
||
[switch] | ||
[Parameter(ParameterSetName = "AlreadyLoggedIn", Mandatory = $true)] | ||
$AlreadyLoggedIn, | ||
|
||
[string] [Parameter(Mandatory = $true)] $SubscriptionId, | ||
[string] [Parameter(Mandatory = $true)] $TenantId, | ||
[string] [Parameter(Mandatory = $true)] $Location, | ||
[string] [Parameter(Mandatory = $true)] $ConferenceName, | ||
[string] [Parameter(Mandatory = $true)] $AppEnvironment, | ||
[string] [Parameter(Mandatory = $true)] $AppServicePlanResourceGroup, | ||
[string] [Parameter(Mandatory = $true)] $AppServicePlanName, | ||
[string] [Parameter(Mandatory = $true)] $NewSessionNotificationLogicAppUrl, | ||
[string] [Parameter(Mandatory = $true)] $DeploymentZipUrl, | ||
[string] [Parameter(Mandatory = $true)] $SessionizeApiKey, | ||
[string] [Parameter(Mandatory = $true)] $EventbriteApiBearerToken, | ||
[string] $SessionizeReadModelSyncSchedule = "0 */5 * * * *", | ||
[string] $ResourceGroupName = "$ConferenceName-backend-$AppEnvironment" | ||
) | ||
|
||
function Get-Parameters() { | ||
return @{ | ||
"serverFarmResourceId" = "/subscriptions/$SubscriptionId/resourceGroups/$AppServicePlanResourceGroup/providers/Microsoft.Web/serverfarms/$AppServicePlanName"; | ||
"functionsAppName" = "$ConferenceName-functions-$AppEnvironment".ToLower(); | ||
"storageName" = "$($ConferenceName)functions$AppEnvironment".ToLower(); | ||
"storageType" = "Standard_LRS"; | ||
"newSessionNotificationLogicAppUrl" = $NewSessionNotificationLogicAppUrl; | ||
"deploymentZipUrl" = $DeploymentZipUrl; | ||
"sessionizeApiKey" = $SessionizeApiKey; | ||
"sessionizeReadModelSyncSchedule" = $SessionizeReadModelSyncSchedule; | ||
"eventbriteApiBearerToken" = $EventbriteApiBearerToken; | ||
} | ||
} | ||
|
||
try { | ||
Set-StrictMode -Version "Latest" | ||
$ErrorActionPreference = "Stop" | ||
|
||
if (-not $AlreadyLoggedIn) { | ||
Write-Output "Authenticating to ARM as service principal $ServicePrincipalId" | ||
$securePassword = ConvertTo-SecureString $ServicePrincipalPassword -AsPlainText -Force | ||
$servicePrincipalCredentials = New-Object System.Management.Automation.PSCredential ($ServicePrincipalId, $securePassword) | ||
Login-AzureRmAccount -ServicePrincipal -TenantId $TenantId -Credential $servicePrincipalCredentials | Out-Null | ||
} | ||
|
||
Write-Output "Selecting subscription $SubscriptionId" | ||
Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId | Out-Null | ||
|
||
Write-Output "Ensuring resource group $ResourceGroupName exists" | ||
New-AzureRmResourceGroup -Location $Location -Name $ResourceGroupName -Force | Out-Null | ||
|
||
Write-Output "Deploying to ARM" | ||
$Parameters = Get-Parameters | ||
$result = New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile "$PSScriptRoot\azuredeploy.json" -TemplateParameterObject $Parameters -Name ("$ConferenceName-$AppEnvironment-" + (Get-Date -Format "yyyy-MM-dd-HH-mm-ss")) -ErrorAction Continue -Verbose | ||
Write-Output $result | ||
if ((-not $result) -or ($result.ProvisioningState -ne "Succeeded")) { | ||
throw "Deployment failed" | ||
} | ||
|
||
} | ||
catch { | ||
Write-Error $_ -ErrorAction Continue | ||
exit 1 | ||
} |
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,200 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"serverFarmResourceId": { | ||
"type": "string" | ||
}, | ||
"functionsAppName": { | ||
"type": "string" | ||
}, | ||
"storageName": { | ||
"type": "string" | ||
}, | ||
"storageType": { | ||
"type": "string", | ||
"allowedValues": [ | ||
"Standard_LRS", | ||
"Standard_ZRS", | ||
"Standard_GRS", | ||
"Standard_RAGRS", | ||
"Premium_LRS" | ||
] | ||
}, | ||
"newSessionNotificationLogicAppUrl": { | ||
"type": "string" | ||
}, | ||
"deploymentZipUrl": { | ||
"type": "string" | ||
}, | ||
"sessionizeApiKey": { | ||
"type": "string" | ||
}, | ||
"sessionizeReadModelSyncSchedule": { | ||
"type": "string" | ||
}, | ||
"eventbriteApiBearerToken": { | ||
"type": "string" | ||
} | ||
}, | ||
"variables": { | ||
}, | ||
"resources": [ | ||
{ | ||
"type": "Microsoft.DocumentDB/databaseAccounts", | ||
"kind": "GlobalDocumentDB", | ||
"name": "[parameters('functionsAppName')]", | ||
"apiVersion": "2015-04-08", | ||
"location": "Australia East", | ||
"tags": { | ||
"defaultExperience": "DocumentDB" | ||
}, | ||
"scale": null, | ||
"properties": { | ||
"databaseAccountOfferType": "Standard", | ||
"consistencyPolicy": { | ||
"defaultConsistencyLevel": "Session", | ||
"maxIntervalInSeconds": 5, | ||
"maxStalenessPrefix": 100 | ||
}, | ||
"name": "[parameters('functionsAppName')]" | ||
}, | ||
"dependsOn": [] | ||
}, | ||
{ | ||
"type": "Microsoft.Insights/components", | ||
"name": "[parameters('functionsAppName')]", | ||
"apiVersion": "2014-04-01", | ||
"location": "Southeast Asia", | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Web/sites/', parameters('functionsAppName'))]" | ||
], | ||
"tags": { | ||
"[concat('hidden-link:', resourceId('Microsoft.Web/sites', parameters('functionsAppName')))]": "Resource" | ||
}, | ||
"properties": { | ||
"ApplicationId": "[parameters('functionsAppName')]", | ||
"Request_Source": "IbizaWebAppExtensionCreate" | ||
} | ||
}, | ||
{ | ||
"type": "Microsoft.Storage/storageAccounts", | ||
"name": "[parameters('storageName')]", | ||
"apiVersion": "2015-06-15", | ||
"location": "[resourceGroup().location]", | ||
"properties": { | ||
"accountType": "[parameters('storageType')]" | ||
} | ||
}, | ||
{ | ||
"type": "Microsoft.Web/sites", | ||
"name": "[parameters('functionsAppName')]", | ||
"kind": "functionapp", | ||
"apiVersion": "2015-08-01", | ||
"location": "[resourceGroup().location]", | ||
"properties": { | ||
"name": "[parameters('functionsAppName')]", | ||
"serverFarmId": "[parameters('serverFarmResourceId')]" | ||
}, | ||
"tags": { | ||
"[concat('hidden-related:', parameters('serverFarmResourceId'))]": "Resource" | ||
}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2015-08-01", | ||
"name": "appsettings", | ||
"type": "config", | ||
"dependsOn": [ | ||
"[parameters('functionsAppName')]", | ||
"[resourceId('Microsoft.Insights/components', parameters('functionsAppName'))]", | ||
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]" | ||
], | ||
"properties": { | ||
"WEBSITE_USE_ZIP": "[parameters('deploymentZipUrl')]", | ||
"WEBSITE_NODE_DEFAULT_VERSION": "8.9.4", | ||
"FUNCTIONS_EXTENSION_VERSION": "beta", | ||
"FUNCTION_APP_EDIT_MODE": "readonly", | ||
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', parameters('functionsAppName')), '2014-04-01').InstrumentationKey]", | ||
"ApplicationInsights:InstrumentationKey": "[reference(resourceId('Microsoft.Insights/components', parameters('functionsAppName')), '2014-04-01').InstrumentationKey]", | ||
"AzureWebJobsDashboard":"[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageName'), ';AccountKey=', listkeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-06-15').key1)]", | ||
"AzureWebJobsStorage":"[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageName'), ';AccountKey=', listkeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-06-15').key1)]", | ||
"AZURE_STORAGE_CONNECTION_STRING":"[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageName'), ';AccountKey=', listkeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-06-15').key1)]", | ||
"queue_STORAGE":"[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageName'), ';AccountKey=', listkeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-06-15').key1)]", | ||
"NewSessionNotificationLogicAppUrl": "[parameters('newSessionNotificationLogicAppUrl')]", | ||
"SessionsDataSourceCosmosDatabaseId": "Conference", | ||
"SessionsDataSourceCosmosCollectionId": "Sessions", | ||
"SessionizeApiKey": "[parameters('sessionizeApiKey')]", | ||
"SessionizeReadModelSyncSchedule": "[parameters('sessionizeReadModelSyncSchedule')]", | ||
"EventbriteApiBearerToken": "[parameters('eventbriteApiBearerToken')]" | ||
} | ||
}, | ||
{ | ||
"apiVersion": "2015-08-01", | ||
"type": "config", | ||
"name": "connectionstrings", | ||
"dependsOn": [ | ||
"[parameters('functionsAppName')]", | ||
"[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('functionsAppName'))]" | ||
], | ||
"properties": { | ||
"Sessions": { | ||
"value": "[concat('AccountEndpoint=https://', parameters('functionsAppName'), '.documents.azure.com:443/;AccountKey=', listkeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('functionsAppName')), '2015-04-08').primaryMasterKey)]", | ||
"type": "Custom" | ||
} | ||
} | ||
}, | ||
{ | ||
"apiVersion": "2015-08-01", | ||
"name": "web", | ||
"type": "config", | ||
"dependsOn": [ | ||
"[parameters('functionsAppName')]" | ||
], | ||
"properties": { | ||
"phpVersion": "", | ||
"pythonVersion": "", | ||
"nodeVersion": "8.9.4", | ||
"javaVersion": null, | ||
"netFrameworkVersion": "v4.0", | ||
"use32BitWorkerProcess": true, | ||
"webSocketsEnabled": true, | ||
"alwaysOn": true, | ||
"requestTracingEnabled": false, | ||
"httpLoggingEnabled": true, | ||
"logsDirectorySizeLimit": 100, | ||
"detailedErrorLoggingEnabled": false, | ||
"azureApplicationLogsFileSystemEnabled": true | ||
} | ||
}, | ||
{ | ||
"apiVersion": "2015-08-01", | ||
"name": "logs", | ||
"type": "config", | ||
"dependsOn": [ | ||
"[parameters('functionsAppName')]" | ||
], | ||
"properties": { | ||
"applicationLogs": { | ||
"fileSystem": { | ||
"level": "Information" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"apiVersion": "2015-08-01", | ||
"name": "Microsoft.ApplicationInsights.AzureWebSites", | ||
"type": "siteextensions", | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Web/Sites', parameters('functionsAppName'))]", | ||
"[resourceId('Microsoft.Web/Sites/config', parameters('functionsAppName'), 'web')]", | ||
"[resourceId('Microsoft.Insights/components', parameters('functionsAppName'))]" | ||
], | ||
"properties": { | ||
"feed_url": "https://www.siteextensions.net/api/v2/" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
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,13 @@ | ||
{ | ||
"TenantId": "", | ||
"SubscriptionId": "", | ||
"ConferenceName": "", | ||
"Location": "Australia East", | ||
"AppEnvironment": "dev", | ||
"AppServicePlanResourceGroup": "", | ||
"AppServicePlanName": "", | ||
"NewSessionNotificationLogicAppUrl": "", | ||
"DeploymentZipUrl": "", | ||
"SessionizeApiKey": "", | ||
"EventbriteApiBearerToken": "" | ||
} |