@@ -1,5 +1,10 @@
11#!/bin/sh
22
3+IMAGE_ID=ami-0fa8979d18f69948b
4+INSTANCE_TYPE=t4g.2xlarge
5+KEY_NAME=debian-arm-us-east-2
6+SECURITY_GROUP_ID=sg-086ffbadc286c5c00
7+
38# Spin up an ARM build machine using aws cli, build pandoc, and
49# download the artifact.
510#
@@ -8,22 +13,23 @@
813
914aws configure set default.region us-east-2
1015
11−# Now start instance with volume 16GB.
12−# note, the AMI id is different for different regions.
13−# for us east-2 the Debian Buster ARM AMI is ami-0fa8979d18f69948b:
14−
1516echo "Creating instance..."
1617
17−aws ec2 run-instances --image-id ami-0fa8979d18f69948b --count 1 --instance-type t4g.2xlarge --block-device-mapping 'DeviceName=/dev/xvda,Ebs={VolumeSize=16}' --key-name debian-arm-us-east-2 --security-group-ids sg-086ffbadc286c5c00 > ec2.json
18+aws ec2 run-instances --image-id "$IMAGE_ID" --count 1 --instance-type "$INSTANCE_TYPE" --block-device-mapping 'DeviceName=/dev/xvda,Ebs={VolumeSize=16}' --key-name "$KEY_NAME" --security-group-ids "$SECURITY_GROUP_ID" > ec2.json
19+
20+jq < ec2.json
1821
1922# Now get the public IP address.
2023
2124INSTANCEID=$(jq '.Instances[0].InstanceId' ec2.json | sed -e 's/"//g')
2225IPADDR=$(aws ec2 describe-instances --instance-ids="$INSTANCEID" --query 'Reservations[0].Instances[0].PublicIpAddress' | sed -e 's/"//g')
2326
27+echo "IP address is $IPADDR"
28+
2429clean_up() {
25− echo "Terminating the instance..."
26− aws ec2 terminate-instances --instance-ids "$INSTANCEID"
30+ echo "Terminating the instance in 20 seconds..."
31+ echo "Ctrl-C to preserve it."
32+ sleep 20 && aws ec2 terminate-instances --instance-ids "$INSTANCEID"
2733}
2834trap clean_up EXIT
2935
@@ -40,8 +46,7 @@ done
4046# At this point you can connect via SSH, or run this script:
4147# $ ssh -i ~/.ssh/debian-arm-us-east-2.pem admin@$IPADDR
4248
43−SSH="ssh -i ~/.ssh/debian-arm-us-east-2.pem admin@$IPADDR"
44−SCP="scp -r -i ~/.ssh/debian-arm-us-east-2.pem admin@$IPADDR:"
49+SSH="ssh -i ~/.ssh/$KEY_NAME.pem admin@$IPADDR"
4550
4651echo "Provisioning..."
4752
@@ -74,16 +79,17 @@ EOF
7479
7580while true
7681do
77− sleep 60
78− $SSH "tail -n1 src/pandoc/docker.log && free -h"
82+ sleep 20
83+ # print last line of log output and free memory
84+ $SSH "tail -n1 src/pandoc/docker.log && free -h | grep Mem"
7985 # Check to see if the artifact has been produced
80− $SSH "ls -l linux/artifacts/*.tar.gz" && break
86+ $SSH "ls -l src/pandoc/linux/artifacts/*.tar.gz 2>/dev/null" && break
8187done
8288
8389# Retrieve the artifacts
8490
8591echo "Successful build. Retrieving artifacts..."
8692
87−$SCP -r src/pandoc/linux/artifacts "arm-build-artifacts-$(date +%s)"
93+scp -i "$HOME/.ssh/$KEY_NAME.pem" -r "admin@$IPADDR:src/pandoc/linux/artifacts" "arm-build-artifacts-$(date +%s)"
8894
8995exit 0