github.com/gorgonia/agogo@v0.1.1/deploy/componenttester/componenttester.sh (about) 1 #!/usr/local/bin/bash 2 #set -x 3 4 # Create functions to backup/restore the cfn template 5 function backup { 6 echo "" 7 echo "Backing up Cloudformation template and updating with vars" 8 echo "" 9 if cp componenttester.yaml componenttester.yaml.bak; then 10 echo "Backup successful" 11 echo "" 12 else 13 echo "Backup failed!" 14 exit 1 15 fi 16 } 17 18 function restore { 19 echo "" 20 echo "Restoring Cloudformation template to defaults" 21 echo "" 22 if mv componenttester.yaml.bak componenttester.yaml; then 23 echo "Restore successful" 24 else 25 echo "Restore failed! Check file and do a git --reset" 26 exit 1 27 fi 28 } 29 30 # Script description, read in the vars 31 clear 32 echo "###########################################" 33 echo "## Welcome to the agogo component tester ##" 34 echo "###########################################" 35 echo "" 36 echo "This script will:" 37 echo " - ask you for some inputs" 38 echo " - spin up an ec2 instance" 39 echo " - run trace/cpuprofile tests" 40 echo " - zip up the output and upload to s3" 41 echo " - pull down the zip to your cwd" 42 echo "" 43 read -p "Press enter to start" 44 45 echo "" 46 echo "" 47 echo "Input values for the cfn template, press enter to accept the default" 48 echo "" 49 read -p "Branch of gorgonia.org/tensor: " -e -i "v0.9.0-working" TENSORBRANCH 50 read -p "Branch of gorgonia.org/gorgonia: " -e -i "concurrentTapeMachine" GORGBRANCH 51 read -p "Component: " -e -i "dualnet" COMPONENT 52 echo "" 53 read -p "Instance type: " -e -i "p2.8xlarge" INSTANCETYPE 54 read -p "Keypair: " -e -i "deploy-ap-southeast-2" KEYPAIR 55 read -p "Profile name in $HOME/.aws/credentials: " -e -i "agogo" PROFILE 56 EC2KEY=`grep -A3 $PROFILE $HOME/.aws/credentials | grep aws_access | cut -d' ' -f3` 57 EC2SECRET=`grep -A3 $PROFILE $HOME/.aws/credentials | grep aws_secret | cut -d' ' -f3` 58 echo "" 59 read -p "GitHub User: " -e -i "username" GITUSER 60 read -p "GitHub Password: " -e -i "password" GITPASS 61 echo "" 62 63 # Backup and do cfn template subs 64 backup 65 if sed -i "" -e "s#TENSORBRANCH#$TENSORBRANCH#g" -e "s#GORGBRANCH#$GORGBRANCH#g" -e "s#COMPONENT#$COMPONENT#g" -e "s#INSTANCETYPE#$INSTANCETYPE#g" -e "s#EC2KEY#$EC2KEY#g" -e "s#EC2SECRET#$EC2SECRET#g" -e "s#KEYPAIR#$KEYPAIR#g" -e "s#GITUSER#$GITUSER#g" -e "s#GITPASS#$GITPASS#g" componenttester.yaml; then 66 echo "Cloudformation template var substitutions successful" 67 echo "" 68 else 69 echo "Cloudformation template var substitutions failed!" 70 exit 1 71 fi 72 73 # Create stack, confirm successful 74 read -p "Enter name for your Cloudformation stack: " -e -i "Test-TraceProfile" STACKNAME 75 echo "" 76 echo "Now creating stack..." 77 echo "" 78 if aws cloudformation create-stack --stack-name $STACKNAME --template-body file://componenttester.yaml --profile $PROFILE; then 79 echo "" 80 echo "Cloudformation request successful" 81 else 82 echo "Cloudformation request failed!" 83 restore 84 exit 1 85 fi 86 87 # Wait for stack to get created before executing rest of script 88 echo "" 89 echo "Now deploying AWS resources & running tests, can take 10-15mins..." 90 echo "" 91 if aws cloudformation wait stack-create-complete --stack-name $STACKNAME --profile $PROFILE; then 92 echo "Tests complete!" 93 else 94 echo "Tests failed! Examine deploy.out or hit up Gareth on Slack" 95 fi 96 97 # Pull down latest file from S3, could be traces or the output of errors from the instance 98 echo "" 99 echo "Pulling down latest file from S3:" 100 S3OBJECT=`aws s3 ls s3://agogo-testing --recursive --profile $PROFILE | sort | tail -n 1 | awk '{print $4}'` 101 if aws s3 cp "s3://agogo-testing/$S3OBJECT" ./ --profile $PROFILE; then 102 echo "Copy successful" 103 else 104 echo "Copy of $S3OBJECT to cwd failed!" 105 restore 106 exit 1 107 fi 108 109 # Delete stack 110 read -p "Press enter to delete stack or 'x' to quit: " DEL 111 if [ "$DEL" != "x" ]; then 112 echo "" 113 echo "Deleting stack, waiting for DELETE_COMPLETE" 114 echo "" 115 aws cloudformation delete-stack --stack-name $STACKNAME --profile $PROFILE 116 if aws cloudformation wait stack-delete-complete --stack-name $STACKNAME --profile $PROFILE; then 117 echo "Stack $STACKNAME deleted." 118 echo "All outputs contained in $S3OBJECT" 119 restore 120 exit 0 121 else 122 echo "Stack deletion failed! Manually delete $STACKNAME" 123 restore 124 exit 1 125 fi 126 fi