forked from microsoft/fhir-server-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
114 lines (105 loc) · 7.43 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Build ASP.NET Core project using Azure Pipelines
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core?view=vsts
variables:
buildConfiguration: "Release"
stages:
- stage: Deploy
jobs:
- job: DeployAndTest
pool:
vmImage: "vs2017-win2016"
steps:
- task: DotNetCoreInstaller@0
displayName: "Use .NET Core sdk 2.2"
inputs:
version: 2.2.101
- powershell: |
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
Install-Module -Name AzureAD -Force -Verbose -Scope CurrentUser
displayName: "Install AzureAD"
- task: AzureKeyVault@1
displayName: "Azure Key Vault: fhirserversamples-tenant"
inputs:
azureSubscription: "Microsoft Health Open Source Subscription"
KeyVaultName: "fhirserversamples-tenant"
- task: AzurePowerShell@3
displayName: "Deploy to Azure"
inputs:
preferredAzurePowerShellVersion: 5.1.1
azureSubscription: "Microsoft Health Open Source Subscription"
ScriptType: InlineScript
Inline: |
$user = "$(tenant-admin-username)"
$passwd = ConvertTo-SecureString -AsPlainText "$(tenant-admin-password)" -Force
$adminCreds = New-Object PSCredential $user,$passwd
Connect-AzureAD -TenantId "$(tenant-id)" -Credential $adminCreds
$tenantInfo = Get-AzureADCurrentSessionInfo -ErrorAction Stop
$environmentName = "fhirsampdev"
if ($env:BUILD_SOURCEBRANCHNAME -eq "merge")
{
# branch: /refs/pull/<PR>/merge
$pr = $env:BUILD_SOURCEBRANCH.split('/')[2]
$environmentName = "fhirsamp-$pr"
$pulls = Invoke-WebRequest 'https://api.github.com/repos/Microsoft/fhir-server-samples/pulls' | ConvertFrom-Json
$pullDetails = $pulls | Where-Object { $_.number -eq $pr }
$remoteRepo = $pullDetails.head.repo.full_name
$remoteRepo = "https://github.com/" + $remoteRepo
$remoteBranch = $pullDetails.head.ref
}
else
{
$remoteRepo = "https://github.com/Microsoft/fhir-server-samples"
$remoteBranch = "master"
}
Write-Host "##vso[task.setvariable variable=dashboardWebAppName]${environmentName}dash"
Write-Host "##vso[task.setvariable variable=DashboardUrl]https://${environmentName}dash.azurewebsites.net"
Write-Host "##vso[task.setvariable variable=FhirServerUrl]https://${environmentName}.azurehealthcareapis.com"
cd $(Build.SourcesDirectory)/deploy/scripts/
Write-Host "Remote Repo: ${remoteRepo}"
Write-Host "Remote branch: ${remoteBranch}"
./Create-FhirServerSamplesEnvironment.ps1 -EnvironmentName $environmentName -AdminPassword $(ConvertTo-SecureString "Fh1rD3m0!!" -AsPlainText -Force) -EnvironmentLocation "westus" -DeployAdf $true -UsePaaS $true -SourceRepository "${remoteRepo}" -SourceRevision "${remoteBranch}"
$DashboardUserUpn = (Get-AzureKeyVaultSecret -VaultName "${environmentName}-ts" -Name "${environmentName}-admin-upn").SecretValueText
$DashboardUserPassword = (Get-AzureKeyVaultSecret -VaultName "${environmentName}-ts" -Name "${environmentName}-admin-password").SecretValueText
Write-Host "##vso[task.setvariable variable=DashboardUserUpn]$DashboardUserUpn"
Write-Host "##vso[task.setvariable variable=DashboardUserPassword]$DashboardUserPassword"
$storageAccountName = ("${environmentName}impsa").Replace('-','');
$storageAccountKey = (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $environmentName)[0].Value
$storageAccountConnectionString = "DefaultEndpointsProtocol=https;AccountName=${storageAccountName};AccountKey=${storageAccountKey}"
Write-Host "##vso[task.setvariable variable=StorageAccountConnectionString]$storageAccountConnectionString"
$fhirServerMetadataUrl = "https://${environmentName}.azurehealthcareapis.com/metadata"
Invoke-WebRequest $fhirServerMetadataUrl
$functionAppUrl = "https://${environmentName}imp.azurewebsites.net"
Invoke-WebRequest $functionAppUrl
- powershell: |
$env:FhirServerUrl = "$(FhirServerUrl)"
$env:DashboardUrl = "$(DashboardUrl)"
$env:DashboardUserUpn = "$(DashboardUserUpn)"
$env:DashboardUserPassword = "$(DashboardUserPassword)"
$env:StorageAccountConnectionString = "$(StorageAccountConnectionString)"
Write-Host "FhirServerUrl: " + $env:FhirServerUrl
Write-Host "DashboardUrl: " + $env:DashboardUrl
Write-Host "DashboardUserUpn: " + $env:DashboardUserUpn
Write-Host "DashboardUserPassword: " + $env:DashboardUserPassword
Write-Host "StorageAccountConnectionString: " + $env:StorageAccountConnectionString
cd $(Build.SourcesDirectory)/test/FhirDashboard.Tests.E2E
dotnet test
displayName: "PowerShell Script"
- task: AzurePowerShell@3
displayName: "Delete Environment"
inputs:
preferredAzurePowerShellVersion: 5.1.1
azureSubscription: "Microsoft Health Open Source Subscription"
ScriptType: InlineScript
Inline: |
$user = "$(tenant-admin-username)"
$passwd = ConvertTo-SecureString -AsPlainText "$(tenant-admin-password)" -Force
$adminCreds = New-Object PSCredential $user,$passwd
Connect-AzureAD -TenantId "$(tenant-id)" -Credential $adminCreds
if ($env:BUILD_SOURCEBRANCHNAME -eq "merge")
{
# branch: /refs/pull/<PR>/merge
$pr = $env:BUILD_SOURCEBRANCH.split('/')[2]
$environmentName = "fhirsamp-$pr"
cd $(Build.SourcesDirectory)/deploy/scripts/
./Delete-FhirServerSamplesEnvironment.ps1 -EnvironmentName $environmentName
}