Skip to content

Commit 3f21f64

Browse files
committed
add bash script to run tests on AWS instances
1 parent 073d72f commit 3f21f64

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/aws_tests.bash

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Preliminary setup
4+
# - Install AWS CLI v2 (perhaps it works on v1, untested):
5+
# - on Arch Linux: paru -S aws-cli-v2
6+
# - Configure AWS Credentials: aws configure
7+
8+
set -e # Exit script on first error
9+
10+
AMI_ID_x86_64="ami-020cba7c55df1f615"
11+
AMI_ID_aarch64="ami-07041441b708acbd6"
12+
13+
INSTANCES_x86_64=()
14+
INSTANCES_aarch64=("c6g.medium" "c7g.medium" "c8g.medium")
15+
16+
KEY_NAME="openssh"
17+
KEY_PATH="~/.ssh/openssh.pem"
18+
SSH_COMMAND="ssh -i ${KEY_PATH} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
19+
SECURITY_GROUP="sg-0315466a0d7fc99e1"
20+
VOLUME_SIZE=10 # in GB
21+
22+
PROJECT_DIR=$(basename $(pwd))
23+
24+
for INSTANCE_NAME in "${INSTANCES_x86_64[@]}" "${INSTANCES_aarch64[@]}"; do
25+
if printf '%s\n' "${INSTANCES_aarch64[@]}" | grep -qx "${INSTANCE_NAME}"; then
26+
AMI_ID=${AMI_ID_aarch64}
27+
else
28+
AMI_ID=${AMI_ID_x86_64}
29+
fi
30+
echo "Running instance for ${INSTANCE_NAME} with AMI ${AMI_ID}"
31+
32+
INSTANCE_ID=$(aws ec2 run-instances \
33+
--image-id ${AMI_ID} \
34+
--instance-type ${INSTANCE_NAME} \
35+
--key-name ${KEY_NAME} \
36+
--block-device-mappings "DeviceName=/dev/sda1,Ebs={VolumeSize=${VOLUME_SIZE}}" \
37+
--associate-public-ip-address \
38+
--security-group-ids ${SECURITY_GROUP} \
39+
--count "1" --query 'Instances[0].InstanceId' --output text)
40+
41+
aws ec2 wait instance-status-ok --instance-ids ${INSTANCE_ID}
42+
echo "Started instance: ${INSTANCE_ID}"
43+
44+
PUBLIC_IP=$(aws ec2 describe-instances \
45+
--instance-ids ${INSTANCE_ID} \
46+
--query "Reservations[0].Instances[0].PublicIpAddress" \
47+
--output text)
48+
echo "Instance public IP: ${PUBLIC_IP}"
49+
50+
rsync -avz --partial --progress --exclude ".git" --exclude "build" -e "${SSH_COMMAND}" \
51+
${PROJECT_DIR}/ ubuntu@${PUBLIC_IP}:~/${PROJECT_DIR}
52+
${SSH_COMMAND} ubuntu@${PUBLIC_IP} << 'EOF'
53+
set -e # Exit on error
54+
55+
# Install dependencies
56+
sudo apt update
57+
sudo apt install -y linux-tools-common linux-tools-generic g++ cmake
58+
59+
# Build the project
60+
cmake -B build . && cmake --build build
61+
62+
# Run the script to generate multiple tables
63+
./scripts/generate_multiple_tables.py
64+
EOF
65+
66+
echo "Script executed successfully"
67+
mkdir -p "${PROJECT_DIR}/outputs/${INSTANCE_NAME}"
68+
rsync -avz --partial --progress -e "${SSH_COMMAND}" \
69+
ubuntu@${PUBLIC_IP}:~/${PROJECT_DIR}/outputs/ ${PROJECT_DIR}/outputs/${INSTANCE_NAME}/
70+
71+
aws ec2 terminate-instances --instance-ids ${INSTANCE_ID}
72+
echo "Terminated instance: ${INSTANCE_ID}"
73+
done

0 commit comments

Comments
 (0)