deploy-infra.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. source bash-config.cfg
  3. ACCOUNT_ID=$(aws sts get-caller-identity --profile $CLI_PROFILE --query Account --output text)
  4. NEW_STACK_NAME="${STACK_NAME}-${ACCOUNT_ID}"
  5. # Deploy the CloudFormation template
  6. echo -e "\n\n=========== Deploying main.yml ==========="
  7. aws cloudformation deploy \
  8. --region $REGION \
  9. --profile $CLI_PROFILE \
  10. --stack-name $NEW_STACK_NAME \
  11. --template-file main.yml \
  12. --no-fail-on-empty-changeset \
  13. --capabilities CAPABILITY_NAMED_IAM \
  14. --parameter-overrides \
  15. EC2InstanceType=$EC2_INSTANCE_TYPE \
  16. KeyName=$AWS_KEY_PAIR_NAME \
  17. EC2AMI=$EC2_AMI_ID
  18. # If the deploy succeeded, get the IP, create inventory and configure the created instances
  19. if [ $? -eq 0 ]; then
  20. aws cloudformation list-exports \
  21. --profile $CLI_PROFILE \
  22. --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}PublicIp')].Value" \
  23. --output text | sed 's/\t\t*/\n/g' > inventory
  24. if [ -z "$EC2_AMI_ID" ]
  25. then
  26. echo -e "\n\n=========== Configuring the servers ==========="
  27. ansible-playbook -i inventory --private-key $KEY_PATH build-code.yml --extra-vars "branch_name=$BRANCH_NAME"
  28. fi
  29. echo -e "\n\n=========== Configuring the chain spec file ==========="
  30. ansible-playbook -i inventory --private-key $KEY_PATH chain-spec-configuration.yml \
  31. --extra-vars "local_dir=$LOCAL_CODE_PATH network_suffix=$NETWORK_SUFFIX data_path=data-$NEW_STACK_NAME"
  32. fi