-
Notifications
You must be signed in to change notification settings - Fork 10
235 lines (203 loc) · 13.7 KB
/
deploy-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
name: Deploy Devnet
on:
workflow_dispatch:
inputs:
terms1:
description: "I acknowledge that running this workflow will make changes to the state of our EKS environments..."
type: boolean
required: true
terms2:
description: "I understand that an updated chain-spec from the same CI Run as the Substrate image must be provided if Substrate PVCs are being wiped"
type: boolean
required: true
terms3:
description: "I have made the Team aware that this deployment is about to occur"
type: boolean
required: true
substrate-node-image:
description: "Substrate Node ECR Image (Leave blank to use value from master)"
required: false
chain-spec-secret-name:
description: "Chain Spec Secret Name (Leave blank to use value from master, or if 'Wipe Substrate PVCs' is not selected)"
required: false
wipe:
description: "Wipe Substrate PVCs?"
type: boolean
required: true
rolling:
description: "Rolling Upgrade without deleting pods or PVCs?"
type: boolean
required: true
jobs:
deploy:
runs-on: eks
permissions:
id-token: write
contents: write
steps:
- name: Validate Terms and Conditions
run: |
echo "Validating terms and conditions..."
if [[ "${{ github.event.inputs.terms1 }}" != 'true' || "${{ github.event.inputs.terms2 }}" != 'true' || "${{ github.event.inputs.terms3 }}" != 'true' ]]; then
echo "Please read and accept all Terms before running the deployment. Exiting..."
exit 1
fi
echo "All terms and conditions accepted."
- name: Confirm Inputs and Evaluate Conditions
id: evaluate-conditions
run: |
echo "Confirming inputs..."
echo
echo "substrate-node-image: ${{ github.event.inputs.substrate-node-image }}"
echo "chain-spec-secret-name: ${{ github.event.inputs.chain-spec-secret-name }}"
echo "wipe: ${{ github.event.inputs.wipe }}"
echo "rolling: ${{ github.event.inputs.rolling }}"
echo "Evaluating Deployment Type..."
if [[ "${{ github.event.inputs.wipe }}" == 'true' ]]; then
echo "wipe=true" >> $GITHUB_ENV
else
echo "wipe=false" >> $GITHUB_ENV
fi
if [[ "${{ github.event.inputs.rolling }}" == 'true' ]]; then
echo "rolling=true" >> $GITHUB_ENV
else
echo "rolling=false" >> $GITHUB_ENV
fi
if [[ "${{ github.event.inputs.wipe }}" == 'true' && "${{ github.event.inputs.chain-spec-secret-name }}" != '' && "${{ github.event.inputs.substrate-node-image }}" != '' ]]; then
echo "deployment_type=1" >> $GITHUB_ENV
echo "Step: Deploy with chain-spec and image override will be run"
elif [[ "${{ github.event.inputs.wipe }}" == 'false' && "${{ github.event.inputs.substrate-node-image }}" != '' ]]; then
echo "deployment_type=2" >> $GITHUB_ENV
echo "Step: Deploy with image override will be run"
elif [[ "${{ github.event.inputs.substrate-node-image }}" == '' ]]; then
echo "deployment_type=3" >> $GITHUB_ENV
echo "Step: Deploy from master with no value overrides will be run"
else
echo "No matching condition for deployment"
exit 1
fi
- name: Checkout sidechains-infra-priv repo
uses: actions/checkout@v4
with:
repository: input-output-hk/sidechains-infra-priv
token: ${{ secrets.ACTIONS_PAT }}
path: sidechains-infra-priv
- name: Install kubectl, kubernetes-helm and awscli
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
sudo apt-get install apt-transport-https --yes
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
- name: Configure kubectl
run: |
echo "${{ secrets.kubeconfig_base64 }}" | base64 --decode > ${{ runner.temp }}/kubeconfig.yaml
kubectl config set-cluster my-cluster --server=${{ secrets.K8S_SERVER }} --insecure-skip-tls-verify=true
kubectl config set-credentials github-actions --token=${{ secrets.K8S_SA_TOKEN }}
kubectl config set-context my-context --cluster=my-cluster --user=github-actions --namespace=default
kubectl config use-context my-context
- name: Delete pods
if: env.rolling != 'true'
continue-on-error: true
run: |
kubectl delete pod alice -n sc || true
kubectl delete pod bob -n sc || true
kubectl delete pod charlie -n sc || true
kubectl delete pod dave -n sc || true
kubectl delete pod eve -n sc || true
kubectl delete pod ferdie -n sc || true
kubectl delete pod greg -n sc || true
kubectl delete pod henry -n sc || true
echo "Waiting for all pods to delete..."
kubectl wait --for=delete pod/alice pod/bob pod/charlie pod/dave pod/eve pod/ferdie pod/greg pod/henry -n sc --timeout=120s || true
- name: Delete substrate PVCs
if: env.wipe == 'true' && env.rolling != 'true'
continue-on-error: true
run: |
kubectl delete pvc alice-claim-substrate-node-data -n sc
kubectl delete pvc bob-claim-substrate-node-data -n sc
kubectl delete pvc charlie-claim-substrate-node-data -n sc
kubectl delete pvc dave-claim-substrate-node-data -n sc
kubectl delete pvc eve-claim-substrate-node-data -n sc
kubectl delete pvc ferdie-claim-substrate-node-data -n sc
kubectl delete pvc greg-claim-substrate-node-data -n sc
kubectl delete pvc henry-claim-substrate-node-data -n sc
echo "Waiting for all PVCs to delete..."
kubectl wait --for=delete pvc/alice-claim-substrate-node-data pvc/bob-claim-substrate-node-data pvc/charlie-claim-substrate-node-data pvc/dave-claim-substrate-node-data pvc/eve-claim-substrate-node-data pvc/ferdie-claim-substrate-node-data pvc/greg-claim-substrate-node-data pvc/henry-claim-substrate-node-data -n sc --timeout=120s
- name: Deploy with chain-spec and image override
if: env.deployment_type == 1
run: |
cd sidechains-infra-priv/src/kube/substrate-poc/environments/helm/substrate-node-stack-chart/
helm upgrade --install alice . -f values/chains/devnet.yaml -f values/nodes/devnet/alice.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install bob . -f values/chains/devnet.yaml -f values/nodes/devnet/bob.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install charlie . -f values/chains/devnet.yaml -f values/nodes/devnet/charlie.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install dave . -f values/chains/devnet.yaml -f values/nodes/devnet/dave.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install eve . -f values/chains/devnet.yaml -f values/nodes/devnet/eve.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install ferdie . -f values/chains/devnet.yaml -f values/nodes/devnet/ferdie.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install greg . -f values/chains/devnet.yaml -f values/nodes/devnet/greg.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
helm upgrade --install henry . -f values/chains/devnet.yaml -f values/nodes/devnet/henry.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}" --set chain.chainspec_secretName="${{ github.event.inputs.chain-spec-secret-name }}"
- name: Deploy with image override
if: env.deployment_type == 2
run: |
cd sidechains-infra-priv/src/kube/substrate-poc/environments/helm/substrate-node-stack-chart/
helm upgrade --install alice . -f values/chains/devnet.yaml -f values/nodes/devnet/alice.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install bob . -f values/chains/devnet.yaml -f values/nodes/devnet/bob.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install charlie . -f values/chains/devnet.yaml -f values/nodes/devnet/charlie.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install dave . -f values/chains/devnet.yaml -f values/nodes/devnet/dave.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install eve . -f values/chains/devnet.yaml -f values/nodes/devnet/eve.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install ferdie . -f values/chains/devnet.yaml -f values/nodes/devnet/ferdie.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install greg . -f values/chains/devnet.yaml -f values/nodes/devnet/greg.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
helm upgrade --install henry . -f values/chains/devnet.yaml -f values/nodes/devnet/henry.yaml --set images.substrateNode="${{ github.event.inputs.substrate-node-image }}"
- name: Deploy from master with no value overrides
if: env.deployment_type == 3
run: |
cd sidechains-infra-priv/src/kube/substrate-poc/environments/helm/substrate-node-stack-chart/
helm upgrade --install alice . -f values/chains/devnet.yaml -f values/nodes/devnet/alice.yaml
helm upgrade --install bob . -f values/chains/devnet.yaml -f values/nodes/devnet/bob.yaml
helm upgrade --install charlie . -f values/chains/devnet.yaml -f values/nodes/devnet/charlie.yaml
helm upgrade --install dave . -f values/chains/devnet.yaml -f values/nodes/devnet/dave.yaml
helm upgrade --install eve . -f values/chains/devnet.yaml -f values/nodes/devnet/eve.yaml
helm upgrade --install ferdie . -f values/chains/devnet.yaml -f values/nodes/devnet/ferdie.yaml
helm upgrade --install greg . -f values/chains/devnet.yaml -f values/nodes/devnet/greg.yaml
helm upgrade --install henry . -f values/chains/devnet.yaml -f values/nodes/devnet/henry.yaml
- name: Wait
run: |
echo "Waiting for Alice..."
kubectl wait --for=condition=ready pod alice -n sc --timeout=300s
echo "Waiting for Bob..."
kubectl wait --for=condition=ready pod bob -n sc --timeout=300s
echo "Waiting for Charlie..."
kubectl wait --for=condition=ready pod charlie -n sc --timeout=300s
echo "Waiting for Dave..."
kubectl wait --for=condition=ready pod dave -n sc --timeout=300s
echo "Waiting for Eve..."
kubectl wait --for=condition=ready pod eve -n sc --timeout=300s
echo "Waiting for Ferdie..."
kubectl wait --for=condition=ready pod ferdie -n sc --timeout=300s
echo "Waiting for Greg..."
kubectl wait --for=condition=ready pod greg -n sc --timeout=300s
echo "Waiting for Henry..."
kubectl wait --for=condition=ready pod henry -n sc --timeout=300s
- name: Validate
run: |
echo "Checking Alice..."
kubectl get pod alice -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Bob..."
kubectl get pod bob -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Charlie..."
kubectl get pod charlie -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Dave..."
kubectl get pod dave -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Eve..."
kubectl get pod eve -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Ferdie..."
kubectl get pod ferdie -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Greg..."
kubectl get pod greg -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
echo "Checking Henry..."
kubectl get pod henry -n sc -o jsonpath="{.status.containerStatuses[*].ready}"
kubectl get pods -n sc -o custom-columns='NAME:.metadata.name,READY:.status.containerStatuses[*].ready' | grep -E '^(alice|bob|charlie|dave|eve|ferdie|greg|henry)' | awk '{if ($2 != "true,true,true,true") exit 1}'
echo "All pods are 4/4 up and ready"