Skip to content

Instantly share code, notes, and snippets.

@sallyom
Last active July 11, 2016 20:28
Show Gist options
  • Save sallyom/305e07eba559dd8e1f1a52988b990158 to your computer and use it in GitHub Desktop.
Save sallyom/305e07eba559dd8e1f1a52988b990158 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 1) Make sure you fill in all env vars in online_env.conf in same directory as this script
# 2) Make sure you run 'git submodule update --init --recursive' in your online repo before running this script
# 3) Keep your local online repo up to date, as this script tars up your local online repo, otherwise you'd need to have git ssh keys set up with VM
set -o errexit
set -o nounset
set -o pipefail
# read creds, urls, branches from 'online_env' in same dir as this script...
set -o allexport
source online_env.conf
set +o allexport
# Provision rhel online_dev instance in AWS
instance_id=`ec2-run-instances ami-68fb7d7f --key libra -t t2.large -s subnet-cf57c596 -g sg-7e73221a -g sg-5875023f -g sg-e1760186 | grep INSTANCE | awk '{print$2}'`
#instance_id=<> #fill this in and comment 'instance_id...' line above to use already existing instance
echo "Instance ID: $instance_id"
ec2addtag $instance_id --tag Name=$TAG
echo
echo "Tagging $instance_id $TAG"
public_DNS=`ec2-describe-instances $instance_id | grep INSTANCE | awk '{print$4}'`
echo
echo "Public DNS of $TAG: $public_DNS"
set -x
# Need to tar online repo and scp, or else we'd need ssh keys set up in github
pushd $PATH_TO_REPOS/online > /dev/null
git checkout $ONLINE_BRANCH
pushd ../ > /dev/null
tar -cf online.tar online/
popd > /dev/null
popd > /dev/null
echo "Waiting for amazon instance to be available..."
sleep 15
scp -i ~/.ssh/libra.pem online_env.conf ec2-user@${public_DNS}:~/.
ssh -i ~/.ssh/libra.pem ec2-user@${public_DNS} "sudo mkdir -p $PATH_TO_REPOS && sudo chmod 777 $PATH_TO_REPOS"
pushd $PATH_TO_REPOS > /dev/null
scp -i ~/.ssh/libra.pem online.tar ec2-user@${public_DNS}:$PATH_TO_REPOS
popd > /dev/null
ssh -i ~/.ssh/libra.pem ec2-user@${public_DNS} "pushd $PATH_TO_REPOS > /dev/null && sudo tar -xf online.tar && popd > /dev/null"
ssh -i ~/.ssh/libra.pem ec2-user@${public_DNS} "pushd $PATH_TO_REPOS > /dev/null && git clone $ORIGIN_URL && pushd origin && git checkout $ORIGIN_BRANCH && popd > /dev/null && popd > /dev/null"
ssh -i ~/.ssh/libra.pem ec2-user@${public_DNS} "curl -o onlineUp.sh $ONLINE_UP_SH_URL; chmod +x onlineUp.sh"
echo "Now running onlineUp.sh to set up Online environment"
ssh -i ~/.ssh/libra.pem ec2-user@${public_DNS} "sudo ./onlineUp.sh"
set +x
echo "All Set! ssh into your ec2 instance and check out your running Online All-In-One cluster (ssh -i /path/to/libra.pem ec2-user@public_DNS)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment