forked from ita-social-projects/GreenCity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
az-cd-pipeline.yml
158 lines (139 loc) · 4.66 KB
/
az-cd-pipeline.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
trigger:
batch: true
branches:
include:
- dev
paths:
exclude:
- README.md
variables:
agentOS: ubuntu-latest
azKeyVault: key-vault-greencity
jsonSecret: google-credentials
jsonFile: google-creds.json
jsonLocation: /site/wwwroot
artifactName: drop
coreRepoName: core
mailRepoName: email
onbootJarName: app.jar
azureSub: GreenCity
resourceGroup: GreenCity
coreServiceName: greencity
mailServiceName: greencity-mail
stages:
- stage: Build
jobs:
- job: Build
pool:
vmImage: $(agentOS)
steps:
- task: AzureCLI@2
displayName: Get GOOGLE_APPLICATION_CREDENTIALS from Azure Key Vault
inputs:
azureSubscription: '$(azureSub)'
scriptType: 'bash'
scriptLocation: inlineScript
inlineScript: |
az keyvault secret download --name $(jsonSecret) --vault-name $(azKeyVault) --file $(jsonFile)
- task: AzureKeyVault@1
displayName: Get FTP credentials from Azure Key Vault
inputs:
azureSubscription: '$(azureSub)'
KeyVaultName: '$(azKeyVault)'
SecretsFilter: 'ftpHost, ftpUser, ftpPass'
- task: FtpUpload@2
displayName: Upload json to app service via FTP
inputs:
credentialsOption: 'inputs'
serverUrl: '$(ftpHost)'
username: '$(ftpUser)'
password: '$(ftpPass)'
filePatterns: '$(jsonFile)'
remoteDirectory: '$(jsonLocation)'
- task: AzureAppServiceSettings@1
displayName: Set GOOGLE_APPLICATION_CREDENTIALS config in Azure Portal
inputs:
azureSubscription: '$(azureSub)'
appName: '$(coreServiceName)'
resourceGroupName: '$(resourceGroup)'
appSettings: |
[
{
"name": "GOOGLE_APPLICATION_CREDENTIALS",
"value": "/home$(jsonLocation)/$(jsonFile)",
"slotSetting": false
}
]
- task: Maven@3
displayName: Maven package
inputs:
mavenPomFile: 'pom.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
mavenVersionOption: 'Default'
options: '-Dmaven.test.skip=true'
- script: mv $(coreRepoName)/target/*.jar $(coreRepoName)/target/$(onbootJarName)
displayName: Rename core jar to app
- script: mv $(mailRepoName)/target/*.jar $(mailRepoName)/target/$(onbootJarName)
displayName: Rename email jar to app
- task: CopyFiles@2
displayName: Copy Files
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**/target/*.jar'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: Publish Artifact
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
artifactName: '$(artifactName)'
- stage: Deploy
jobs:
- deployment: DeployCore
displayName: Deploy core app service
pool:
vmImage: $(agentOS)
environment: 'prod'
strategy:
runOnce:
deploy:
steps:
- download: none
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: '$(artifactName)'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment@4
inputs:
azureSubscription: '$(azureSub)'
appType: 'webAppLinux'
WebAppName: '$(coreServiceName)'
deployToSlotOrASE: true
ResourceGroupName: '$(resourceGroup)'
packageForLinux: '$(System.ArtifactsDirectory)/$(artifactName)/$(coreRepoName)/target/$(onbootJarName)'
- deployment: DeployMail
displayName: Deploy mail app service
pool:
vmImage: $(agentOS)
environment: 'prod'
strategy:
runOnce:
deploy:
steps:
- download: none
- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: '$(artifactName)'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment@4
inputs:
azureSubscription: '$(azureSub)'
appType: 'webAppLinux'
WebAppName: '$(mailServiceName)'
deployToSlotOrASE: true
ResourceGroupName: '$(resourceGroup)'
packageForLinux: '$(System.ArtifactsDirectory)/$(artifactName)/$(mailRepoName)/target/$(onbootJarName)'