deploy-infra.sh 1.5 KB

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