Browse Source

Move common functions to separate file, add stack name parameter

Anuj Bansal 3 years ago
parent
commit
bb1a5fd6fb

+ 0 - 8
devops/infrastructure/bash-config.sample.cfg

@@ -41,11 +41,3 @@ BRANCH_NAME=sumer
 
 # If true will build LOCAL_CODE_PATH otherwise will pull from GIT_REPO:BRANCH_NAME
 BUILD_LOCAL_CODE=false
-
-get_aws_export () {
-  RESULT=$(aws cloudformation list-exports \
-    --profile $CLI_PROFILE \
-    --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}$1')].Value" \
-    --output text | sed 's/\t\t*/\n/g')
-  echo -e $RESULT | tr " " "\n"
-}

+ 9 - 0
devops/infrastructure/common.sh

@@ -0,0 +1,9 @@
+get_aws_export () {
+  STACK=$1
+  PROPERTY=$2
+  RESULT=$(aws cloudformation list-exports \
+    --profile $CLI_PROFILE \
+    --query "Exports[?starts_with(Name,'$STACK$PROPERTY')].Value" \
+    --output text | sed 's/\t\t*/\n/g')
+  echo -e $RESULT | tr " " "\n"
+}

+ 3 - 1
devops/infrastructure/delete-stack.sh

@@ -2,6 +2,8 @@
 
 set -e
 
+source common.sh
+
 if [ -z "$1" ]; then
   echo "ERROR: Configuration file not passed"
   echo "Please use ./delete-stack.sh PATH/TO/CONFIG to run this script"
@@ -11,7 +13,7 @@ else
   source $1
 fi
 
-BUCKET_NAME=$(get_aws_export "S3BucketName")
+BUCKET_NAME=$(get_aws_export $NEW_STACK_NAME "S3BucketName")
 
 # Delete the CloudFormation stack
 

+ 7 - 5
devops/infrastructure/deploy-infra.sh

@@ -2,6 +2,8 @@
 
 set -e
 
+source common.sh
+
 if [ -z "$1" ]; then
   echo "ERROR: Configuration file not passed"
   echo "Please use ./deploy-infra.sh PATH/TO/CONFIG to run this script"
@@ -44,7 +46,7 @@ if [ $? -eq 0 ]; then
   # Install additional Ansible roles from requirements
   ansible-galaxy install -r requirements.yml
 
-  ASG=$(get_aws_export "AutoScalingGroup")
+  ASG=$(get_aws_export $NEW_STACK_NAME "AutoScalingGroup")
 
   VALIDATORS=""
 
@@ -57,13 +59,13 @@ if [ $? -eq 0 ]; then
     VALIDATORS+="$IP\n"
   done
 
-  RPC_NODES=$(get_aws_export "RPCPublicIp")
+  RPC_NODES=$(get_aws_export $NEW_STACK_NAME "RPCPublicIp")
 
-  BUILD_SERVER=$(get_aws_export "BuildPublicIp")
+  BUILD_SERVER=$(get_aws_export $NEW_STACK_NAME "BuildPublicIp")
 
-  BUCKET_NAME=$(get_aws_export "S3BucketName")
+  BUCKET_NAME=$(get_aws_export $NEW_STACK_NAME "S3BucketName")
 
-  DOMAIN_NAME=$(get_aws_export "DomainName")
+  DOMAIN_NAME=$(get_aws_export $NEW_STACK_NAME "DomainName")
 
   mkdir -p $DATA_PATH
 

+ 1 - 1
devops/infrastructure/deploy-single-node.sh

@@ -40,7 +40,7 @@ if [ $? -eq 0 ]; then
   # Install additional Ansible roles from requirements
   ansible-galaxy install -r requirements.yml
 
-  SERVER_IP=$(get_aws_export "PublicIp")
+  SERVER_IP=$(get_aws_export $SINGLE_NODE_STACK_NAME "PublicIp")
 
   echo -e "New Node Public IP: $SERVER_IP"