-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathazure-pipelines.yaml
328 lines (314 loc) · 16.5 KB
/
azure-pipelines.yaml
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
trigger:
- develop
pool:
vmImage: "ubuntu-latest"
variables:
- group: aleo-program-ids
- name: aleoProgramIdsGroupId
value: 10
- name: devOpsOrg
value: $(System.TeamFoundationCollectionUri)
- name: devOpsProject
value: $(System.TeamProject)
- name: commitHash
value: $(Build.SourceVersion)
- name: buildId
value: $(Build.BuildId)
- name: privateKey
value: $(PRIVATE_KEY)
- name: dockerRegistryUrl
value: $(DOCKER_REGISTRY_URL)
- name: vmProject
value: $(VM_PROJECT)
- name: containerServiceAccountName
value: $(CONTAINER_SERVICE_ACCOUNT_NAME)
- name: containerServiceAccountAddress
value: $(containerServiceAccountName)@$(vmProject).iam.gserviceaccount.com
- name: runAleoDeployments
value: $(RUN_ALEO_DEPLOYMENTS)
- name: GIT_MIRROR_URL
value: $(gitMirrorUrl)
- name: GIT_MIRROR_TOKEN
value: $(gitMirrorToken)
stages:
- stage: check_updated_programs
displayName: Check updated programs that have to be deployed
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), eq(variables['runAleoDeployments'], 'True'))
jobs:
- job: run_check_script
displayName: Running script to check updated programs
steps:
- script: |
files=$(git diff HEAD HEAD~ --name-only)
while IFS= read -r name; do
echo $name
if [[ $name =~ ^contracts/boloney_match_summary/* ]]; then
echo "##vso[task.setvariable variable=boloneyMatchSummaryUpdated;isoutput=true]True"
elif [[ $name =~ ^contracts/boloney_match/* ]]; then
echo "##vso[task.setvariable variable=boloneyMatchUpdated;isoutput=true]True"
elif [[ $name =~ ^contracts/dice/* ]]; then
echo "##vso[task.setvariable variable=diceUpdated;isoutput=true]True"
elif [[ $name =~ ^contracts/power_up_2a/* ]]; then
echo "##vso[task.setvariable variable=powerUp2Updated;isoutput=true]True"
elif [[ $name =~ ^contracts/power_up/* ]]; then
echo "##vso[task.setvariable variable=powerUpUpdated;isoutput=true]True"
elif [[ $name =~ ^contracts/rng/* ]]; then
echo "##vso[task.setvariable variable=rngUpdated;isoutput=true]True"
elif [[ $name =~ ^contracts/hash_chain/* ]]; then
echo "##vso[task.setvariable variable=hashChainUpdated;isoutput=true]True"
fi
done <<<"$files"
name: UpdatedPrograms
- stage: build_and_deploy_leo_programs_stage
displayName: Build and deploy Leo programs
dependsOn: check_updated_programs
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
variables:
boloneyMatchUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.boloneyMatchUpdated']]
boloneyMatchSummaryUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.boloneyMatchSummaryUpdated']]
diceUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.diceUpdated']]
powerUpUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.powerUpUpdated']]
rngUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.rngUpdated']]
hashChainUpdated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.hashChainUpdated']]
powerUp2Updated: $[stageDependencies.check_updated_programs.run_check_script.outputs['UpdatedPrograms.powerUp2Updated']]
jobs:
- job: build_and_deploy_leo_programs_job
displayName: Build and deploy programs
condition: succeeded()
steps:
- task: DownloadSecureFile@1
name: authkey
displayName: "Download Service Account Key"
inputs:
secureFile: $(containerServiceAccountName).json
retryCount: "2"
- script: gcloud auth activate-service-account $(containerServiceAccountAddress) --key-file=$(authkey.secureFilePath)
displayName: Activate Service Account
- script: gcloud --quiet auth configure-docker $(dockerRegistryUrl)
displayName: Configure Docker Account
- script: echo $(System.AccessToken) | az devops login --organization $(devOpsOrg)
displayName: Logging in to DevOps organization
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=boloney_match \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=5000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Boloney match Docker build
condition: and(succeeded(), eq(variables['boloneyMatchUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=boloneyMatchVersion;isoutput=true]$(buildId)"
displayName: Update boloney match version locally
condition: and(succeeded(), eq(variables['boloneyMatchUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name boloneyMatchVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update boloney match version in variable group
condition: and(succeeded(), eq(variables['boloneyMatchUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=boloney_match_summary \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=5000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Boloney match summary Docker build
condition: and(succeeded(), eq(variables['boloneyMatchSummaryUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=boloneyMatchSummaryVersion;isoutput=true]$(buildId)"
displayName: Update boloney match summary version locally
condition: and(succeeded(), eq(variables['boloneyMatchSummaryUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name boloneyMatchSummaryVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update boloney match summary version in variable group
condition: and(succeeded(), eq(variables['boloneyMatchSummaryUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=dice \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=16000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Dice Docker build
condition: and(succeeded(), eq(variables['diceUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=diceVersion;isoutput=true]$(buildId)"
displayName: Update dice version locally
condition: and(succeeded(), eq(variables['diceUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name diceVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update dice version in variable group
condition: and(succeeded(), eq(variables['diceUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=power_up \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=15000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Power-up Docker build
condition: and(succeeded(), eq(variables['powerUpUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=powerUpVersion;isoutput=true]$(buildId)"
displayName: Update power-up version locally
condition: and(succeeded(), eq(variables['powerUpUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name powerUpVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update power-up version in variable group
condition: and(succeeded(), eq(variables['powerUpUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=rng \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=5000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: RNG Docker build
condition: and(succeeded(), eq(variables['rngUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=rngVersion;isoutput=true]$(buildId)"
displayName: Update RNG version locally
condition: and(succeeded(), eq(variables['rngUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name rngVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update RNG version in variable group
condition: and(succeeded(), eq(variables['rngUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=hash_chain \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=5000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Hash chain Docker build
condition: and(succeeded(), eq(variables['hashChainUpdated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=hashChainVersion;isoutput=true]$(buildId)"
displayName: Update hash chain version locally
condition: and(succeeded(), eq(variables['hashChainUpdated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name hashChainVersion \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update hash chain version in variable group
condition: and(succeeded(), eq(variables['hashChainUpdated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- script: |
docker build -f Dockerfile.program . \
--build-arg APP_NAME=power_up_2a \
--build-arg PRIVATE_KEY=$(privateKey) \
--build-arg BUILD_ID=$(buildId) \
--build-arg FEE=5000000 \
--build-arg ZK_GAMING_ALEO="eu.gcr.io/web3-335312/aleo/zk-gaming-snarkos:latest"
displayName: Power-up 2 Docker build
condition: and(succeeded(), eq(variables['powerUp2Updated'], 'True'))
retryCountOnTaskFailure: 3
- script: echo "##vso[task.setvariable variable=powerUp2Version;isoutput=true]$(buildId)"
displayName: Update power-up 2 version locally
condition: and(succeeded(), eq(variables['powerUp2Updated'], 'True'))
- script: |
az pipelines variable-group variable update \
--group-id $(aleoProgramIdsGroupId) \
--name powerUp2Version \
--org $(devOpsOrg) \
--project $(devOpsProject) \
--value $(buildId)
displayName: Update power-up 2 version in variable group
condition: and(succeeded(), eq(variables['powerUp2Updated'], 'True'))
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- stage: build_and_deploy
displayName: Build and Deploy
dependsOn: build_and_deploy_leo_programs_stage
condition: and(or(succeeded(), ne(variables['runAleoDeployments'], 'True')), ne(variables['Build.Reason'], 'PullRequest'))
jobs:
- job: build_and_deploy
displayName: Build Docker images and deploy through Kubernetes
steps:
- script: curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && sudo install skaffold /usr/local/bin/
displayName: Install Skaffold
- task: DownloadSecureFile@1
name: authkey
displayName: "Download Service Account Key"
inputs:
secureFile: $(containerServiceAccountName).json
retryCount: "2"
- script: gcloud auth activate-service-account $(containerServiceAccountAddress) --key-file=$(authkey.secureFilePath)
displayName: Activate Service Account
- script: gcloud --quiet auth configure-docker $(dockerRegistryUrl)
displayName: Configure Docker Account
- task: Kubernetes@1
inputs:
connectionType: "Kubernetes Service Connection"
kubernetesServiceEndpoint: "gke-zk-gaming"
namespace: "zk-gaming-tk-staging"
command: "login"
- script: |
skaffold run --filename=skaffold.snarkos.yaml
displayName: Build and push Aleo Docker images
enabled: false
- script: |
sed 's/SEDSUBST_BOLONEY_MATCH_VERSION/"$(boloneyMatchVersion)"/g' deployment/staging/deployments/toolkit.template.yaml > deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_BOLONEY_MATCH_SUMMARY_VERSION/"$(boloneyMatchSummaryVersion)"/g' deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_DICE_VERSION/"$(diceVersion)"/g' deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_POWER_UP_VERSION/"$(powerUpVersion)"/g' deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_POWER_UP_2_VERSION/"$(powerUp2Version)"/g' deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_RNG_VERSION/"$(rngVersion)"/g' deployment/staging/deployments/toolkit.yaml
sed -i 's/SEDSUBST_HASH_CHAIN_VERSION/"$(hashChainVersion)"/g' deployment/staging/deployments/toolkit.yaml
displayName: Setting program ids in Kubernetes deployment
- script: |
skaffold run --filename=skaffold.staging.yaml
displayName: Build and push Toolkit Docker images
- stage: mirror
displayName: Mirror
dependsOn:
- build_and_deploy
condition: ne(variables['Build.Reason'], 'PullRequest')
jobs:
- job:
displayName: Mirror repository
steps:
- task: CmdLine@2
displayName: Push repository to mirror
continueOnError: true
inputs:
script: 'git -c http.$(GIT_MIRROR_URL).extraheader="AUTHORIZATION: basic $(GIT_MIRROR_TOKEN)" push --force $(GIT_MIRROR_URL) HEAD:$(Build.SourceBranch)'