forked from dotnet/arcade-services
-
Notifications
You must be signed in to change notification settings - Fork 1
/
grafana-setup.yml
94 lines (87 loc) · 3.6 KB
/
grafana-setup.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
trigger:
branches:
exclude:
- '*'
variables:
# Cannot use key:value syntax in root defined variables
- name: _TeamName
value: DotNetCore
- name: _PublishUsingPipelines
value: true
- name: _DotNetArtifactsCategory
value: .NETCore
# This can be overridden if we are using a locally built fork
- group: Dotnet Grafana
# Variables we want to be settable, so can't be defined here:
# GrafanaBinPath: /usr/sbin/grafana-server
# TargetVmName: grafana
# TargetResourceGroup: monitoring
stages:
- stage: deploy
displayName: Deploy grafana server
jobs:
- template: /eng/common/templates/jobs/jobs.yml
parameters:
enableMicrobuild: false
enablePublishBuildArtifacts: false
enablePublishTestResults: false
enablePublishBuildAssets: false
enablePublishUsingPipelines: ${{ variables._PublishUsingPipelines }}
enableTelemetry: false
helixRepo: dotnet/arcade-services
jobs:
- job: Windows_NT
timeoutInMinutes: 90
pool:
vmImage: windows-2019
steps:
- checkout: self
clean: true
- powershell: |
if (-not (Test-Path env:GrafanaDomain)) { Write-Host "Missing GrafanaDomain, ensure required variables are defined"; exit 1}
if (-not (Test-Path env:TargetVmName)) { Write-Host "Missing TargetVmName, ensure required variables are defined"; exit 1}
if (-not (Test-Path env:TargetResourceGroup)) { Write-Host "Missing TargetResourceGroup, ensure required variables are defined"; exit 1}
if ($env:GrafanaEnvironment -ne "staging" -and $env:GrafanaEnvironment -ne "production") { Write-Host "GrafanaEnvironment must be 'staging' or 'production'"; exit 1}
Write-Host "All required variables defined"
displayName: Ensure variables defined
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)\src\Monitoring\grafana-init
includeRootFolder: false
archiveType: tar
tarCompression: gz
archiveFile: $(Build.ArtifactStagingDirectory)/grafana-init.tar.gz
- task: AzureFileCopy@3
displayName: Copy grafana-init to VM
inputs:
sourcePath: $(Build.ArtifactStagingDirectory)/grafana-init.tar.gz
azureSubscription: DncEng-VSTS
storage: dotnetgrafana
containerName: build-transfer
blobPrefix: grafana-init-$(Build.BuildNumber)
destination: azureBlob
outputStorageUri: UploadedUri
- task: AzureCLI@2
displayName: Execute grafana-init/setup.sh on VM
inputs:
azureSubscription: DncEng-VSTS
scriptType: ps
scriptLocation: inlineScript
inlineScript: >-
az vm run-command invoke
-g $(TargetResourceGroup)
-n $(TargetVmName)
--command-id RunShellScript
--scripts
"
mkdir -p /tmp/grafana-init/ &&
cd /tmp/grafana-init &&
curl --silent --show-error --fail '$(UploadedUri)grafana-init-$(Build.BuildNumber)/grafana-init.tar.gz' -o ./grafana-init.tar.gz &&
tar -xzf ./grafana-init.tar.gz &&
sudo bash ./setup.sh -b '$(GrafanaBinPath)' -d '$(GrafanaDomain)' --$(GrafanaEnvironment)
"
| Tee-Object -variable cmdoutput
| findstr /c:"SETUP_EXIT_CODE=0"
| Out-Null;
$cmdoutput |% {$_ -replace "\\n","`n-> "} |% {$_ -replace "\\",""} | Write-Host;
$LASTEXITCODE