Skip to content

Commit

Permalink
#7 multi-region support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLarsenNZ committed Mar 19, 2021
1 parent ce3e828 commit ec36169
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
8 changes: 8 additions & 0 deletions deploy/_vars.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$location = 'australiaeast'
$loc = 'aue'
$rg = 'numberservice-rg'
$tags = 'project=NumberService', 'repo=DanielLarsenNZ/NumberService'
$insights = 'numberservice-insights'
$cosmos = 'numberservice'
$cosmosDB = 'NumberService'
$container='Numbers'
43 changes: 9 additions & 34 deletions deploy/deploy-azure.ps1
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
# Deploy NumberService resources

$ErrorActionPreference = 'Stop'
. ./_vars.ps1

$location = 'australiaeast'
$loc = 'aue'
$rg = 'numberservice-rg'
$tags = 'project=NumberService', 'repo=DanielLarsenNZ/NumberService'
$cosmos = 'numberservice'
$cosmosDB = 'NumberService'
$throughput = 400
$container='Numbers'
$pk = '/id'
$insights = 'numberservice-insights'
$functionApp = "numberservice-$loc"
$repo = 'https://github.com/DanielLarsenNZ/NumberService.git'
$storage = "numservfn$loc"

$primaryCosmosLocation = 'australiaeast'
$secondaryCosmosLocation = 'australiasoutheast'

# RESOURCE GROUP
az group create -n $rg --location $location --tags $tags


# COSMOS DB ACCOUNT
az cosmosdb create -n $cosmos -g $rg --default-consistency-level Session `
--locations regionName=$location failoverPriority=0 isZoneRedundant=True
--locations regionName=$primaryCosmosLocation failoverPriority=0 isZoneRedundant=True `
--locations regionName=$secondaryCosmosLocation failoverPriority=1 isZoneRedundant=False `
--enable-automatic-failover $true `
--enable-multiple-write-locations $true
az cosmosdb sql database create -a $cosmos -g $rg -n $cosmosDB --throughput $throughput
az cosmosdb sql container create -a $cosmos -g $rg -d $cosmosDB -n $container -p $pk
$connString = ( az cosmosdb keys list -n $cosmos -g $rg --type 'connection-strings' | ConvertFrom-Json ).connectionStrings[0].connectionString


# STORAGE ACCOUNT
az storage account create -n $storage -g $rg --tags $tags --location $location --sku 'Standard_LRS'

$env:NUMBERS_COSMOS_CONNSTRING = ( az cosmosdb keys list -n $cosmos -g $rg --type 'connection-strings' | ConvertFrom-Json ).connectionStrings[0].connectionString

# APPLICATION INSIGHTS
$instrumentationKey = ( az monitor app-insights component create --app $insights --location $location -g $rg --tags $tags | ConvertFrom-Json ).instrumentationKey


# FUNCTION APP
az functionapp create -n $functionApp -g $rg --consumption-plan-location $location --functions-version 3 `
--app-insights $insights --app-insights-key $instrumentationKey -s $storage
az functionapp config appsettings set -n $functionApp -g $rg --settings `
"CosmosDbConnectionString=$connString" `
"CosmosDbDatabaseId=$cosmosDB" `
"CosmosDbContainerId=$container"
az functionapp deployment source config -n $functionApp -g $rg --repo-url $repo --branch 'main'

# Tear down
# az group delete -n $rg --yes
$env:NUMBERS_APP_INSIGHTS_IKEY = ( az monitor app-insights component create --app $insights --location $location -g $rg --tags $tags | ConvertFrom-Json ).instrumentationKey
29 changes: 29 additions & 0 deletions deploy/deploy-function.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)] [ValidateSet('australiaeast', 'australiasoutheast')] $FunctionLocation
)

. ./_vars.ps1

$loc = switch ($FunctionLocation) {
'australiaeast' { 'aue' }
'australiasoutheast' { 'ase' }
default { throw "$FunctionLocation is not supported" }
}

$functionApp = "numberservice-$loc"
$repo = 'https://github.com/DanielLarsenNZ/NumberService.git'
$storage = "numservfn$loc"

# STORAGE ACCOUNT
az storage account create -n $storage -g $rg --tags $tags --location $FunctionLocation --sku 'Standard_LRS'


# FUNCTION APP
az functionapp create -n $functionApp -g $rg --consumption-plan-location $FunctionLocation --functions-version 3 `
--app-insights $insights --app-insights-key $env:NUMBERS_APP_INSIGHTS_IKEY -s $storage
az functionapp config appsettings set -n $functionApp -g $rg --settings `
"CosmosDbConnectionString=$env:NUMBERS_COSMOS_CONNSTRING" `
"CosmosDbDatabaseId=$cosmosDB" `
"CosmosDbContainerId=$container"
az functionapp deployment source config -n $functionApp -g $rg --repo-url $repo --branch 'main'

0 comments on commit ec36169

Please sign in to comment.