-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
108 lines (85 loc) · 3.51 KB
/
run.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
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
PROFILE=...
export BUCKET=...
REGION=us-east-1
KEYPAIR=ec2-keypair
# https://cloud-images.ubuntu.com/locator/ec2/ # amd64 us-east-1 ebs-ssd hvm
IMAGEID=ami-0c43b23f011ba5061
export BENCHMARK="$1"
# https://stackoverflow.com/questions/2427995/bash-no-arguments-warning-and-case-decisions
if [[ $# -eq 0 ]]; then BENCHMARK="countbits"; fi
case "$BENCHMARK" in
# https://unix.stackexchange.com/questions/62333/setting-a-shell-variable-in-a-null-coalescing-fashion
fibonacci) export ARGS="${2:-42}" ;;
*) ;;
esac
# http://docs.aws.amazon.com/cli/latest/userguide/controlling-output.html#controlling-output-filter
SGID=$(aws ec2 describe-security-groups \
--profile $PROFILE \
--region $REGION \
--query 'SecurityGroups[?GroupName==`ssh-anywhere`].GroupId' \
--output text)
echo $SGID
echo $PROFILE $REGION $BUCKET $TYPE $KEYPAIR $IMAGEID $SGID
NOW=`date +%Y%m%d%H%M%S`
# https://www.cyberciti.biz/faq/bash-for-loop-array/
types=( c csharp elixir go java java_1 java_2 jruby javascript javascript_1 javascript_2 php python3 ruby rust )
for TYPE in "${types[@]}"
do
export TYPE
# https://stackoverflow.com/questions/1494178/how-to-define-hash-tables-in-bash
export TYPE_LANG=${TYPE%%_*}
# https://stackoverflow.com/questions/59838/check-if-a-directory-exists-in-a-shell-script
if [ ! -d "$BENCHMARK/$TYPE" ]; then
continue
fi
echo ""
echo "aws s3 ls --profile $PROFILE $BUCKET/$TYPE/"
aws s3 ls --profile $PROFILE $BUCKET/$TYPE/
# https://superuser.com/questions/133780/in-bash-how-do-i-escape-an-exclamation-mark
# https://stackoverflow.com/questions/10683349/forcing-bash-to-expand-variables-in-a-string-loaded-from-a-file
USERDATA=$(
echo -e "#"'!'"/bin/bash\n"
echo -e "\n# ----- CLONE -----\n"
cat clone_repo.sh
echo -e "\n# ----- SETUP -----\n"
cat setup/$TYPE_LANG/setup.sh
echo -e "\n# ----- BUILD -----\n"
echo -e "cd countbits/$BENCHMARK/$TYPE && . ./build.sh\n"
echo -e "\n# ----- RUN AND COPY -----\n"
envsubst \$BUCKET,\$BENCHMARK,\$TYPE,\$ARGS < benchmark_type.sh
)
INSTANCEID=$(aws ec2 run-instances \
--profile $PROFILE \
--region $REGION \
--output text \
--query 'Instances[*].InstanceId' \
--image-id $IMAGEID \
--key-name $KEYPAIR \
--security-group-ids $SGID \
--instance-type t2.micro \
--user-data "$USERDATA" \
--instance-initiated-shutdown-behavior terminate \
--iam-instance-profile Name="s3-put-profile" \
--count 1)
echo "aws ec2 terminate-instances --profile $PROFILE --region $REGION --instance-ids $INSTANCEID"
aws ec2 create-tags \
--profile $PROFILE \
--region $REGION \
--resources $INSTANCEID \
--tags Key=Name,Value="$BENCHMARK $TYPE $NOW"
DOMAIN=$(aws ec2 describe-instances \
--profile $PROFILE \
--region $REGION \
--instance-ids $INSTANCEID \
--output text \
--query 'Reservations[*].Instances[*].PublicDnsName')
echo "ssh -i ~/.ssh/$KEYPAIR.pem ubuntu@$DOMAIN"
done
unset ARGS # in case it was set for fibonacci
echo ""
echo "aws ec2 describe-instances --profile $PROFILE --region $REGION --query 'Reservations[*].Instances[*].[LaunchTime, InstanceId, State.Name, Tags[0].Value]' --output text"
aws ec2 describe-instances \
--profile $PROFILE \
--region $REGION \
--query 'Reservations[*].Instances[*].[LaunchTime, InstanceId, State.Name, Tags[0].Value]' \
--output text