git.iko.soy/typeable/pandoc
on 2.14 help sign in
typeable/pandoc/tools/build-arm.sh
108 lines 3.2 kB history raw
1#!/bin/sh
3IMAGE_ID=ami-0fa8979d18f69948b
4INSTANCE_TYPE=t4g.2xlarge
5KEY_NAME=debian-arm-us-east-2
6SECURITY_GROUP_ID=sg-086ffbadc286c5c00
7ARTIFACTS="${ARTIFACTS:-build-artifacts-$(date +%s)}"
9STARTTIME=$(date +%H:%M)
11# Spin up an ARM build machine using aws cli, build pandoc, and
12# download the artifact.
14# We need to use us-east-2; since my us-west-1 has EC2-classic.
15# docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-classic-platform.html
17aws configure set default.region us-east-2
19echo "Creating instance..."
21aws 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
23jq < ec2.json
25# Now get the public IP address.
27INSTANCEID=$(jq '.Instances[0].InstanceId' ec2.json | sed -e 's/"//g')
28IPADDR=$(aws ec2 describe-instances --instance-ids="$INSTANCEID" --query 'Reservations[0].Instances[0].PublicIpAddress' | sed -e 's/"//g')
30echo "IP address is $IPADDR"
32clean_up() {
33 echo "Terminating the instance in 20 seconds..."
34 echo "Ctrl-C to preserve it."
35 sleep 20 && aws ec2 terminate-instances --instance-ids "$INSTANCEID"
37trap clean_up EXIT
39echo "Waiting for instance to start up..."
41STATUS=none
42while [ "$STATUS" != "running" ]
43do
44 sleep 20
45 STATUS=$(aws ec2 describe-instance-status --instance-id "$INSTANCEID" | jq '.InstanceStatuses[0].InstanceState.Name' | sed -e 's/"//g')
46 echo "...$STATUS"
47done
49# At this point you can connect via SSH, or run this script:
50# $ ssh -i ~/.ssh/debian-arm-us-east-2.pem admin@$IPADDR
52ssh -o "StrictHostKeyChecking=no" -i "~/.ssh/$KEY_NAME.pem" admin@$IPADDR uname -a
54SSH="ssh -i ~/.ssh/$KEY_NAME.pem admin@$IPADDR"
56echo "Provisioning..."
58$SSH <<EOF
59sudo apt-get update
60sudo apt-get upgrade -y
61sudo apt-get install -y apt-transport-https ca-certificates curl gnupg git make
62curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
63echo \
64 "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
65 \$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
66sudo apt-get update
67sudo apt-get install -y docker-ce docker-ce-cli containerd.io
68sudo groupadd docker
69sudo usermod -aG docker admin
70EOF
72echo "Building..."
74($SSH <<EOF
75mkdir src
76cd src || exit
77git clone https://github.com/jgm/pandoc
78cd pandoc || exit
79make debpkg
80EOF
81) &
83# Now we need to wait for the build to complete (this can take 3 hours).
85while true
86do
87 sleep 20
88 # print last line of log output and free memory
89 $SSH "tail -n1 src/pandoc/docker.log && free -h | grep Mem"
90 # Check to see if the artifact has been produced
91 $SSH "ls -l src/pandoc/linux/artifacts/DONE 2>/dev/null" && break
92done
94# Retrieve the artifacts
96echo "Successful build. Retrieving artifacts..."
98scp -i "$HOME/.ssh/$KEY_NAME.pem" -r "admin@$IPADDR:src/pandoc/linux/artifacts" "$ARTIFACTS"
100echo "Artifacts saved in $ARTIFACTS"
101ls "$ARTIFACTS"
103ENDTIME=$(date +%H:%M)
105echo "Started: $STARTTIME"
106echo "Finished: $ENDTIME"
108exit 0