-
Notifications
You must be signed in to change notification settings - Fork 12
486 lines (454 loc) · 18.3 KB
/
build.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
name: Build
on:
workflow_dispatch:
inputs:
ENVIRONMENT_NAME:
description: 'Environment Name'
required: true
default: Stokenet
type: choice
options:
- Stokenet
push:
branches:
- develop
- release/*
pull_request:
branches:
- develop
- release/**
release:
types: [published]
jobs:
snyk-scan-deps-licences:
runs-on: ubuntu-latest
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'radix-dapp-toolkit'
step_name: 'snyk-scan-deps-licenses'
secret_prefix: 'SNYK'
secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
- name: Run Snyk to check for deps vulnerabilities
uses: snyk/actions/node@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0
with:
args: --all-projects --org=${{ env.SNYK_PROJECTS_ORG_ID }} --severity-threshold=critical
snyk-scan-code:
runs-on: ubuntu-latest
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'radix-dapp-toolkit'
step_name: 'snyk-scan-code'
secret_prefix: 'SNYK'
secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
- name: Run Snyk to check for code vulnerabilities
uses: snyk/actions/node@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0
with:
args: --all-projects --org=${{ env.SNYK_PROJECTS_ORG_ID }} --severity-threshold=high
command: code test
snyk-sbom:
runs-on: ubuntu-latest
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
needs:
- snyk-scan-deps-licences
- snyk-scan-code
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'radix-dapp-toolkit'
step_name: 'snyk-sbom'
secret_prefix: 'SNYK'
secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
- name: Generate SBOM # check SBOM can be generated but nothing is done with it
uses: snyk/actions/node@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0
with:
args: --all-projects --org=${{ env.SNYK_PROJECTS_ORG_ID }} --format=cyclonedx1.4+json --json-file-output sbom.json
command: sbom
build:
runs-on: ubuntu-latest
needs:
- snyk-scan-deps-licences
- snyk-scan-code
outputs:
tag: ${{ steps.setup_tags.outputs.tag }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- name: Setup tags for docker image
id: setup_tags
run: echo "tag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Use Node.js
uses: actions/setup-node@7c29869aec4da703a571b27bcd84d4f15af0b56e
with:
node-version: '18.x'
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPMJS_TOKEN }}" > ~/.npmrc
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
- name: Build
run: npm run build
- name: Dump context
uses: crazy-max/ghaction-dump-context@v2
setup-build-args:
runs-on: ubuntu-latest
name: Setup build argument values for docker
outputs:
network: ${{ steps.network_name_step.outputs.network_name }}
is_public: ${{ steps.network_name_step.outputs.is_public }}
steps:
- name: Dump context
uses: crazy-max/ghaction-dump-context@v2
- name: Info
run: |
echo "This is triggered by: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
- name: Define network name
id: network_name_step
run: |
if [ "${{ github.event_name}}" = 'release' -a ${{!github.event.release.prerelease}} ]; then
echo "is_public=true" >> $GITHUB_OUTPUT
echo "network_name=Mainnet" >> $GITHUB_OUTPUT
elif [ ${{github.event_name }} = 'workflow_dispatch' -a "${{github.event.inputs.ENVIRONMENT_NAME}}" = 'Stokenet' ]; then
echo "is_public=true" >> $GITHUB_OUTPUT
echo "network_name=Stokenet" >> $GITHUB_OUTPUT
else
echo "is_public=false" >> $GITHUB_OUTPUT
echo "network_name=" >> $GITHUB_OUTPUT
fi
push-docker-image:
name: (PRIVATE) Docker AMD
needs:
- setup-build-args
- build
uses: radixdlt/public-iac-resuable-artifacts/.github/workflows/docker-build.yml@main
with:
runs_on: ubuntu-latest
image_registry: "docker.io"
image_organization: "radixdlt"
image_name: "private-radix-dapp-toolkit"
tag: ${{ needs.build.outputs.tag }}
tags: |
type=semver,pattern={{version}}
context: "./"
dockerfile: "./Dockerfile"
platforms: "linux/amd64"
scan_image: true
snyk_target_ref: ${{ github.ref_name }}
build-args: |
NETWORK_NAME=${{needs.setup-build-args.outputs.network}}
IS_PUBLIC=${{needs.setup-build-args.outputs.is_public}}
snyk-monitor:
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
needs:
- push-docker-image
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: radixdlt/public-iac-resuable-artifacts/fetch-secrets@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'radix-dapp-toolkit'
step_name: 'snyk-monitor'
secret_prefix: 'SNYK'
secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
- name: Enable Snyk online monitoring to check for vulnerabilities
uses: snyk/actions/node@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0
with:
args: --all-projects --org=${{ env.SNYK_PROJECTS_ORG_ID }} --target-reference=${{ github.ref_name }}
command: monitor
snyk-container-monitor:
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
needs:
- push-docker-image
permissions:
id-token: write
pull-requests: read
contents: read
deployments: write
steps:
- uses: radixdlt/public-iac-resuable-artifacts/snyk-container-monitor@main
with:
role_name: ${{ secrets.AWS_ROLE_NAME_SNYK_SECRET }}
app_name: 'radix-dapp-toolkit'
step_name: 'snyk-container-monitor'
dockerhub_secret_name: ${{ secrets.AWS_SECRET_NAME_DOCKERHUB }}
snyk_secret_name: ${{ secrets.AWS_SECRET_NAME_SNYK }}
parse_json: true
snyk_org_id: ${{ secrets.SNYK_ORG_ID }}
image: docker.io/radixdlt/private-radix-dapp-toolkit:${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
target_ref: ${{ github.ref_name }}
deploy-pr:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
needs:
- push-docker-image
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: unfor19/install-aws-cli-action@457b7980b125044247e455d87b9a26fc2299b787
with:
version: 2
- name: Setup helmfile and helm
uses: mamezou-tech/setup-helmfile@55ae2a66c5af4883148b7a50cc6ddc9b61042184
with:
helm-diff-plugin-version: 'v3.1.3'
helmfile-version: 'v0.144.0'
helm-version: 'v3.11.0'
install-kubectl: no
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 #v3.2
with:
version: 'v1.25.6'
- name: Configure AWS credentials for deployment
uses: aws-actions/configure-aws-credentials@bab55d3830fe69833c9fecaa51fe2c829a7508f3
with:
role-to-assume: ${{ secrets.DEPLOY_PR_IAM_ROLE }}
aws-region: eu-west-2
- name: Deploy application
working-directory: deploy/helm
run: |
cat <<DOC > namespace.yaml
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
name: radix-dapp-toolkit-pr-${{ github.event.number }}
namespace: radix-dapp-toolkit-ci-pr
DOC
aws eks update-kubeconfig --name ${{ secrets.CLUSTER_NAME }} \
--alias ${{ secrets.CLUSTER_NAME }} \
--region eu-west-2
kubectl apply -f namespace.yaml
helmfile --environment pr --namespace radix-dapp-toolkit-pr-${{ github.event.number }} \
--state-values-set "ci.tag=${{ env.CI_TAG }}" \
--state-values-set "ci.ingressDomain=${{ env.INGRESS_DOMAIN }}" \
apply
env:
CI_TAG: ${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
INGRESS_DOMAIN: radix-dapp-toolkit-pr-${{ github.event.number}}.${{ secrets.INGRESS_DOMAIN }}
HELM_GH_USER: ${{ secrets.HELM_GH_USER }}
HELM_GH_PASS: ${{ secrets.HELM_GH_PASS }}
deploy-dev:
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- push-docker-image
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: unfor19/install-aws-cli-action@457b7980b125044247e455d87b9a26fc2299b787
with:
version: 2
- name: Setup helmfile and helm
uses: mamezou-tech/setup-helmfile@55ae2a66c5af4883148b7a50cc6ddc9b61042184
with:
helm-diff-plugin-version: 'v3.1.3'
helmfile-version: 'v0.144.0'
helm-version: 'v3.11.0'
install-kubectl: no
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 #v3.2
with:
version: 'v1.25.6'
- name: Configure AWS credentials for deployment
uses: aws-actions/configure-aws-credentials@bab55d3830fe69833c9fecaa51fe2c829a7508f3
with:
role-to-assume: ${{ secrets.DEPLOY_DEV_IAM_ROLE }}
aws-region: eu-west-2
- name: Deploy application
working-directory: deploy/helm
run: |
aws eks update-kubeconfig --name ${{ secrets.CLUSTER_NAME }} \
--alias ${{ secrets.CLUSTER_NAME }} \
--region eu-west-2
helmfile --environment dev --namespace radix-dapp-toolkit-dev \
--state-values-set "ci.tag=${{ env.CI_TAG }}" \
--state-values-set "ci.ingressDomain=${{ env.INGRESS_DOMAIN }}" \
apply
env:
CI_TAG: ${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
INGRESS_DOMAIN: radix-dapp-toolkit-dev.${{ secrets.INGRESS_DOMAIN }}
HELM_GH_USER: ${{ secrets.HELM_GH_USER }}
HELM_GH_PASS: ${{ secrets.HELM_GH_PASS }}
deploy-release:
if: startsWith(github.ref_name,'release/')
runs-on: ubuntu-latest
needs:
- push-docker-image
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: unfor19/install-aws-cli-action@457b7980b125044247e455d87b9a26fc2299b787
with:
version: 2
- name: Setup helmfile and helm
uses: mamezou-tech/setup-helmfile@55ae2a66c5af4883148b7a50cc6ddc9b61042184
with:
helm-diff-plugin-version: 'v3.1.3'
helmfile-version: 'v0.144.0'
helm-version: 'v3.11.0'
install-kubectl: no
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 #v3.2
with:
version: 'v1.25.6'
- name: Configure AWS credentials for deployment
uses: aws-actions/configure-aws-credentials@bab55d3830fe69833c9fecaa51fe2c829a7508f3
with:
role-to-assume: ${{ secrets.DEPLOY_RELEASES_IAM_ROLE }}
aws-region: eu-west-2
- name: Deploy application
working-directory: deploy/helm
run: |
aws eks update-kubeconfig --name ${{ secrets.CLUSTER_NAME }} \
--alias ${{ secrets.CLUSTER_NAME }} \
--region eu-west-2
BRANCH_NAME=${{ github.ref_name }}
NORMALIZED_BRANCH_NAME=${BRANCH_NAME/\//-}
cat <<DOC > subns-manifest.yaml
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
name: radix-dapp-toolkit-$NORMALIZED_BRANCH_NAME
namespace: radix-dapp-toolkit-ci-releases
DOC
kubectl apply -f subns-manifest.yaml
helmfile --environment dev --namespace radix-dapp-toolkit-$NORMALIZED_BRANCH_NAME \
--state-values-set "ci.tag=${{ env.CI_TAG }}" \
--state-values-set "ci.ingressDomain=radix-dapp-toolkit-${NORMALIZED_BRANCH_NAME}.${{ env.INGRESS_DOMAIN }}" \
apply
env:
CI_TAG: ${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
INGRESS_DOMAIN: ${{ secrets.INGRESS_DOMAIN }}
HELM_GH_USER: ${{ secrets.HELM_GH_USER }}
HELM_GH_PASS: ${{ secrets.HELM_GH_PASS }}
deploy-stokenet:
if: ( github.event.inputs.ENVIRONMENT_NAME == 'Stokenet' && github.event_name == 'workflow_dispatch' )
runs-on: ubuntu-latest
environment: stokenet
needs:
- push-docker-image
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: unfor19/install-aws-cli-action@457b7980b125044247e455d87b9a26fc2299b787
with:
version: 2
- name: Setup helmfile and helm
uses: mamezou-tech/setup-helmfile@55ae2a66c5af4883148b7a50cc6ddc9b61042184
with:
helm-diff-plugin-version: 'v3.1.3'
helmfile-version: 'v0.144.0'
helm-version: 'v3.11.0'
install-kubectl: no
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 #v3.2
with:
version: 'v1.25.6'
- name: Configure AWS credentials for deployment
uses: aws-actions/configure-aws-credentials@bab55d3830fe69833c9fecaa51fe2c829a7508f3
with:
role-to-assume: ${{ secrets.DEPLOY_STOKENET_IAM_ROLE }}
aws-region: eu-west-2
- name: Deploy application
working-directory: deploy/helm
run: |
aws eks update-kubeconfig --name ${{ secrets.STOKENET_CLUSTER_NAME }} \
--alias ${{ secrets.STOKENET_CLUSTER_NAME }} \
--region eu-west-2
helmfile --environment stokenet --namespace radix-dapp-toolkit-stokenet \
--state-values-set "ci.tag=${{ env.CI_TAG }}" \
--state-values-set "ci.ingressDomain=${{ env.INGRESS_DOMAIN }}" \
apply
env:
CI_TAG: ${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
INGRESS_DOMAIN: ${{ secrets.STOKENET_INGRESS_DOMAIN }}
HELM_GH_USER: ${{ secrets.HELM_GH_USER }}
HELM_GH_PASS: ${{ secrets.HELM_GH_PASS }}
deploy-mainnet:
if: github.event_name == 'release' && !github.event.release.prerelease
runs-on: ubuntu-latest
needs:
- push-docker-image
permissions:
id-token: write
contents: read
pull-requests: read
steps:
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
- uses: unfor19/install-aws-cli-action@457b7980b125044247e455d87b9a26fc2299b787
with:
version: 2
- name: Setup helmfile and helm
uses: mamezou-tech/setup-helmfile@55ae2a66c5af4883148b7a50cc6ddc9b61042184
with:
helm-diff-plugin-version: 'v3.1.3'
helmfile-version: 'v0.144.0'
helm-version: 'v3.11.0'
install-kubectl: no
- name: Install kubectl
uses: azure/setup-kubectl@901a10e89ea615cf61f57ac05cecdf23e7de06d8 #v3.2
with:
version: 'v1.25.6'
- name: Configure AWS credentials for deployment
uses: aws-actions/configure-aws-credentials@bab55d3830fe69833c9fecaa51fe2c829a7508f3
with:
role-to-assume: ${{ secrets.DEPLOY_MAINNET_IAM_ROLE }}
aws-region: eu-west-2
- name: Deploy application
working-directory: deploy/helm
run: |
aws eks update-kubeconfig --name ${{ secrets.MAINNET_CLUSTER_NAME }} \
--alias ${{ secrets.MAINNET_CLUSTER_NAME }} \
--region eu-west-2
helmfile --environment mainnet --namespace radix-dapp-toolkit-mainnet \
--state-values-set "ci.tag=${{ env.CI_TAG }}" \
--state-values-set "ci.ingressDomain=${{ env.INGRESS_DOMAIN }}" \
apply
env:
CI_TAG: ${{ fromJSON(needs.push-docker-image.outputs.json).labels['org.opencontainers.image.version'] }}
INGRESS_DOMAIN: ${{ secrets.MAINNET_INGRESS_DOMAIN }}
HELM_GH_USER: ${{ secrets.HELM_GH_USER }}
HELM_GH_PASS: ${{ secrets.HELM_GH_PASS }}