-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathec2_launcher
More file actions
executable file
·55 lines (45 loc) · 1.61 KB
/
ec2_launcher
File metadata and controls
executable file
·55 lines (45 loc) · 1.61 KB
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
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: <keypair.pem> <ssh_cidr_block> <vpc_cidr_block>"
exit 1
fi
aws cloudformation deploy \
--region us-east-2 \
--profile poolgp \
--template-file ec2_stack.yaml \
--stack-name poolgpec2cluster \
--parameter-overrides KeyName=poolgp_cluster \
InstanceType=c4.2xlarge \
InstanceAmiId=ami-0f65671a86f061fcd \
SSHLocation=$2 \
VpcCIDR=$3
STACKJSON=$(aws cloudformation describe-stacks \
--region us-east-2 \
--profile poolgp \
--stack-name poolgpec2cluster)
for node in 'C8PublicIP' 'C7PublicIP' 'C6PublicIP' 'C5PublicIP' 'C4PublicIP' 'C3PublicIP' 'C2PublicIP' 'C1PublicIP'
do
IP=$(echo $STACKJSON | python -c "import json,sys;json_obj=json.load(sys.stdin); \
print(filter(lambda o: o['OutputKey'] == '${node}', \
json_obj['Stacks'][0]['Outputs'])[0]['OutputValue'])")
#attempt to reach instance
until ping -c1 $IP &>/dev/null; do :; done
#attempt to ssh into instance
ssh -i $1 ubuntu@$IP exit
while test $? -gt 0
do
sleep 5
ssh -i $1 ubuntu@$IP exit
done
echo "Copying docker installer to ubuntu@${IP}..."
scp -i $1 docker/docker_installer ubuntu@$IP:
if [ $node = 'C1PublicIP' ]
then
echo "Copying swarm configuration to ubuntu@${IP}..."
scp -i $1 docker/docker-compose.yml ubuntu@$IP:
echo "STACK CREATION RESULT"
echo $STACKJSON
#finally, ssh into master
ssh -i $1 ubuntu@$IP
fi
done