Browse Source

Move variables to bash, add delete stack script, change playbook name

Anuj Bansal 3 years ago
parent
commit
920d0e3c64

+ 9 - 1
devops/infrastructure/bash-config.sample.cfg

@@ -5,11 +5,19 @@ REGION=us-east-1
 CLI_PROFILE=joystream-user
 KEY_PATH="/Users/joystream/Joystream/joystream-key.pem"
 AWS_KEY_PAIR_NAME="joystream-key"
-EC2_INSTANCE_TYPE=t2.xlarge
+EC2_INSTANCE_TYPE=t2.micro
 
 # Set a prebuilt AMI if required
 EC2_AMI_ID="ami-064f99551235fb1ac"
 
+ACCOUNT_ID=$(aws sts get-caller-identity --profile $CLI_PROFILE --query Account --output text)
+
+NEW_STACK_NAME="${STACK_NAME}-${ACCOUNT_ID}"
+
+DATA_PATH="data-$NEW_STACK_NAME"
+
+INVENTORY_PATH="$DATA_PATH/inventory"
+
 #### PARAMETERS USED BY ANSIBLE
 
 LOCAL_CODE_PATH="~/Joystream/joystream"

+ 1 - 1
devops/infrastructure/chain-spec-configuration.yml → devops/infrastructure/chain-spec-pioneer.yml

@@ -1,5 +1,5 @@
 ---
-# Configure chain spec and start joystream-node service on the servers
+# Configure chain spec, start joystream-node service on the servers and build Pioneer
 
 - name: Create and copy the chain-spec file
   hosts: all

+ 38 - 0
devops/infrastructure/delete-stack.sh

@@ -0,0 +1,38 @@
+#!/bin/bash
+
+set -e
+
+if [ -z "$1" ]; then
+  echo "ERROR: Configuration file not passed"
+  echo "Please use ./delete-stack.sh PATH/TO/CONFIG to run this script"
+  exit 1
+else
+  echo "Using $1 file for config"
+  source $1
+fi
+
+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"
+}
+
+BUCKET_NAME=$(get_aws_export "S3BucketName")
+
+# Delete the CloudFormation stack
+
+echo -e "\n\n=========== Emptying bucket $BUCKET_NAME ==========="
+
+aws s3 rm s3://$BUCKET_NAME --recursive --profile $CLI_PROFILE
+
+echo -e "\n\n=========== Deleting stack $NEW_STACK_NAME ==========="
+
+aws cloudformation delete-stack --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
+
+echo -e "\n\n=========== Waiting for stack deletion to complete ==========="
+
+aws cloudformation wait stack-delete-complete --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
+
+echo -e "\n\n=========== Stack $NEW_STACK_NAME deleted ==========="

+ 0 - 8
devops/infrastructure/deploy-infra.sh

@@ -11,14 +11,6 @@ else
   source $1
 fi
 
-ACCOUNT_ID=$(aws sts get-caller-identity --profile $CLI_PROFILE --query Account --output text)
-
-NEW_STACK_NAME="${STACK_NAME}-${ACCOUNT_ID}"
-
-DATA_PATH="data-$NEW_STACK_NAME"
-
-INVENTORY_PATH="$DATA_PATH/inventory"
-
 if [ $ACCOUNT_ID == None ]; then
     echo "Couldn't find Account ID, please check if AWS Profile $CLI_PROFILE is set"
     exit 1