@@ -9,10 +9,10 @@ if [[ $(basename "$PWD") != "nuklaivm" ]]; then
9
9
exit 1
10
10
fi
11
11
12
- KEY_NAME=" ../ssh-keys/nuklaivm-nodes-devnet.pem"
12
+ KEY_FILE=" ./scripts/aws/nuklaivm-nodes-devnet.pem"
13
+ KEY_NAME=" nuklaivm-nodes-devnet"
13
14
INSTANCE_NAME=" nuklaivm-nodes-devnet"
14
15
REGION=" eu-west-1"
15
- INSTANCE_PROFILE_NAME=" "
16
16
INSTANCE_TYPE=" t3a.medium"
17
17
SECURITY_GROUP=" sg-0c06bc676cb309bbc"
18
18
SUBNET_ID=" subnet-08322a251c30c1367"
40
40
echo " Using AMI ID: $AMI_ID "
41
41
42
42
# Check if an instance is already running
43
- INSTANCE_ID=$( aws ec2 describe-instances --region $REGION \
44
- --filters " Name=tag:Name,Values=$INSTANCE_NAME " " Name=instance-state-name,Values=running" \
45
- --query " Reservations[0].Instances[0].InstanceId" --output text)
46
-
47
- if [ " $INSTANCE_ID " != " None" ]; then
48
- echo " Existing instance found. Terminating it..."
49
- aws ec2 terminate-instances --instance-ids $INSTANCE_ID --region $REGION
50
- aws ec2 wait instance-terminated --instance-ids $INSTANCE_ID --region $REGION
51
- echo " Instance terminated."
52
- fi
43
+ RETRIES=3
44
+ for (( i= 1 ; i<= RETRIES; i++ )) ; do
45
+ INSTANCE_ID=$( aws ec2 describe-instances --region $REGION \
46
+ --filters " Name=tag:Name,Values=$INSTANCE_NAME " " Name=instance-state-name,Values=running" \
47
+ --query " Reservations[0].Instances[0].InstanceId" --output text)
48
+ if [[ " $INSTANCE_ID " != " None" ]]; then
49
+ echo " Existing instance found. Terminating it..."
50
+ aws ec2 terminate-instances --instance-ids $INSTANCE_ID --region $REGION
51
+ aws ec2 wait instance-terminated --instance-ids $INSTANCE_ID --region $REGION
52
+ echo " Instance terminated."
53
+ break
54
+ elif [[ $i -eq $RETRIES ]]; then
55
+ echo " Failed to describe instances after $RETRIES attempts."
56
+ exit 1
57
+ fi
58
+ sleep $(( 2 ** i))
59
+ done
53
60
54
61
# Check if an Elastic IP has already been allocated
55
62
if [ -f " $EIP_FILE " ]; then
76
83
77
84
# Launch a new EC2 instance
78
85
echo " Launching a new EC2 instance..."
79
- INSTANCE_ID=$( aws ec2 run-instances \
80
- --region $REGION \
86
+ INSTANCE_ID=$( aws ec2 run-instances --region $REGION \
87
+ --image-id $AMI_ID --count 1 --instance-type $INSTANCE_TYPE \
88
+ --key-name $KEY_NAME --security-group-ids $SECURITY_GROUP \
81
89
--subnet-id $SUBNET_ID \
82
- --launch-template ' LaunchTemplateName=nuklaivm-nodes-devnet,Version=$Latest' \
90
+ --associate-public-ip-address \
91
+ --block-device-mappings ' DeviceName=/dev/xvda,Ebs={VolumeSize=100,VolumeType=gp3,DeleteOnTermination=true}' \
92
+ --tag-specifications " ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME }]" \
93
+ --user-data file://$USER_DATA_FILE \
83
94
--query " Instances[0].InstanceId" --output text)
84
95
85
96
@@ -102,10 +113,10 @@ if [ -f "$HOME/.ssh/known_hosts" ]; then
102
113
fi
103
114
104
115
echo " Transferring tarball and private key to the EC2 instance..."
105
- scp -o " StrictHostKeyChecking=no" -o " UserKnownHostsFile=/dev/null" -i $KEY_NAME $TARBALL ec2-user@$ELASTIC_IP :/home/ec2-user/
116
+ scp -o " StrictHostKeyChecking=no" -o " UserKnownHostsFile=/dev/null" -i $KEY_FILE $TARBALL ec2-user@$ELASTIC_IP :/home/ec2-user/
106
117
107
118
echo " Connecting to the EC2 instance and deploying devnet..."
108
- ssh -o " StrictHostKeyChecking=no" -o " UserKnownHostsFile=/dev/null" -i $KEY_NAME ec2-user@$ELASTIC_IP << EOF
119
+ ssh -o " StrictHostKeyChecking=no" -o " UserKnownHostsFile=/dev/null" -i $KEY_FILE ec2-user@$ELASTIC_IP << EOF
109
120
echo "Waiting for Docker installation to complete..."
110
121
TIMEOUT=180 # Set a timeout in seconds to wait for Docker installation completion
111
122
SECONDS=0
0 commit comments