Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Personal/wiyochum/arm deployment event batching #83

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions deploy/scripts/Create-IomtWebJobsEnvironment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<#
.SYNOPSIS
Creates a new IoMT FHIR Connector for Azure without using Stream Analytics
.DESCRIPTION
#>
param
(
[Parameter(Mandatory = $true)]
[string]$ResourceGroup,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateLength(5,12)]
[ValidateScript({
if ("$_" -cmatch "(^([a-z]|\d)+$)") {
return $true
}
else {
throw "Environment name must be lowercase and numbers"
return $false
}
})]
[string]$EnvironmentName,

[Parameter(Mandatory = $false)]
[ValidateSet('South Africa North', 'South Africa West', 'East Asia', 'Southeast Asia', 'Australia Central', 'Australia Central 2', 'Australia East', 'Australia Southeast', 'Brazil South', 'Brazil Southeast', 'Canada Central', 'Canada East', 'China East', 'China East 2', 'China North', 'China North 2', 'North Europe', 'West Europe', 'France Central', 'France South', 'Germany Central', 'Germany Northeast', 'Germany West Central', 'Central India', 'South India', 'West India', 'Japan East', 'Japan West', 'Korea Central', 'Korea South', 'Norway East', 'Switzerland North', 'Switzerland West', 'UAE Central', 'UAE North', 'UK West', 'UK South', 'Central US', 'East US', 'East US 2', 'North Central US', 'South Central US', 'West Central US', 'West US', 'West US 2')]
[string]$EnvironmentLocation = "North Central US",
[Parameter(Mandatory = $false)]
[ValidateSet('R4')]
[string]$FhirVersion = "R4",

[Parameter(Mandatory = $false)]
[string]$SourceRepository = "https://github.com/microsoft/iomt-fhir",

[Parameter(Mandatory = $false)]
[string]$SourceRevision = "master",

[Parameter(Mandatory = $true)]
[string]$FhirServiceUrl,

[Parameter(Mandatory = $true)]
[string]$FhirServiceAuthority,

[Parameter(Mandatory = $true)]
[string]$FhirServiceClientId,

[Parameter(Mandatory = $true)]
[string]$FhirServiceSecret,

[Parameter(Mandatory = $false)]
[string]$EnvironmentDeploy = $true
)

Function BuildPackage() {
try {
Push-Location $currentPath
cd ../../src/console/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: do we assume that the script is being executed at a specific location, like "deploy/scripts/"? is that possible to set a working directory with dotnet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be better to just resolve the path and build against it if possible. Changing directory and keeping target can get tricky.


In reply to: 544493385 [](ancestors = 544493385)

dotnet restore
dotnet build --output $buildPath /p:DeployOnBuild=true /p:DeployTarget=Package
} finally {
Pop-Location
}
}

Function Deploy-WebJobs($DeviceDataWebJobName, $NormalizedDataWebJobName) {
try {
$tempPath = "$currentPath\Temp"
$webAppName = $EnvironmentName
$webJobType = "Continuous"

Clear-Path -WebJobName $DeviceDataWebJobName
Clear-Path -WebJobName $NormalizedDataWebJobName

$DeviceWebJobPath = "$tempPath\App_Data\jobs\$webJobType\$DeviceDataWebJobName"
$NormalizedWebJobPath = "$tempPath\App_Data\jobs\$webJobType\$NormalizedDataWebJobName"
Copy-Item "$buildPath\*" -Destination $DeviceWebJobPath -Recurse
Copy-Item "$buildPath\*" -Destination $NormalizedWebJobPath -Recurse

Compress-Archive -Path "$tempPath\*" -DestinationPath "$currentPath\iomtwebjobs.zip" -Force

Publish-AzWebApp -ArchivePath "$currentPath\iomtwebjobs.zip" -ResourceGroupName $ResourceGroup -Name $webAppName
} finally {
Pop-Location
}
}

Function Clear-Path($WebJobName) {
$WebJobPath = "$tempPath\App_Data\jobs\$webJobType\$WebJobName"
Get-ChildItem -Path $WebJobPath -Recurse | Remove-Item -Force -Recurse
if( -Not (Test-Path -Path $WebJobPath ) )
{
New-Item $WebJobPath -ItemType Directory
}
}

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

# deploy event hubs, app service, key vaults, storage
if ($EnvironmentDeploy -eq $true) {
Write-Host "Deploying environment resources..."
$webjobTemplate = "..\templates\default-azuredeploy-webjobs.json"
New-AzResourceGroupDeployment -TemplateFile $webjobTemplate -ResourceGroupName $ResourceGroup -ServiceName $EnvironmentName -FhirServiceUrl $fhirServiceUrl -FhirServiceAuthority $FhirServiceAuthority -FhirServiceResource $fhirServiceUrl -FhirServiceClientId $FhirServiceClientId -FhirServiceClientSecret (ConvertTo-SecureString -String $FhirServiceSecret -AsPlainText -Force) -RepositoryUrl $SourceRepository -RepositoryBranch $SourceRevision -ResourceLocation $EnvironmentLocation
}

# deploy the stream analytics replacement webjobs
Write-Host "Deploying WebJobs..."

$currentPath = (Get-Location).Path
$buildPath = "$currentPath\OSS_Deployment"
BuildPackage
Deploy-WebJobs -DeviceDataWebJobName "devicedata" -NormalizedDataWebJobName "normalizeddata"

Loading