-
Notifications
You must be signed in to change notification settings - Fork 10
494 lines (469 loc) · 16.6 KB
/
cd.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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
name: "CD"
on:
workflow_dispatch:
inputs:
sha:
description: "partner-chains commit SHA to build from"
required: true
type: string
tag:
description: "partner-chains release tag"
required: true
type: string
no-release:
description: "Skip Release and GHCR steps"
required: false
type: boolean
default: false
no-deploy:
description: "Skip deploy steps"
required: false
type: boolean
default: false
no-tests:
description: "Skip test steps"
required: false
type: boolean
default: false
permissions:
id-token: write
contents: write
packages: write
env:
AWS_REGION: "eu-central-1"
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
STAGING_PREVIEW_SERVICES_HOST: staging-preview-services-service.staging-preview.svc.cluster.local
STAGING_PREVIEW_VALIDATOR_1_HOST: staging-preview-validator-1-service.staging-preview.svc.cluster.local
STAGING_PREVIEW_VALIDATOR_1_PORT: 9933
jobs:
build-linux:
permissions:
id-token: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}
- name: Build and Upload for Linux
uses: ./.github/actions/artifacts/build-pc-artifacts
with:
sha: ${{ inputs.sha }}
tag: ${{ inputs.tag }}
os: linux
build-macos-x86_64:
if: ${{ github.event.inputs.no-release != 'true' }}
permissions:
id-token: write
contents: write
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}
- name: Build and Upload for macOS x86_64
uses: ./.github/actions/artifacts/build-pc-artifacts
with:
sha: ${{ inputs.sha }}
tag: ${{ inputs.tag }}
os: macos-x86_64
build-macos-arm64:
if: ${{ github.event.inputs.no-release != 'true' }}
permissions:
id-token: write
contents: write
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}
- name: Build and Upload for macOS arm64
uses: ./.github/actions/artifacts/build-pc-artifacts
with:
sha: ${{ inputs.sha }}
tag: ${{ inputs.tag }}
os: macos-arm64
build-and-publish-ecr:
permissions:
id-token: write
contents: write
needs: build-linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and Publish to ECR
uses: ./.github/actions/images/build-and-publish-ecr
with:
sha: ${{ inputs.sha }}
tag: ${{ inputs.tag }}
env:
AWS_REGION: "eu-central-1"
ECR_REGISTRY_SECRET: ${{ secrets.ECR_REGISTRY_SECRET }}
AWS_ROLE_ARN_SECRET: ${{ secrets.AWS_ROLE_ARN_SECRET }}
create-draft-release:
if: ${{ github.event.inputs.no-release != 'true' }}
permissions:
id-token: write
contents: write
needs:
- build-linux
- build-macos-x86_64
- build-macos-arm64
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Draft Release
uses: ./.github/actions/release/create-draft-release
with:
tag: ${{ inputs.tag }}
env:
GITHUB_TOKEN: ${{ github.token }}
generate-chain-specs:
permissions:
id-token: write
contents: write
needs: build-linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate Chain Specs
uses: ./.github/actions/artifacts/generate-chain-specs
with:
tag: ${{ inputs.tag }}
upload-chain-specs:
permissions:
id-token: write
contents: write
needs: generate-chain-specs
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Upload chain spec artifacts to Kubernetes
uses: ./.github/actions/deploy/upload-chain-specs
with:
sha: ${{ github.sha }}
env:
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
deploy-staging-preview:
if: ${{ github.event.inputs.no-deploy != 'true' }}
permissions:
id-token: write
contents: write
needs:
- build-and-publish-ecr
- upload-chain-specs
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy staging-preview
uses: ./.github/actions/deploy/deploy-staging-preview
with:
image: ${{ secrets.ECR_REGISTRY_SECRET }}/substrate-node:${{ inputs.sha }}
sha: ${{ github.sha }}
env:
AWS_REGION: "eu-central-1"
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
AWS_ROLE_ARN_SECRET: ${{ secrets.AWS_ROLE_ARN_SECRET }}
ECR_REGISTRY_SECRET: ${{ secrets.ECR_REGISTRY_SECRET }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
partner-chain-ready:
if: ${{ github.event.inputs.no-tests != 'true' && (needs.deploy-staging-preview.result == 'success' || needs.deploy-staging-preview.result == 'skipped') }}
runs-on: eks
needs: deploy-staging-preview
outputs:
deployment_mc_epoch: ${{ steps.mc-epoch.outputs.deployment_mc_epoch }}
steps:
- name: Set deployment main chain epoch
id: mc-epoch
run: echo "deployment_mc_epoch=$(curl -s http://$STAGING_PREVIEW_SERVICES_HOST:1337/health | jq .currentEpoch)" >> $GITHUB_OUTPUT
shell: bash
- name: Check Finalization Status
run: |
FINALIZED_NUMBER=$(
curl -s -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getFinalizedHead","params":[],"id":"1"}' http://$STAGING_PREVIEW_VALIDATOR_1_HOST:$STAGING_PREVIEW_VALIDATOR_1_PORT |
jq -r ".result" |
xargs -I {} curl -s -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getHeader","params":["{}"],"id":"1"}' http://$STAGING_PREVIEW_VALIDATOR_1_HOST:$STAGING_PREVIEW_VALIDATOR_1_PORT |
jq -r ".result.number" | xargs printf "%d"
)
timeout=300 # Timeout in seconds
interval=10 # Interval in seconds
elapsed=0
while [ "$FINALIZED_NUMBER" -le 0 ]; do
if [ $elapsed -ge $timeout ]; then
echo "Timeout reached: $timeout seconds"
exit 1
fi
echo "Waiting for blocks to be finalized..."
sleep $interval
elapsed=$((elapsed + interval))
FINALIZED_NUMBER=$(
curl -s -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getFinalizedHead","params":[],"id":"1"}' http://$STAGING_PREVIEW_VALIDATOR_1_HOST:$STAGING_PREVIEW_VALIDATOR_1_PORT |
jq -r ".result" |
xargs -I {} curl -s -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"chain_getHeader","params":["{}"],"id":"1"}' http://$STAGING_PREVIEW_VALIDATOR_1_HOST:$STAGING_PREVIEW_VALIDATOR_1_PORT |
jq -r ".result.number" | xargs printf "%d"
)
done
echo "Blocks are being finalized. Finalized Block Number: $FINALIZED_NUMBER"
shell: bash
run-smoke-tests:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs: partner-chain-ready
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup tests
uses: ./.github/actions/tests/setup-python
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Run smoke tests
uses: ./.github/actions/tests/run-e2e-tests
with:
blockchain: substrate
env: staging
decrypt: true
markers: "not active_flow and not passive_flow and (CD or rpc)"
threads: 1
run-all-tests:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs: run-smoke-tests
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup tests
uses: ./.github/actions/tests/setup-python
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Run all tests (some skipped due to new deployment)
uses: ./.github/actions/tests/run-e2e-tests
env:
DEPLOYMENT_MC_EPOCH: ${{ needs.partner-chain-ready.outputs.deployment_mc_epoch }}
with:
blockchain: substrate
env: staging
decrypt: true
markers: "not active_flow and not passive_flow"
deployment_mc_epoch: $DEPLOYMENT_MC_EPOCH
threads: 1
wait-for-n1-epoch:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs: partner-chain-ready
runs-on: eks
timeout-minutes: 1440
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure kubectl
uses: ./.github/actions/tests/configure-kubectl
env:
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Set MC epoch to wait for
id: increment-epoch
env:
DEPLOYMENT_MC_EPOCH: ${{ needs.partner-chain-ready.outputs.deployment_mc_epoch }}
run: |
echo "Current epoch: $DEPLOYMENT_MC_EPOCH"
incremented_epoch=$((DEPLOYMENT_MC_EPOCH + 1))
echo "Incremented epoch: $incremented_epoch"
echo "mc_epoch_to_wait_for=$incremented_epoch" >> $GITHUB_OUTPUT
- name: Wait for next MC epoch
uses: ./.github/actions/tests/wait-for-epoch
with:
epoch: ${{ steps.increment-epoch.outputs.mc_epoch_to_wait_for }}
deployment: kubernetes
node: staging-preview-validator-1
environment: staging-preview
run-all-tests-on-n1-epoch:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs: wait-for-n1-epoch
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup tests
uses: ./.github/actions/tests/setup-python
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Run all tests (some skipped due to new deployment)
uses: ./.github/actions/tests/run-e2e-tests
env:
DEPLOYMENT_MC_EPOCH: ${{ needs.partner-chain-ready.outputs.deployment_mc_epoch }}
with:
blockchain: substrate
env: staging
decrypt: true
latest_mc_epoch: true
markers: "not active_flow and not passive_flow"
deployment_mc_epoch: $DEPLOYMENT_MC_EPOCH
threads: 1
wait-for-n2-epoch:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs:
- partner-chain-ready
- wait-for-n1-epoch
runs-on: eks
timeout-minutes: 1450
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure kubectl
uses: ./.github/actions/tests/configure-kubectl
env:
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Set MC epoch to wait for
id: increment-epoch
env:
DEPLOYMENT_MC_EPOCH: ${{ needs.partner-chain-ready.outputs.deployment_mc_epoch }}
run: |
echo "Current epoch: $DEPLOYMENT_MC_EPOCH"
incremented_epoch=$((DEPLOYMENT_MC_EPOCH + 2))
echo "Incremented epoch: $incremented_epoch"
echo "mc_epoch_to_wait_for=$incremented_epoch" >> $GITHUB_OUTPUT
- name: Wait for next MC epoch
uses: ./.github/actions/tests/wait-for-epoch
with:
epoch: ${{ steps.increment-epoch.outputs.mc_epoch_to_wait_for }}
deployment: kubernetes
node: staging-preview-validator-1
environment: staging-preview
run-all-tests-on-n2-epoch:
if: ${{ github.event.inputs.no-tests != 'true' }}
permissions:
id-token: write
contents: read
needs: wait-for-n2-epoch
runs-on: eks
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup tests
uses: ./.github/actions/tests/setup-python
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
K8S_SERVER: ${{ secrets.K8S_SERVER }}
K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
- name: Run all tests (no skipped tests)
uses: ./.github/actions/tests/run-e2e-tests
env:
DEPLOYMENT_MC_EPOCH: ${{ needs.partner-chain-ready.outputs.deployment_mc_epoch }}
with:
blockchain: substrate
env: staging
decrypt: true
latest_mc_epoch: true
markers: "not active_flow and not passive_flow"
deployment_mc_epoch: $DEPLOYMENT_MC_EPOCH
threads: 1
publish:
if: ${{ always() && github.event.inputs.no-release != 'true' && (github.event.inputs.no-tests == 'true' || needs.run-all-tests-on-n2-epoch.result == 'success') }}
permissions:
id-token: write
contents: write
packages: write
needs:
- build-linux
- build-macos-x86_64
- build-macos-arm64
- run-all-tests-on-n2-epoch
runs-on: ubuntu-latest
steps:
- name: Trigger Publish Workflow
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.ACTIONS_PUBLISH_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/publish.yml/dispatches \
-d '{"ref": "${{ github.ref_name }}", "inputs": {"sha": "${{ inputs.sha }}", "tag": "${{ inputs.tag }}"}}'
# deploy-staging-preprod:
# if: ${{ github.event.inputs.no-deploy != 'true' }}
# permissions:
# id-token: write
# contents: write
# needs: run-all-tests-on-n2-epoch
# runs-on: eks
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Deploy staging-preprod
# uses: ./.github/actions/deploy-staging-preprod
# with:
# image: ${{ secrets.ECR_REGISTRY_SECRET }}/substrate-node:${{ inputs.sha }}
# chain-spec-secret: ${{ inputs.chain-spec-secret }}
# env:
# AWS_REGION: "eu-central-1"
# SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
# AWS_ROLE_ARN_SECRET: ${{ secrets.AWS_ROLE_ARN_SECRET }}
# ECR_REGISTRY_SECRET: ${{ secrets.ECR_REGISTRY_SECRET }}
# kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
# K8S_SERVER: ${{ secrets.K8S_SERVER }}
# K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}
#
# staging-preprod-tests:
# if: ${{ github.event.inputs.no-tests != 'true' }}
# permissions:
# id-token: write
# contents: write
# needs: deploy-staging-preprod
# runs-on: eks
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Run Tests
# uses: ./.github/actions/tests/staging-preprod-tests
# with:
# node-host: staging-preprod-validator-1.staging-preprod.svc.cluster.local
# node-port: 9933
# env:
# SSH_AUTH_SOCK: /tmp/ssh_agent.sock
# AWS_ROLE_ARN_: ${{ secrets.AWS_ROLE_ARN_ }}
# SSH_KEY_BINARY_HOST: ${{ secrets.SSH_KEY_BINARY_HOST }}
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# JIRA_URL: ${{ secrets.JIRA_URL }}
# ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
# kubeconfig_base64: ${{ secrets.kubeconfig_base64 }}
# K8S_SERVER: ${{ secrets.K8S_SERVER }}
# K8S_SA_TOKEN: ${{ secrets.K8S_SA_TOKEN }}