deploy-infra.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -e
  3. if [ -z "$1" ]; then
  4. echo "ERROR: Configuration file not passed"
  5. echo "Please use ./deploy-infra.sh PATH/TO/CONFIG to run this script"
  6. exit 1
  7. else
  8. echo "Using $1 file for config"
  9. source $1
  10. fi
  11. if [ $ACCOUNT_ID == None ]; then
  12. echo "Couldn't find Account ID, please check if AWS Profile $CLI_PROFILE is set"
  13. exit 1
  14. fi
  15. if [ ! -f "$KEY_PATH" ]; then
  16. echo "Key file not found at $KEY_PATH"
  17. exit 1
  18. fi
  19. get_aws_export () {
  20. RESULT=$(aws cloudformation list-exports \
  21. --profile $CLI_PROFILE \
  22. --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}$1')].Value" \
  23. --output text | sed 's/\t\t*/\n/g')
  24. echo -e $RESULT | tr " " "\n"
  25. }
  26. # Deploy the CloudFormation template
  27. echo -e "\n\n=========== Deploying main.yml ==========="
  28. aws cloudformation deploy \
  29. --region $REGION \
  30. --profile $CLI_PROFILE \
  31. --stack-name $NEW_STACK_NAME \
  32. --template-file main.yml \
  33. --no-fail-on-empty-changeset \
  34. --capabilities CAPABILITY_NAMED_IAM \
  35. --parameter-overrides \
  36. EC2InstanceType=$EC2_INSTANCE_TYPE \
  37. KeyName=$AWS_KEY_PAIR_NAME \
  38. EC2AMI=$EC2_AMI_ID
  39. # If the deploy succeeded, get the IP, create inventory and configure the created instances
  40. if [ $? -eq 0 ]; then
  41. # Install additional Ansible roles from requirements
  42. ansible-galaxy install -r requirements.yml
  43. VALIDATORS=$(get_aws_export "PublicIp")
  44. RPC_NODES=$(get_aws_export "RPCPublicIp")
  45. BUILD_SERVER=$(get_aws_export "BuildPublicIp")
  46. BUCKET_NAME=$(get_aws_export "S3BucketName")
  47. DOMAIN_NAME=$(get_aws_export "DomainName")
  48. mkdir -p $DATA_PATH
  49. echo -e "[build]\n$BUILD_SERVER\n\n[validators]\n$VALIDATORS\n\n[rpc]\n$RPC_NODES" > $INVENTORY_PATH
  50. if [ -z "$EC2_AMI_ID" ]
  51. then
  52. echo -e "\n\n=========== Configuring the node servers ==========="
  53. ansible-playbook -i $INVENTORY_PATH --private-key $KEY_PATH build-code.yml --extra-vars "branch_name=$BRANCH_NAME git_repo=$GIT_REPO build_local_code=$BUILD_LOCAL_CODE"
  54. fi
  55. echo -e "\n\n=========== Configuring the Build server ==========="
  56. ansible-playbook -i $INVENTORY_PATH --private-key $KEY_PATH setup-admin.yml \
  57. --extra-vars "local_dir=$LOCAL_CODE_PATH build_local_code=$BUILD_LOCAL_CODE"
  58. echo -e "\n\n=========== Configuring the chain spec file and Pioneer app ==========="
  59. ansible-playbook -i $INVENTORY_PATH --private-key $KEY_PATH chain-spec-configuration.yml \
  60. --extra-vars "local_dir=$LOCAL_CODE_PATH network_suffix=$NETWORK_SUFFIX data_path=data-$NEW_STACK_NAME bucket_name=$BUCKET_NAME"
  61. echo -e "\n\n Pioneer URL: https://$DOMAIN_NAME"
  62. fi