This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh
executable file
·77 lines (61 loc) · 2.79 KB
/
deploy.sh
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
#!/bin/bash
CLUSTERNAME="add-cluster-name"
S3_BUCKETNAME="add-bucket-name"
SECURITYGROUP_RSW="sg-##"
SUBNETID="subnet-##"
REGION="eu-west-1"
KEY="add-keyname"
# Posit Workbench Version
PWB_VER=2022.07.2-576.pro12
PWB_VER=2022.12.0-353.pro20
PWB_VER=2023.09.1-494.pro2
#PWB_VER=2023.05.0-daily-312.pro2
# SLURM Version - use only "-" to resemble git tag version
SLURM_VER=22-05-5-1
CERT="/Users/michael/projects/aws/certs/michael.pem"
# create random rstudio password and store it in a secret
## rstudiopw will be a 12 character random string with mixed upper and lowercase characters + numbers
rstudiopw=`python -c "import random,string; x=''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=12));print(x)"`
## let's label the secret so it can be recognised again
secret_name="rstudiopw-cluster-$CLUSTERNAME"
aws secretsmanager create-secret \
--name $secret_name \
--description "Secret for rstudio user password on AWS ParallelCluster $CLUSTERNAME" \
--secret-string "$rstudiopw"
if [ $? -eq 254 ]; then
secret_id=`aws secretsmanager list-secrets --filters Key=name,Values=$secret_name | jq -r '.SecretList | .[]| .ARN'`
echo "secret $secret_name already exists, we need to update it"
aws secretsmanager update-secret \
--secret-id "$secret_id" \
--secret-string "$rstudiopw"
else
secret_id=`aws secretsmanager list-secrets --filters Key=name,Values=$secret_name | jq -r '.SecretList | .[]| .ARN'`
fi
get_secret=`aws secretsmanager get-secret-value --secret-id $secret_id | jq -r '.SecretString'`
echo "rstudio user password is now set to $get_secret"
rm -rf tmp
mkdir -p tmp
cp -Rf scripts/* tmp
cat scripts/aliases.sh | sed "s#CERT#${CERT}#" > tmp/aliases.sh
cat scripts/install-rsw.sh | sed "s/PWB_VER/$PWB_VER/" \
| sed "s#S3_BUCKETNAME#${S3_BUCKETNAME}#g" \
| sed "s#SECRET#$get_secret#g"> tmp/install-rsw.sh
cat scripts/install-compute.sh | sed "s#SECRET#$get_secret#g" > tmp/install-compute.sh
for i in scripts/*.sdef
do
if [[ $PWB_VER =~ "2022.12" ]]; then
cat $i | sed "s/PWB_VER/$PWB_VER/" | sed "s/SLURM_VER/$SLURM_VER/" | sed "s#r-session-complete:#r-session-complete-preview:dev-#" > ${i/scripts/tmp/}
else
PWB_VER=`echo $PWB_VER | sed 's/\-.*//'`
cat $i | sed "s/PWB_VER/$PWB_VER/" | sed "s/SLURM_VER/$SLURM_VER/"> ${i/scripts/tmp/}
fi
done
aws s3 cp tmp/ s3://${S3_BUCKETNAME} --recursive
cat config/cluster-config-wb.tmpl | \
sed "s#S3_BUCKETNAME#${S3_BUCKETNAME}#g" | \
sed "s#SECURITYGROUP_RSW#${SECURITYGROUP_RSW}#g" | \
sed "s#SUBNETID#${SUBNETID}#g" | \
sed "s#REGION#${REGION}#g" | \
sed "s#KEY#${KEY}#g" \
> config/cluster-config-wb.yaml
pcluster create-cluster --cluster-name="$CLUSTERNAME" --cluster-config=config/cluster-config-wb.yaml --rollback-on-failure false