-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.bash
380 lines (364 loc) · 12.2 KB
/
setup.bash
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
#!/bin/bash
VERSION=1.0
IFS=$'\n'
BACKTITLE="Folding@home Docker, Microsoft AKS and Microsoft ACI setup - Carlos Milán Figueredo @cmilanf"
LOCATION="westeurope"
pause () {
read -n 1 -s -r -p "Press any key to continue"
echo ''
}
headermsg () {
echo "Folding@home Setup script v${VERSION}"
echo "...with GPU support via CUDA!"
echo "Copyright (c) 2020 Carlos Milán Figueredo - MIT License"
echo ""
}
usagemsg () {
echo "You can use the following parameters to set script defaults:"
echo "$0 -g <resource group name> -s <Azure subscription name or id> -l <location>"
echo ""
}
chkbin () {
if ! [ -x "$(command -v $1)" ]; then
echo "ERROR: This script requires $1 program to continue. Please install it."
exit 1
fi
}
checkdeps () {
chkbin dialog
}
docker_build () {
clear
chkbin docker
HEIGHT=10
WIDTH=75
TITLE="Build Docker image"
BODY="Please enter the name and tag of the Docker image to build, for instance: cmilanf/fohclient:7.5.1"
exec 3>&1
VALUE=$(dialog --ok-label "Build" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 0 \
"Docker image name:" 1 1 "cmilanf/fahclient:latest" 1 20 60 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CMD="docker build -t $VALUE ."
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
docker_push () {
clear
chkbin az
HEIGHT=10
WIDTH=75
TITLE="Push Docker image"
BODY="Please enter the name and tag of the Docker image to push. You must have permissions into your container registry. If not, please, go back to the shell and perform a 'docker login'."
exec 3>&1
VALUE=$(dialog --ok-label "Push" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 0 \
"Docker image name:" 1 1 "cmilanf/fahclient:latest" 1 20 60 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CMD="docker push $VALUE"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
aks () {
clear
chkbin az
HEIGHT=19
WIDTH=75
TITLE="Deploy Azure Kubernetes Service"
BODY="We are going to Deploy Azure Kubernetes Service with GPU equiped Virtual Machines (keep close eye on Azure consumtion costs!). You need the AZ CLI and to be previously authenticated into your Microsoft Azure subscription. If not, please, exit the script and return once it is done.\n\nFill the following data and for further customization take a look 'deploy-gpu-aks.parameters.json'. You don't need to provide SSH RSA key as it is generated by the script."
exec 3>&1
VALUES=$(dialog --ok-label "Deploy" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 5 \
"Subscription name or id:" 1 1 "$subscription" 1 25 45 0 \
"Resource group name:" 2 1 "$rg" 2 25 45 0 \
"Location:" 3 1 "$LOCATION" 3 25 45 0 \
"AKS cluster name:" 4 1 "" 4 25 45 0 \
"DNS prefix:" 5 1 "" 5 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CHOICES=($VALUES)
CMD="scripts/deploy-gpu-aks.bash --subscription ${CHOICES[0]} -g ${CHOICES[1]} --location ${CHOICES[2]} --aks-cluster-name ${CHOICES[3]} --dns-prefix ${CHOICES[4]} --template-file arm/deploy-gpu-aks.json --parameters-file arm/deploy-gpu-aks.parameters.json --create-aad-sp"
echo "Issuing command => $CMD"
echo ''
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
aks_cred () {
clear
chkbin az
chkbin kubectl
HEIGHT=12
WIDTH=75
TITLE="Import AKS credentials into kubectl"
BODY="Is your AKS cluster deployed? Then let's import credentials into kubectl before deploying the application. You will need AZ CLI and kubectl installed on your system."
exec 3>&1
VALUES=$(dialog --ok-label "Import credentials" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 3 \
"Subscription name or id:" 1 1 "$subscription" 1 25 45 0 \
"Resource group name:" 2 1 "$rg" 2 25 45 0 \
"AKS name:" 3 1 "$aksname" 3 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CHOICES=($VALUES)
CMD="az aks get-credentials --subscription ${CHOICES[0]} -g ${CHOICES[1]} -n ${CHOICES[2]}"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
aks_clean () {
clear
chkbin az
HEIGHT=14
WIDTH=75
TITLE="DELETE AKS and AAD SP"
BODY="We are going to DELETE the Azure AD Service Principal and the Resource Group specified on this script. THIS ACTION IS PERMANENT. Please know what your are doing before proceeding. Note that we will be using the deploy-gpu-aks.parameters.json file to gather information needed for deletion."
exec 3>&1
VALUES=$(dialog --ok-label "DELETE" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 3 \
"Subscription name or id:" 1 1 "$subscription" 1 25 45 0 \
"Resource group name:" 2 1 "$rg" 2 25 45 0 \
"Write iknowwhatiamdoing:" 3 1 "$iknowwhatiamdoing" 3 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CHOICES=($VALUES)
if [ "${CHOICES[2]}" = "iknowwhatiamdoing" ]; then
CMD="scripts/clean-gpu-aks.bash --subscription ${CHOICES[0]} -g ${CHOICES[1]} --parameters-file output/deploy-gpu-aks.parameters.json --iknowwhatiamdoing"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
else
echo "You don't know what you are doing, so I am aborting the operation."
fi
pause
fi
exec 3>&-
}
k8s_nvidia () {
clear
chkbin kubectl
K8S_CONTEXT=$(kubectl config current-context)
HEIGHT=10
WIDTH=75
TITLE="Install NVIDIA GPU driver into Kubernetes"
BODY="This operation will install NVIDIA GPU drivers into your Kubernetes cluster. Check the context we are going to use for applying the manifest. If it is wrong, you have the chance to correct it."
exec 3>&1
VALUE=$(dialog --ok-label "Install drivers" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 1 \
"kubectl context:" 1 1 "$K8S_CONTEXT" 1 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CMD="kubectl config set-context $VALUE"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
CMD="kubectl apply -f k8s/nvidia-device-plugin-ds.yaml"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
k8s_fah () {
clear
chkbin kubectl
chkbin sed
K8S_CONTEXT=$(kubectl config current-context)
HEIGHT=12
WIDTH=75
TITLE="Deploy Folding@home client into Kubernetes"
BODY="This operation will deploy FAHClient into your Kubernetes cluster using the image cmilanf/fahclient. Check the context we are going to use for applying the manifest. If it is wrong, you have the chance to correct it."
exec 3>&1
VALUES=$(dialog --ok-label "Deploy FAHClient" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 3 \
"kubectl context:" 1 1 "$K8S_CONTEXT" 1 25 45 0 \
"FAH user name:" 2 1 "Anonymous" 2 25 45 0 \
"FAH team:" 3 1 "0" 3 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CHOICES=($VALUES)
CMD="kubectl config set-context ${CHOICES[0]}"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
mkdir -p output
cp -f k8s/fah-deployment.yaml output/
sed -i "s/value: Anonymous/value: ${CHOICES[1]}/g" output/fah-deployment.yaml
sed -i "s/value: '0'/value: '${CHOICES[2]}'/g" output/fah-deployment.yaml
CMD="kubectl apply -f output/fah-deployment.yaml"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
aci () {
clear
chkbin az
chkbin sed
HEIGHT=14
WIDTH=75
TITLE="Deploy Folding@home client into ACI"
BODY="This operation will deploy FAHClient into Azure Container Instances. At the time of writting this script, only CPU compute is supported, being GPU one in preview; so I will deploy CPU-only instances."
exec 3>&1
VALUES=$(dialog --ok-label "Deploy FAHClient" \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--form "$BODY" \
$HEIGHT $WIDTH 5 \
"Subscription name or id:" 1 1 "$subscription" 1 25 45 0 \
"Resource group name:" 2 1 "$rg" 2 25 45 0 \
"Number of instances:" 3 1 "1" 3 25 45 0 \
"FAH user name:" 4 1 "Anonymous" 4 25 45 0 \
"FAH team:" 5 1 "0" 5 25 45 0 \
2>&1 1>&3)
if [ $? -eq 0 ]; then
clear
CHOICES=($VALUES)
if [ $(az group exists -g ${CHOICES[1]}) = 'false' ]; then
az group create -n ${CHOICES[1]} -l westeurope
fi
CMD="az deployment group create --subscription ${CHOICES[0]} -g ${CHOICES[1]} --template-file arm/deploy-aci.json --parameters fah-user=${CHOICES[3]} fah-team=${CHOICES[4]} count=${CHOICES[2]} --verbose"
echo "Issuing command => $CMD"
sleep 3
/bin/bash -c $CMD
pause
fi
exec 3>&-
}
mainmenu () {
HEIGHT=25
WIDTH=80
CHOICE_HEIGHT=10
TITLE="Main menu"
BODY="Welcome to the Folding@home setup program, an elegant way to donate your compute capacity to scientific community and help fighting COVID-19, Cancer, Alzheimer... Join us!\n\nThis script perform the tasks needed for deploying the application into Azure Kubernetes Service with GPU support enabled or Azure Container Instances.\n\nPlease select an option:"
OPTIONS=(DOCKER_BUILD "Build Docker image"
DOCKER_PUSH "Push the Docker image to your repository"
AKS "Deploy Azure Kubernetes Service with GPU and AAD SP"
AKS_CRED "Import AKS credentials into your kubectl"
AKS_CLEAN "Remove AKS and associated AAD SP"
K8S_NVIDIA "Deploy NVIDIA GPU drivers for Kubernetes"
K8S_FAH "Deploy Folding@home for Kubernetes with CPU and GPU"
ACI "Deploy Azure Container Instances with Folding@home"
--- "---------------------"
EXIT "Exit the setup script")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$BODY" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
if [ $? -eq 0 ]; then
clear
case $CHOICE in
DOCKER_BUILD)
docker_build
;;
DOCKER_PUSH)
docker_push
;;
AKS)
aks
;;
AKS_CRED)
aks_cred
;;
AKS_CLEAN)
aks_clean
;;
K8S_NVIDIA)
k8s_nvidia
;;
K8S_FAH)
k8s_fah
;;
ACI)
aci
;;
EXIT)
exit 0
;;
esac
else
exit 0
fi
}
headermsg
chkbin dialog
while [ $# -gt 0 ]
do
case "$1" in
-s)
subscription="$2"
shift 2
;;
-g)
rg="$2"
shift 2
;;
-l)
LOCATION="$2"
shift 2
;;
--help)
usagemsg
exit 0
;;
*)
echo "Incorrect arguments or syntax fail: $1"; echo ''
exit 1
;;
esac
done
sleep 1
while true; do
mainmenu
done