-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaction.yml
513 lines (469 loc) · 19.5 KB
/
action.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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
name: SAFE Network Testnet Workflow Action
description: GitHub action to use the sn-testnet-deploy repository to deploy a testnet
inputs:
action:
description: >
Task to be carried out.
Accepts 'create', 'destroy', 'resources', 'logs', 'list-inventory', 'print-inventory', 'upscale'.
required: true
ansible-forks:
description: The number of forks to use with Ansible
ansible-vault-password:
description: Password for Ansible vault.
required: true
ansible-verbose:
description: Set to use verbose output for Ansible
required: true
default: false
aws-access-key-id:
description: AWS access key ID
aws-access-key-secret:
description: AWS access key
aws-region:
description: AWS region
default: eu-west-2
beta-encryption-key:
description: Supply an encryption key that will be used with the auditor.
bootstrap-node-count:
description: Number of node services to run on each bootstrap node VM
bootstrap-node-vm-count:
description: Number of bootstrap node VMs to be deployed
do-token:
description: Digital Ocean Authorization token
required: true
environment-type:
description: >
Possible values are 'development', 'staging' and 'production'. This value determines the sizes
and counts of VMs. The counts can be overridden with the other count inputs.
required: true
faucet-version:
description: Supply a version for the faucet. Otherwise the latest will be used.
log-format:
description: Set the log format for the nodes, can be 'json' or 'default'. Defaults to 'default' if not set.
network-contacts-file-name:
description: Provide a name for the network contacts file
node-count:
description: Number of node services to run on each node VM
node-vm-count:
description: Number of node VMs to be deployed
public-rpc:
description: Set to make node manager RPC daemons publicly accessible
required: true
default: false
protocol-version:
description: The network protocol version can be set to 'restricted' or any custom version string.
provider:
description: The cloud provider. Accepts 'aws' or 'digital-ocean'.
required: true
re-attempts:
description: The number of times to re-run testnet-deploy in case of failures.
default: "0"
rust-log:
description: Set RUST_LOG to this value for testnet-deploy
required: false
safenode-features:
description: Comma-separated list of features to be used when building a branch of safenode
safe-version:
description: Supply a version for safe. Otherwise the latest will be used.
safenode-version:
description: Supply a version for safenode. Otherwise the latest will be used.
safenode-manager-version:
description: Supply a version for safenode-manager. Otherwise the latest will be used.
safe-network-branch:
description: >
Build binaries from the specified safe_network branch. The testnet will use these binaries.
safe-network-user:
description: >
Build binaries from the safe_network repository owned by this org or username. The testnet
will use these binaries.
sn-auditor-version:
description: Supply a version for the sn-auditor. Otherwise the latest will be used.
ssh-secret-key:
description: SSH key used to run the nodes on the Digital Ocean droplets
subnet-id:
description: If running on AWS, this is the subnet of the VPC on which the VMs will be created.
security-group-id:
description: If running on AWS, this is the ID of the security groups the VMs will use.
testnet-name:
description: The name of the testnet.
required: true
testnet-deploy-branch:
description: >
The branch for the sn-testnet-deploy repository. Enables using forks to test changes for
testnet-deploy.
default: main
testnet-deploy-user:
description: >
The user or organisation for the sn-testnet-deploy repository. Enables using forks to test
changes for testnet-deploy.
default: maidsafe
uploader-vm-count:
description: Number of uploader VMs to be deployed
runs:
using: composite
steps:
#
# ====== Prerequisites ======
#
- uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false
- name: Install tools
shell: bash
run: |
sudo apt-get update -y
# There is some issue with the latest version of Ansible not correctly
# reading the Digital Ocean token from environment variables, so just
# pin to this version for now.
pip install --user ansible==8.2.0
pip install --user boto3
sudo apt-get install jq -y
- name: Install tools
if: inputs.action == 'logs'
shell: bash
run: |
sudo apt-get update -y
sudo apt-get install rsync -y
- name: Clone the deployer and setup prerequisite files
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ inputs.aws-access-key-id }}
AWS_DEFAULT_REGION: ${{ inputs.aws-region }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws-access-key-secret }}
DO_PAT: ${{ inputs.do-token }}
SAFE_NETWORK_BRANCH: ${{ inputs.safe-network-branch }}
SAFE_NETWORK_USER: ${{ inputs.safe-network-user }}
SN_TESTNET_DEV_SECURITY_GROUP_ID: ${{ inputs.security-group-id }}
SN_TESTNET_DEV_SUBNET_ID: ${{ inputs.subnet-id }}
TERRAFORM_STATE_BUCKET_NAME: maidsafe-org-infra-tfstate
TESTNET_DEPLOY_BRANCH: ${{ inputs.testnet-deploy-branch }}
TESTNET_DEPLOY_USER: ${{ inputs.testnet-deploy-user }}
run: |
set -e
# This action might be called from inside another repo (after checking
# out). Thus we should clone the deployer inside home.
cd ~
echo "ORIGINAL_DIR=$(pwd)" >> $GITHUB_ENV
# This step can be be called multiple times during the same workflow. Hence we have to check
# if the file/folder exists before we can create them.
if [ ! -d "sn-testnet-deploy" ]; then
git clone --quiet --single-branch --depth 1 \
--branch $TESTNET_DEPLOY_BRANCH https://github.com/$TESTNET_DEPLOY_USER/sn-testnet-deploy
fi
if [ ! -f ~/.ssh/id_rsa ]; then
mkdir ~/.ssh
echo "${{ inputs.ssh-secret-key }}" >> ~/.ssh/id_rsa
chmod 0400 ~/.ssh/id_rsa
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
fi
if [ ! -f ~/.ansible/vault-password ]; then
mkdir ~/.ansible
echo "${{ inputs.ansible-vault-password }}" >> ~/.ansible/vault-password
fi
cd sn-testnet-deploy
if [ ! -f ".env" ]; then
echo "ANSIBLE_VAULT_PASSWORD_PATH=/home/runner/.ansible/vault-password" >> .env
echo "AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }}" >> .env
echo "AWS_DEFAULT_REGION=${{ env.AWS_DEFAULT_REGION }}" >> .env
echo "AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }}" >> .env
echo "DO_PAT=${{ env.DO_PAT }}" >> .env
echo "SSH_KEY_PATH=/home/runner/.ssh/id_rsa" >> .env
echo "SN_TESTNET_DEV_SUBNET_ID=${{ env.SN_TESTNET_DEV_SUBNET_ID }}" >> .env
echo "SN_TESTNET_DEV_SECURITY_GROUP_ID=${{ env.SN_TESTNET_DEV_SECURITY_GROUP_ID }}" >> .env
echo "TERRAFORM_STATE_BUCKET_NAME=${{ env.TERRAFORM_STATE_BUCKET_NAME }}" >> .env
fi
#
# ====== Create Testnet ======
#
- name: Create testnet
if: inputs.action == 'create'
env:
ANSIBLE_FORKS: ${{ inputs.ansible-forks }}
ANSIBLE_VERBOSE: ${{ inputs.ansible-verbose }}
AWS_DEFAULT_REGION: ${{ inputs.aws-region }}
BETA_ENCRYPTION_KEY: ${{ inputs.beta-encryption-key }}
BOOTSTRAP_NODE_COUNT: ${{ inputs.bootstrap-node-count }}
BOOTSTRAP_NODE_VM_COUNT: ${{ inputs.bootstrap-node-vm-count }}
ENVIRONMENT_TYPE: ${{ inputs.environment-type }}
FAUCET_VERSION: ${{ inputs.faucet-version }}
LOG_FORMAT: ${{ inputs.log-format }}
NETWORK_CONTACTS_FILE_NAME: ${{ inputs.network-contacts-file-name }}
NODE_COUNT: ${{ inputs.node-count }}
NODE_VM_COUNT: ${{ inputs.node-vm-count }}
PROTOCOL_VERSION: ${{ inputs.protocol-version }}
PROVIDER: ${{ inputs.provider }}
PUBLIC_RPC: ${{ inputs.public-rpc }}
RETRY_ATTEMPTS: ${{ inputs.re-attempts }}
RUST_LOG: ${{ inputs.rust-log }}
SAFENODE_FEATURES: ${{ inputs.safenode-features }}
SAFE_VERSION: ${{ inputs.safe-version }}
SAFENODE_VERSION: ${{ inputs.safenode-version }}
SAFENODE_MANAGER_VERSION: ${{ inputs.safenode-manager-version }}
SAFE_NETWORK_BRANCH: ${{ inputs.safe-network-branch }}
SAFE_NETWORK_USER: ${{ inputs.safe-network-user }}
SN_AUDITOR_VERSION: ${{ inputs.sn-auditor-version }}
TESTNET_NAME: ${{ inputs.testnet-name }}
UPLOADER_VM_COUNT: ${{ inputs.uploader-vm-count }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
command="cargo run -- deploy \
--name $TESTNET_NAME \
--environment-type $ENVIRONMENT_TYPE \
--provider $PROVIDER "
[[ -n $ANSIBLE_FORKS ]] && command="$command --forks $ANSIBLE_FORKS "
[[ $ANSIBLE_VERBOSE == "true" ]] && command="$command --ansible-verbose "
[[ -n $BETA_ENCRYPTION_KEY ]] && command="$command --beta-encryption-key $BETA_ENCRYPTION_KEY "
[[ -n $BOOTSTRAP_NODE_COUNT ]] && command="$command --bootstrap-node-count $BOOTSTRAP_NODE_COUNT "
[[ -n $BOOTSTRAP_NODE_VM_COUNT ]] && command="$command --bootstrap-node-vm-count $BOOTSTRAP_NODE_VM_COUNT "
[[ -n $FAUCET_VERSION ]] && command="$command --faucet-version $FAUCET_VERSION "
[[ -n $LOG_FORMAT ]] && command="$command --log-format $LOG_FORMAT "
[[ -n $NETWORK_CONTACTS_FILE_NAME ]] && command="$command --network-contacts-file-name $NETWORK_CONTACTS_FILE_NAME "
[[ -n $NODE_COUNT ]] && command="$command --node-count $NODE_COUNT "
[[ -n $NODE_VM_COUNT ]] && command="$command --node-vm-count $NODE_VM_COUNT "
[[ -n $PROTOCOL_VERSION ]] && command="$command --protocol-version $PROTOCOL_VERSION "
[[ $PUBLIC_RPC == "true" ]] && command="$command --public-rpc "
[[ -n $SAFENODE_FEATURES ]] && command="$command --safenode-features $SAFENODE_FEATURES "
[[ -n $SAFE_VERSION ]] && command="$command --safe-version $SAFE_VERSION "
[[ -n $SAFENODE_VERSION ]] && command="$command --safenode-version $SAFENODE_VERSION "
[[ -n $SAFENODE_MANAGER_VERSION ]] && command="$command --safenode-manager-version $SAFENODE_MANAGER_VERSION "
[[ -n $SN_AUDITOR_VERSION ]] && command="$command --sn-auditor-version $SN_AUDITOR_VERSION "
[[ -n $SAFE_NETWORK_BRANCH ]] && command="$command --branch $SAFE_NETWORK_BRANCH "
[[ -n $SAFE_NETWORK_USER ]] && command="$command --repo-owner $SAFE_NETWORK_USER "
[[ -n $UPLOADER_VM_COUNT ]] && command="$command --uploader-vm-count $UPLOADER_VM_COUNT "
max_attempts=$((RETRY_ATTEMPTS + 1)) # +1 as default retry_attempts is 0
for i in $(seq 1 $max_attempts); do
echo "Attempt $i of $max_attempts"
set +e # Temporarily turn off 'exit on error'
echo "Will run testnet-deploy with: $command"
eval $command
result=$?
set -e # Re-enable 'exit on error'
if [[ $result -eq 0 ]]; then
echo "Testnet tool completed successfully."
break
else
echo "Attempt $i of testnet tool failed. Retrying..."
fi
done
if [[ $result -ne 0 ]]; then
echo "Testnet creation failed"
exit 1
fi
- name: Upload the inventory file
if: inputs.action == 'create'
uses: actions/upload-artifact@main
with:
name: wan_testnet_deployment_inventory_${{ inputs.testnet-name }}
path: ~/.local/share/safe/testnet-deploy
- name: Set SAFE_PEERS and SN_INVENTORY (Linux)
if: inputs.action == 'create'
shell: bash
run: |
inventory_path=/home/runner/.local/share/safe/testnet-deploy/"${{ inputs.testnet-name }}"-inventory.json
echo "Inventory Path: $inventory_path"
genesis_multiaddr=$(jq -r '.genesis_multiaddr' $inventory_path)
echo "SAFE_PEERS=$genesis_multiaddr" >> $GITHUB_ENV
echo "SN_INVENTORY=$inventory_path" >> $GITHUB_ENV
#
# ====== Destroy Testnet ======
#
- name: Destroy testnet
if: inputs.action == 'destroy'
env:
AWS_DEFAULT_REGION: ${{ inputs.aws-region }}
PROVIDER: ${{ inputs.provider }}
RETRY_ATTEMPTS: ${{ inputs.re-attempts }}
RUST_LOG: ${{ inputs.rust-log }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
max_attempts=$((RETRY_ATTEMPTS + 1))
for i in $(seq 1 $max_attempts); do
echo "Attempt $i of $max_attempts"
set +e # Temporarily turn off 'exit on error'
cargo run -- clean --name "$TESTNET_NAME" --provider "$PROVIDER"
result=$?
set -e # Re-enable 'exit on error'
if [[ $result -eq 0 ]]; then
echo "Testnet tool completed successfully."
break
else
echo "Attempt $i of testnet tool failed. Retrying..."
fi
done
if [[ $result -ne 0 ]]; then
echo "Destroying the testnet failed"
exit 1
fi
#
# ====== Get resources ======
#
- name: Get resources
if: inputs.action == 'resources'
env:
PROVIDER: ${{ inputs.provider }}
RUST_LOG: ${{ inputs.rust-log }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
max_attempts=$((RETRY_ATTEMPTS + 1))
for i in $(seq 1 $max_attempts); do
echo "Attempt $i of $max_attempts"
set +e # Temporarily turn off 'exit on error'
cargo run -- logs rsync --name "$TESTNET_NAME" --provider "$PROVIDER" --resources-only
result=$?
set -e # Re-enable 'exit on error'
if [[ $result -eq 0 ]]; then
echo "Testnet tool completed successfully."
break
else
echo "Attempt $i of testnet tool failed. Retrying..."
fi
done
if [[ $result -ne 0 ]]; then
echo "Get resources failed"
exit 1
fi
- name: Upload the resources
if: inputs.action == 'resources'
uses: actions/upload-artifact@main
with:
name: wan_testnet_resources_${{ inputs.testnet-name }}
path: ~/sn-testnet-deploy/logs/${{ inputs.testnet-name }}
#
# ====== Rsync logs ======
#
- name: Rsync logs
if: inputs.action == 'logs'
env:
PROVIDER: ${{ inputs.provider }}
RETRY_ATTEMPTS: ${{ inputs.re-attempts }}
RUST_LOG: ${{ inputs.rust-log }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
max_attempts=$((RETRY_ATTEMPTS + 1))
for i in $(seq 1 $max_attempts); do
echo "Attempt $i of $max_attempts"
set +e # Temporarily turn off 'exit on error'
cargo run -- logs rsync --name "$TESTNET_NAME" --provider "$PROVIDER"
result=$?
set -e # Re-enable 'exit on error'
if [[ $result -eq 0 ]]; then
echo "Testnet tool completed successfully."
break
else
echo "Attempt $i of testnet tool failed. Retrying..."
fi
done
if [[ $result -ne 0 ]]; then
echo "All attempts to run testnet tool failed!!"
exit 1
fi
- name: Upload the logs
if: inputs.action == 'logs'
uses: actions/upload-artifact@main
with:
name: wan_testnet_logs_${{ inputs.testnet-name }}
path: ~/sn-testnet-deploy/logs/${{ inputs.testnet-name }}
#
# ====== Fetch inventory ======
#
- name: Fetch inventory
if: inputs.action == 'list-inventory'
env:
PROVIDER: ${{ inputs.provider }}
RETRY_ATTEMPTS: ${{ inputs.re-attempts }}
RUST_LOG: ${{ inputs.rust-log }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
max_attempts=$((RETRY_ATTEMPTS + 1))
for i in $(seq 1 $max_attempts); do
echo "Attempt $i of $max_attempts"
set +e # Temporarily turn off 'exit on error'
cargo run -- inventory --name "$TESTNET_NAME" --provider "$PROVIDER"
result=$?
set -e # Re-enable 'exit on error'
if [[ $result -eq 0 ]]; then
echo "Testnet tool completed successfully."
break
else
echo "Attempt $i of testnet tool failed. Retrying..."
fi
done
if [[ $result -ne 0 ]]; then
echo "All attempts to run testnet tool failed!!"
exit 1
fi
- name: Upload the inventory file
if: inputs.action == 'inventory'
uses: actions/upload-artifact@main
with:
name: wan_testnet_deployment_inventory_${{ inputs.testnet-name }}
path: ~/.local/share/safe/testnet-deploy
# We don't want the action to change dirs on its own
- name: Change PWD back to the original DIR
shell: bash
run: |
cd "$ORIGINAL_DIR"
#
# ====== Print inventory ======
#
- name: Print inventory
if: inputs.action == 'print-inventory'
env:
PROVIDER: ${{ inputs.provider }}
NETWORK_CONTACTS_FILE_NAME: ${{ inputs.network-contacts-file-name }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
cd ~/sn-testnet-deploy
command="cargo run -- inventory --name $TESTNET_NAME --force-regeneration"
[[ -n $NETWORK_CONTACTS_FILE_NAME ]] && command="$command --network-contacts-file-name $NETWORK_CONTACTS_FILE_NAME"
eval $command
#
# ====== Upscale ======
#
- name: Upscale network
if: inputs.action == 'upscale'
env:
AWS_DEFAULT_REGION: ${{ inputs.aws-region }}
DESIRED_BOOTSTRAP_NODE_COUNT: ${{ inputs.bootstrap-node-count }}
DESIRED_BOOTSTRAP_NODE_VM_COUNT: ${{ inputs.bootstrap-node-vm-count }}
DESIRED_NODE_COUNT: ${{ inputs.node-count }}
DESIRED_NODE_VM_COUNT: ${{ inputs.node-vm-count }}
DESIRED_UPLOADER_VM_COUNT: ${{ inputs.uploader-vm-count }}
PROVIDER: ${{ inputs.provider }}
PUBLIC_RPC: ${{ inputs.public-rpc }}
RUST_LOG: ${{ inputs.rust-log }}
SAFE_NETWORK_BRANCH: ${{ inputs.safe-network-branch }}
SAFE_NETWORK_USER: ${{ inputs.safe-network-user }}
TESTNET_NAME: ${{ inputs.testnet-name }}
shell: bash
run: |
set -e
cd ~/sn-testnet-deploy
command="cargo run -- upscale \
--name $TESTNET_NAME \
--provider $PROVIDER "
[[ -n $DESIRED_BOOTSTRAP_NODE_COUNT ]] && command="$command --desired-bootstrap-node-count $DESIRED_BOOTSTRAP_NODE_COUNT "
[[ -n $DESIRED_BOOTSTRAP_NODE_VM_COUNT ]] && command="$command --desired-bootstrap-node-vm-count $DESIRED_BOOTSTRAP_NODE_VM_COUNT "
[[ -n $DESIRED_NODE_COUNT ]] && command="$command --desired-node-count $DESIRED_NODE_COUNT "
[[ -n $DESIRED_NODE_VM_COUNT ]] && command="$command --desired-node-vm-count $DESIRED_NODE_VM_COUNT "
[[ -n $DESIRED_UPLOADER_VM_COUNT ]] && command="$command --desired-uploader-vm-count $DESIRED_UPLOADER_VM_COUNT "
[[ $PUBLIC_RPC == "true" ]] && command="$command --public-rpc "
eval $command
branding:
icon: "globe"
color: "blue"