-
Notifications
You must be signed in to change notification settings - Fork 115
183 lines (163 loc) · 7.53 KB
/
deploy-node-network.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
name: Deploy Network
on:
workflow_dispatch:
inputs:
networkConfiguration:
description: 'Configuration (refer to .pipelines/deploy-node-network-inputs.json)'
required: true
default: ''
defaults:
run:
working-directory: devops/ansible
jobs:
deploy-node-network:
name: Deploy New Joystream Chain
runs-on: ubuntu-latest
env:
STACK_NAME: network-deployment-${{ github.run_number }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set env variables
id: network_config # set the outputs
run: |
jsonInput=$(jq -r '.inputs.networkConfiguration' $GITHUB_EVENT_PATH)
export ENCRYPTION_KEY=$(echo $jsonInput | jq -r '.encryptionKey.value')
echo ::set-output name=encryptionKey::$ENCRYPTION_KEY
echo "::add-mask::$ENCRYPTION_KEY"
echo ::set-output name=gitRepo::$(echo $jsonInput | jq -r '.gitRepo.value')
echo ::set-output name=branchName::$(echo $jsonInput | jq -r '.branchName.value')
echo ::set-output name=instanceType::$(echo $jsonInput | jq -r '.instanceType.value')
echo ::set-output name=networkName::$(echo $jsonInput | jq -r '.networkName.value')
echo ::set-output name=networkId::$(echo $jsonInput | jq -r '.networkId.value')
echo ::set-output name=deploymentType::$(echo $jsonInput | jq -r '.deploymentType.value')
echo ::set-output name=volumeSize::$(echo $jsonInput | jq -r '.volumeSize.value')
echo ::set-output name=runtimeProfile::$(echo $jsonInput | jq -r '.runtimeProfile.value')
echo ::set-output name=endowAccounts::$(echo $jsonInput | jq -r '.endowAccounts.value')
initialBalancesFile=$(echo $jsonInput | jq -r '.initialBalancesFile.value')
if [ -z "$initialBalancesFile" ]
then
echo ::set-output name=initialBalancesFilePath::''
else
wget $initialBalancesFile -O initial-balances.json
echo ::set-output name=initialBalancesFilePath::'initial-balances.json'
fi
- name: Install python3 netaddr
run: sudo apt-get install -y --no-install-recommends python3-netaddr
- name: Install Ansible
run: |
pip3 install --upgrade --user ansible
pipx inject ansible-core boto3 botocore
ansible-playbook --version
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Check if CloudFormation stack exists
id: stack_exists
run: |
if aws cloudformation describe-stacks --stack-name ${{ env.STACK_NAME }} >/dev/null 2>/dev/null; then
echo "Stack already exists"
exit 1
else
echo "Stack does not exist"
fi
- name: Deploy to AWS CloudFormation
uses: aws-actions/aws-cloudformation-github-deploy@v1
id: deploy_stack
with:
name: ${{ env.STACK_NAME }}
template: devops/aws/cloudformation/network.yml
no-fail-on-empty-changeset: '1'
parameter-overrides: >-
KeyName=joystream-github-action-key-new,
EC2InstanceType=${{ steps.network_config.outputs.instanceType }},
VolumeSize=${{ steps.network_config.outputs.volumeSize }}
- name: Wait for docker build server to be ready
run: |
sleep 30
- name: Prepare inventory for Ansible
run: |
VAL1="${{ steps.deploy_stack.outputs.Val1PublicIp }}"
VAL2="${{ steps.deploy_stack.outputs.Val2PublicIp }}"
BOOT1="${{ steps.deploy_stack.outputs.Val3PublicIp }}"
echo -e "[validators]\n$VAL1\n$VAL2\n\n" >> inventory
echo -e "[boot]\n$BOOT1\n\n" >> inventory
echo -e "[build]\n${{ steps.deploy_stack.outputs.BuildPublicIp }}\n\n" >> inventory
echo -e "[rpc]\n${{ steps.deploy_stack.outputs.RPCPublicIp }}\n" >> inventory
cat inventory
# Always Install tools
- name: Install tools on all hosts
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: install-tools.yml
directory: devops/ansible
requirements: requirements.yml
key: ${{ secrets.SSH_PRIVATE_KEY }}
options: |
--inventory inventory
# Build
- name: Build code
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: build-code.yml
directory: devops/ansible
requirements: requirements.yml
key: ${{ secrets.SSH_PRIVATE_KEY }}
options: |
--inventory inventory
--extra-vars "branch_name=${{ steps.network_config.outputs.branchName }} \
git_repo=${{ steps.network_config.outputs.gitRepo }} data_path=deploy_artifacts \
runtime_profile=${{ steps.network_config.outputs.runtimeProfile }}"
# Always Fetch binaries
- name: Fetch binaries from build host
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: fetch-binaries.yml
directory: devops/ansible
requirements: requirements.yml
key: ${{ secrets.SSH_PRIVATE_KEY }}
options: |
--inventory inventory
--extra-vars "data_path=deploy_artifacts"
- name: Terminate Build instance
continue-on-error: true
run: |
echo "Deleting build instance with id ${{ steps.deploy_stack.outputs.BuildInstanceId }}"
aws ec2 terminate-instances --instance-ids ${{ steps.deploy_stack.outputs.BuildInstanceId }}
# Configure and start chain
- name: Run playbook to configure chain-spec
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: deploy-network.yml
directory: devops/ansible
requirements: requirements.yml
key: ${{ secrets.SSH_PRIVATE_KEY }}
options: |
--inventory inventory
--extra-vars "network_name='${{ steps.network_config.outputs.networkName }}' \
network_id=${{ steps.network_config.outputs.networkId }} \
data_path=deploy_artifacts \
deployment_type=${{ steps.network_config.outputs.deploymentType }} \
initial_balances_file=${{ steps.network_config.outputs.initialBalancesFilePath }} \
endow_accounts=${{ steps.network_config.outputs.endowAccounts }} \
chainspec_creation_strategy='generate'"
- name: Encrpyt the artifacts
run: |
cp inventory deploy_artifacts/
7z a -p${{ steps.network_config.outputs.encryptionKey }} chain-data.7z deploy_artifacts/*
- name: Save the output as an artifact
uses: actions/upload-artifact@v3
with:
name: data-chainspec-auth
path: devops/ansible/chain-data.7z
- name: Delete CloudFormation Stack if any step failed
# Skip only if stack already existed or all steps passed succesfully
if: ( failure() || cancelled() ) && steps.stack_exists.outcome != 'failure'
run: |
echo "Deleting ${{ env.STACK_NAME }} stack"
aws cloudformation delete-stack --stack-name ${{ env.STACK_NAME }}
echo "Waiting for ${{ env.STACK_NAME }} to be deleted..."
aws cloudformation wait stack-delete-complete --stack-name ${{ env.STACK_NAME }}