-
Notifications
You must be signed in to change notification settings - Fork 534
291 lines (269 loc) · 13.2 KB
/
deploy.nightly.devnet.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
---
name: Build Devnet
on: # yamllint disable-line rule:truthy
workflow_dispatch:
inputs:
environment:
description: The environment to run against
required: false
type: environment
duration:
default: "10m"
description: Duration of the test
required: false
type: string
workflow_call:
inputs:
environment:
description: The environment to run against
type: string
required: true
duration:
default: "10m"
description: Duration of the test
required: false
type: string
outputs:
workflow_output_loadtest1:
description: "Loadtest output"
value: ${{ jobs.loadtest1.outputs.workflow_output }}
workflow_output_loadtest2:
description: "Loadtest output"
value: ${{ jobs.loadtest2.outputs.workflow_output }}
secrets:
AWS_ROLE_ARN:
required: true
AWS_REGION:
required: true
TF_VAR_DEPLOYMENT_NAME:
required: true
TF_VAR_OWNER:
required: true
TF_VAR_BASE_INSTANCE_TYPE:
required: true
SLACK_PERFORMANCE_WEBHOOK_URL:
required: true
DD_API_KEY:
required: true
LOADTEST_MNEMONIC:
required: true
VAULT_PASSWORD_FILE:
required: true
jobs:
build:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
repository: maticnetwork/terraform-polygon-supernets
ref: main
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Install Terraform
uses: hashicorp/setup-terraform@v2.0.3
with:
terraform_version: 1.4.5
- name: Configure terraform for nightly build
run: |
sed 's/# backend "s3" {}/backend "s3" {}/' main.tf > main.tf.tmp && mv main.tf.tmp main.tf
- name: Terraform Init
id: init
run: terraform init -backend-config="bucket=polygon-edge-devnet-terraform-states" -backend-config="key=state/${{ secrets.TF_VAR_DEPLOYMENT_NAME }}" -backend-config="region=${{ secrets.AWS_REGION }}"
- name: Terraform Validate
id: validate
run: terraform validate -no-color
continue-on-error: true
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve
env:
TF_VAR_deployment_name: ${{ secrets.TF_VAR_DEPLOYMENT_NAME }}
TF_VAR_owner: ${{ secrets.TF_VAR_OWNER }}
TF_VAR_base_instance_type: ${{ secrets.TF_VAR_BASE_INSTANCE_TYPE }}
- name: Retrieve state file from s3
run: aws s3 cp s3://polygon-edge-devnet-terraform-states/state/${{ secrets.TF_VAR_DEPLOYMENT_NAME }} state.json
- name: Configure private keys
run: |
terraform output pk_ansible > ~/devnet_private.key
chmod 600 ~/devnet_private.key
eval "$(ssh-agent)"
ssh-add ~/devnet_private.key
- name: Install ansible / botocore / boto3
run: |
python3 -m pip install --user ansible
python3 -m pip install boto3 botocore
- name: Configure ansible for nightly build
working-directory: ansible
run: |
echo "${{ secrets.VAULT_PASSWORD_FILE }}" > password.txt
sed 's/devnet13/${{ secrets.TF_VAR_DEPLOYMENT_NAME }}/g' inventory/aws_ec2.yml > inventory/aws_ec2.yml.tmp && mv inventory/aws_ec2.yml.tmp inventory/aws_ec2.yml
sed 's/devnet13/${{ secrets.TF_VAR_DEPLOYMENT_NAME }}/g' group_vars/all.yml > group_vars/all.yml.tmp && mv group_vars/all.yml.tmp group_vars/all.yml
sed 's/edge_tag: .*/edge_tag: HEAD/g' group_vars/all.yml > group_vars/all.yml.tmp && mv group_vars/all.yml.tmp group_vars/all.yml
- name: Create script file
working-directory: ansible
run: |
cat > roles/edge/templates/bootstrap.sh <<'EOF'
#!/bin/bash -x
main() {
mkdir /var/lib/bootstrap
pushd /var/lib/bootstrap
{% for item in hostvars %}
{% if (hostvars[item].tags.Role == "fullnode" or hostvars[item].tags.Role == "validator") %}
polygon-edge polybft-secrets --data-dir {{ hostvars[item].tags["Name"] }} --json --insecure > {{ hostvars[item].tags["Name"] }}.json
{% endif %}
{% endfor %}
BURN_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000
PROXY_CONTRACTS_ADMIN=0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed
polygon-edge genesis \
--consensus polybft \
{% for item in hostvars %}{% if (hostvars[item].tags.Role == "fullnode" or hostvars[item].tags.Role == "validator") %} --bootnode /dns4/{{ hostvars[item].tags["Name"] }}/tcp/{{ edge_p2p_port }}/p2p/$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].node_id') {% endif %}{% endfor %} \
{% for item in hostvars %}{% if (hostvars[item].tags.Role == "fullnode" or hostvars[item].tags.Role == "validator") %} --premine $(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].address'):1000000000000000000000000 {% endif %}{% endfor %} \
--premine {{ loadtest_account }}:1000000000000000000000000000 \
--premine $BURN_CONTRACT_ADDRESS \
--reward-wallet 0x0101010101010101010101010101010101010101:1000000000000000000000000000 \
--premine 0xA39Fed214820cF843E2Bcd6cA1759257a530894B:1000000000000000000000000000 \
--premine 0x181d9fEc79EC674DD3cB30dd9dd4188E737939FE:1000000000000000000000000000 \
--premine 0x1AB8C3df809b85012a009c0264eb92dB04eD6EFa:1000000000000000000000000000 \
--block-gas-limit {{ block_gas_limit }} \
--block-time {{ block_time }}s \
{% for item in hostvars %}{% if (hostvars[item].tags.Role == "validator") %} --validators /dns4/{{ hostvars[item].tags["Name"] }}/tcp/{{ edge_p2p_port }}/p2p/$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].node_id'):$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].address' | sed 's/^0x//'):$(cat {{ hostvars[item].tags["Name"] }}.json | jq -r '.[0].bls_pubkey') {% endif %}{% endfor %} \
--epoch-size 10 \
--native-token-config MyToken:MTK:18:true:{{ loadtest_account }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN
polygon-edge polybft stake-manager-deploy \
--jsonrpc {{ rootchain_json_rpc }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN \
--test
polygon-edge rootchain deploy \
--stake-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr') \
--stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr') \
--json-rpc {{ rootchain_json_rpc }} \
--proxy-contracts-admin $PROXY_CONTRACTS_ADMIN \
--test
polygon-edge rootchain fund \
--stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr') \
--mint \
--addresses $(cat validator-*.json | jq -r ".[].address" | paste -sd "," - | tr -d '\n') \
--amounts $(for f in validator-*.json; do echo -n "1000000000000000000000000,"; done | sed 's/,$//') \
--json-rpc {{ rootchain_json_rpc }}
polygon-edge polybft whitelist-validators \
--private-key aa75e9a7d427efc732f8e4f1a5b7646adcc61fd5bae40f80d13c8419c9f43d6d \
--addresses $(cat validator-*.json | jq -r ".[].address" | paste -sd "," - | tr -d '\n') \
--supernet-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.customSupernetManagerAddr') \
--jsonrpc {{ rootchain_json_rpc }}
counter=1
{% for item in hostvars %}
{% if (hostvars[item].tags.Role == "validator") %}
echo "Registering validator: ${counter}"
polygon-edge polybft register-validator \
--data-dir {{ hostvars[item].tags["Name"] }} \
--supernet-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.customSupernetManagerAddr') \
--jsonrpc {{ rootchain_json_rpc }}
polygon-edge polybft stake \
--data-dir {{ hostvars[item].tags["Name"] }} \
--amount 1000000000000000000000000 \
--supernet-id $(cat genesis.json | jq -r '.params.engine.polybft.supernetID') \
--stake-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr') \
--stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr') \
--jsonrpc {{ rootchain_json_rpc }}
((counter++))
{% endif %}
{% endfor %}
{% for item in hostvars %}
{% if (hostvars[item].tags.Role == "validator") %}
{% endif %}
{% endfor %}
polygon-edge polybft supernet \
--private-key aa75e9a7d427efc732f8e4f1a5b7646adcc61fd5bae40f80d13c8419c9f43d6d \
--supernet-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.customSupernetManagerAddr') \
--finalize-genesis-set \
--enable-staking \
--jsonrpc {{ rootchain_json_rpc }}
tar czf {{ base_dn }}.tar.gz *.json *.private
popd
}
main
EOF
- name: Run Ansible
working-directory: ansible
run: |
ansible-inventory --graph
ansible-galaxy install -r requirements.yml
ansible-playbook site.yml --extra-vars "block_gas_limit=200000000 block_time=2"
- name: Set rpc url value
id: url
run: |
terraform output -raw aws_lb_ext_domain | grep -o -E '^ext[^:]*' > rpc_url.txt
- uses: actions/upload-artifact@v3
with:
name: rpc_url
path: rpc_url.txt
loadtest1:
needs: build
uses: ./.github/workflows/loadtest.yml
name: Load Test Nightly Build - multiple_EOA
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
LOADTEST_RPC_URL: "" # this is a workaround because of actions bug in passing output to another job
DD_API_KEY: ${{ secrets.DD_API_KEY }}
LOADTEST_MNEMONIC: ${{ secrets.LOADTEST_MNEMONIC }}
with:
runner: loadtester
environment: ${{ inputs.environment }}
scenario: multiple_EOA
duration: ${{ inputs.duration }}
loadtest2:
needs: loadtest1
uses: ./.github/workflows/loadtest.yml
name: Load Test Nightly Build - multiple_ERC20
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
LOADTEST_RPC_URL: "" # this is a workaround because of actions bug in passing output to another job
DD_API_KEY: ${{ secrets.DD_API_KEY }}
LOADTEST_MNEMONIC: ${{ secrets.LOADTEST_MNEMONIC }}
with:
runner: loadtester
environment: ${{ inputs.environment }}
scenario: multiple_ERC20
duration: ${{ inputs.duration }}
destroy_devnet:
needs: [loadtest1, loadtest2]
if: always()
name: Destroy Nightly Build
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
repository: maticnetwork/terraform-polygon-supernets
ref: main
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Install Terraform
uses: hashicorp/setup-terraform@v2.0.3
with:
terraform_version: 1.4.5
- name: Configure terraform for nightly build
run: |
sed 's/# backend "s3" {}/backend "s3" {}/' main.tf > main.tf.tmp && mv main.tf.tmp main.tf
- name: Terraform Init
id: init
run: terraform init -backend-config="bucket=polygon-edge-devnet-terraform-states" -backend-config="key=state/${{ secrets.TF_VAR_DEPLOYMENT_NAME }}" -backend-config="region=${{ secrets.AWS_REGION }}"
- name: Retrieve state file from s3
run: aws s3 cp s3://polygon-edge-devnet-terraform-states/state/${{ secrets.TF_VAR_DEPLOYMENT_NAME }} state.json
- name: Terraform Destroy
id: destroy
run: terraform destroy -auto-approve -state=state.json
env:
TF_VAR_deployment_name: ${{ secrets.TF_VAR_DEPLOYMENT_NAME }}
TF_VAR_owner: ${{ secrets.TF_VAR_OWNER }}
TF_VAR_base_instance_type: ${{ secrets.TF_VAR_BASE_INSTANCE_TYPE }}