Browse Source

Add admin instance based on config

Anuj Bansal 3 years ago
parent
commit
601a313c5d

+ 1 - 0
devops/infrastructure/bash-config.cfg

@@ -7,5 +7,6 @@ BRANCH_NAME=sumer
 LOCAL_CODE_PATH="~/Joystream/joystream"
 EC2_INSTANCE_TYPE=t2.xlarge
 NETWORK_SUFFIX=7891
+CREATE_ADMIN_SERVER=true
 # Set a prebuilt AMI if required
 EC2_AMI_ID="ami-064f99551235fb1ac"

+ 12 - 2
devops/infrastructure/deploy-infra.sh

@@ -30,7 +30,8 @@ aws cloudformation deploy \
   --parameter-overrides \
     EC2InstanceType=$EC2_INSTANCE_TYPE \
     KeyName=$AWS_KEY_PAIR_NAME \
-    EC2AMI=$EC2_AMI_ID
+    EC2AMI=$EC2_AMI_ID \
+    CreateAdminServer=$CREATE_ADMIN_SERVER
 
 # If the deploy succeeded, get the IP, create inventory and configure the created instances
 if [ $? -eq 0 ]; then
@@ -44,7 +45,16 @@ if [ $? -eq 0 ]; then
     --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}RPCPublicIp')].Value" \
     --output text | sed 's/\t\t*/\n/g')
 
-  echo -e "[validators]\n$VALIDATORS\n\n[rpc]\n$RPC_NODES" > inventory
+  if [ "$CREATE_ADMIN_SERVER" = true ] ; then
+    ADMIN_SERVER=$(aws cloudformation list-exports \
+      --profile $CLI_PROFILE \
+      --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}AdminPublicIp')].Value" \
+      --output text | sed 's/\t\t*/\n/g')
+    ADMIN_INVENTORY="[admin]\n$ADMIN_SERVER\n\n"
+    HOST="admin"
+  fi
+
+  echo -e "$ADMIN_INVENTORY[validators]\n$VALIDATORS\n\n[rpc]\n$RPC_NODES" > inventory
 
   if [ -z "$EC2_AMI_ID" ]
   then

+ 30 - 1
devops/infrastructure/main.yml

@@ -11,6 +11,16 @@ Parameters:
     Type: 'AWS::EC2::KeyPair::KeyName'
     Default: 'joystream-key'
     ConstraintDescription: must be the name of an existing EC2 KeyPair.
+  CreateAdminServer:
+    Description: Whether or not to create the admin instance for creating keys and chain-spec file
+    Type: String
+    AllowedValues: [true, false]
+    Default: false
+
+Conditions:
+  CreateAdminServerCondition: !Equals
+    - !Ref CreateAdminServer
+    - true
 
 Resources:
   SecurityGroup:
@@ -127,6 +137,17 @@ Resources:
         - Key: Name
           Value: !Sub '${AWS::StackName}_rpc'
 
+  AdminInstance:
+    Type: AWS::EC2::Instance
+    Condition: CreateAdminServerCondition
+    Properties:
+      LaunchTemplate:
+        LaunchTemplateId: !Ref InstanceLaunchTemplate
+        Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
+      Tags:
+        - Key: Name
+          Value: !Sub '${AWS::StackName}_admin'
+
   WaitHandle:
     Type: AWS::CloudFormation::WaitConditionHandle
 
@@ -135,7 +156,8 @@ Resources:
     Properties:
       Handle: !Ref 'WaitHandle'
       Timeout: '600'
-      Count: 3
+      Count:
+        !If [CreateAdminServerCondition, 4, 3]
 
 Outputs:
   PublicIp:
@@ -155,3 +177,10 @@ Outputs:
     Value:  !Sub "${RPCInstance.PublicIp}"
     Export:
       Name: !Sub "${AWS::StackName}RPCPublicIp"
+
+  AdminPublicIp:
+    Description: The DNS name for the created instance
+    Value:  !Sub "${AdminInstance.PublicIp}"
+    Condition: CreateAdminServerCondition
+    Export:
+      Name: !Sub "${AWS::StackName}AdminPublicIp"