Browse Source

Add instance type option for RPC, Validator instances

Anuj Bansal 3 years ago
parent
commit
123a39ce0b

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

@@ -5,8 +5,10 @@ REGION=us-east-1
 CLI_PROFILE=joystream-user
 KEY_PATH="/Users/joystream/Joystream/joystream-key.pem"
 AWS_KEY_PAIR_NAME="joystream-key"
-NODE_EC2_INSTANCE_TYPE=t2.micro
+DEFAULT_EC2_INSTANCE_TYPE=t2.micro
+VALIDATOR_EC2_INSTANCE_TYPE=t2.micro
 BUILD_EC2_INSTANCE_TYPE=t2.xlarge
+RPC_EC2_INSTANCE_TYPE=t2.micro
 
 # Set a prebuilt AMI if required
 EC2_AMI_ID="ami-064f99551235fb1ac"

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

@@ -39,7 +39,9 @@ aws cloudformation deploy \
   --no-fail-on-empty-changeset \
   --capabilities CAPABILITY_NAMED_IAM \
   --parameter-overrides \
-    EC2InstanceType=$NODE_EC2_INSTANCE_TYPE \
+    EC2InstanceType=$DEFAULT_EC2_INSTANCE_TYPE \
+    ValidatorEC2InstanceType=$VALIDATOR_EC2_INSTANCE_TYPE \
+    RPCEC2InstanceType=$RPC_EC2_INSTANCE_TYPE \
     BuildEC2InstanceType=$BUILD_EC2_INSTANCE_TYPE \
     KeyName=$AWS_KEY_PAIR_NAME \
     EC2AMI=$EC2_AMI_ID \
@@ -88,7 +90,8 @@ if [ $? -eq 0 ]; then
 
   echo -e "\n\n=========== Configuring the chain spec file and Pioneer app ==========="
   ansible-playbook -i $INVENTORY_PATH --private-key $KEY_PATH chain-spec-pioneer.yml \
-    --extra-vars "local_dir=$LOCAL_CODE_PATH network_suffix=$NETWORK_SUFFIX data_path=data-$NEW_STACK_NAME bucket_name=$BUCKET_NAME"
+    --extra-vars "local_dir=$LOCAL_CODE_PATH network_suffix=$NETWORK_SUFFIX
+                  data_path=data-$NEW_STACK_NAME bucket_name=$BUCKET_NAME number_of_validators=$NUMBER_OF_VALIDATORS"
 
   echo -e "\n\n Pioneer URL: https://$DOMAIN_NAME"
 fi

+ 1 - 0
devops/infrastructure/group_vars/all

@@ -16,5 +16,6 @@ remote_code_path: "/home/ubuntu/joystream"
 remote_chain_spec_path: "{{ remote_code_path }}/chainspec.json"
 run_on_admin_server: true
 build_local_code: false
+number_of_validators: 2
 
 bucket_name: s3-bucket-joystream

+ 16 - 3
devops/infrastructure/infrastructure.yml

@@ -3,8 +3,16 @@ AWSTemplateFormatVersion: 2010-09-09
 Parameters:
   EC2InstanceType:
     Type: String
+    Default: t2.micro
+  ValidatorEC2InstanceType:
+    Type: String
+    Default: t2.micro
+  RPCEC2InstanceType:
+    Type: String
+    Default: t2.micro
   BuildEC2InstanceType:
     Type: String
+    Default: t2.micro
   EC2AMI:
     Type: String
     Default: 'ami-09e67e426f25ce0d7'
@@ -124,9 +132,13 @@ Resources:
       AvailabilityZones:
         Fn::GetAZs:
           Ref: "AWS::Region"
-      LaunchTemplate:
-        LaunchTemplateId: !Ref InstanceLaunchTemplate
-        Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
+      MixedInstancesPolicy:
+        LaunchTemplate:
+          LaunchTemplateSpecification:
+            LaunchTemplateId: !Ref InstanceLaunchTemplate
+            Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
+          Overrides:
+            - InstanceType: !Ref ValidatorEC2InstanceType
       Tags:
         - Key: Name
           Value: !Sub '${AWS::StackName}'
@@ -137,6 +149,7 @@ Resources:
     Properties:
       SecurityGroupIds:
         - !GetAtt RPCSecurityGroup.GroupId
+      InstanceType: !Ref RPCEC2InstanceType
       LaunchTemplate:
         LaunchTemplateId: !Ref InstanceLaunchTemplate
         Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber

+ 4 - 0
devops/infrastructure/roles/admin/tasks/deploy-pioneer.yml

@@ -9,6 +9,10 @@
   shell: "WS_URL=wss://{{ ws_rpc }} yarn && yarn workspace @joystream/types build && yarn workspace pioneer build"
   args:
     chdir: "{{ remote_code_path }}"
+  retries: 3
+  delay: 5
+  register: result
+  until: result is not failed
 
 - name: Copying build files to local
   synchronize:

+ 1 - 1
devops/infrastructure/roles/common/tasks/chain-spec-node-keys.yml

@@ -7,7 +7,7 @@
   run_once: true
 
 - name: Run chain-spec-builder to generate chainspec.json file
-  command: "{{ admin_code_dir }}/target/release/chain-spec-builder generate -a 2 --chain-spec-path {{ chain_spec_path }} --deployment live --endowed 1 --keystore-path {{ data_path }}"
+  command: "{{ admin_code_dir }}/target/release/chain-spec-builder generate -a {{ number_of_validators }} --chain-spec-path {{ chain_spec_path }} --deployment live --endowed 1 --keystore-path {{ data_path }}"
   register: chain_spec_output
   delegate_to: "{{ local_or_admin }}"
   run_once: true