Browse Source

Add single instance deployment support

Anuj Bansal 3 years ago
parent
commit
1437a7faf9

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

@@ -23,6 +23,14 @@ INVENTORY_PATH="$DATA_PATH/inventory"
 
 NUMBER_OF_VALIDATORS=2
 
+## Used for Deploying a new node
+DATE_TIME=$(date +"%d-%b-%Y-%H-%M-%S")
+
+SINGLE_NODE_STACK_NAME="new-node-$DATE_TIME"
+
+BINARY_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joystream-node-5.1.0-9d9e77751-x86_64-linux-gnu.tar.gz"
+CHAIN_SPEC_FILE="https://github.com/Joystream/joystream/releases/download/v9.3.0/joy-testnet-5.json"
+
 #### PARAMETERS USED BY ANSIBLE
 
 LOCAL_CODE_PATH="~/Joystream/joystream"
@@ -33,3 +41,11 @@ 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"
+}

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

@@ -11,14 +11,6 @@ else
   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

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

@@ -21,14 +21,6 @@ if [ ! -f "$KEY_PATH" ]; then
     exit 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"
-}
-
 # Deploy the CloudFormation template
 echo -e "\n\n=========== Deploying main.yml ==========="
 aws cloudformation deploy \

+ 51 - 0
devops/infrastructure/deploy-single-node.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+
+set -o xtrace
+set -e
+
+if [ -z "$1" ]; then
+  echo "ERROR: Configuration file not passed"
+  echo "Please use ./deploy-infra.sh PATH/TO/CONFIG to run this script"
+  exit 1
+else
+  echo "Using $1 file for config"
+  source $1
+fi
+
+if [ $ACCOUNT_ID == None ]; then
+    echo "Couldn't find Account ID, please check if AWS Profile $CLI_PROFILE is set"
+    exit 1
+fi
+
+if [ ! -f "$KEY_PATH" ]; then
+    echo "Key file not found at $KEY_PATH"
+    exit 1
+fi
+
+# # Deploy the CloudFormation template
+# echo -e "\n\n=========== Deploying single instance ==========="
+# aws cloudformation deploy \
+#   --region $REGION \
+#   --profile $CLI_PROFILE \
+#   --stack-name $NEW_STACK_NAME \
+#   --template-file single-instance.yml \
+#   --no-fail-on-empty-changeset \
+#   --capabilities CAPABILITY_NAMED_IAM \
+#   --parameter-overrides \
+#     EC2InstanceType=$DEFAULT_EC2_INSTANCE_TYPE \
+#     KeyName=$AWS_KEY_PAIR_NAME \
+#     EC2AMI=$EC2_AMI_ID
+
+# If the deploy succeeded, get the IP, create inventory and configure the created instances
+if [ $? -eq 0 ]; then
+  # Install additional Ansible roles from requirements
+  # ansible-galaxy install -r requirements.yml
+
+  SERVER_IP=$(get_aws_export "PublicIp")
+
+  echo -e "New Node Public IP: $SERVER_IP"
+
+  echo -e "\n\n=========== Configuring the chain spec file and Pioneer app ==========="
+  ansible-playbook -i $SERVER_IP, --private-key $KEY_PATH new-node-playbook.yml \
+    --extra-vars "binary_file=$BINARY_FILE chain_spec_file=$CHAIN_SPEC_FILE"
+fi

+ 48 - 0
devops/infrastructure/new-node-playbook.yml

@@ -0,0 +1,48 @@
+---
+# Configure chain spec file, copy joystream-node binary and run the service
+
+- name: Create and copy the chain-spec file
+  hosts: all
+  gather_facts: no
+
+  tasks:
+    - name: Download chain spec file using link
+      get_url:
+        url: "{{ chain_spec_file }}"
+        dest: ~/chain-spec.json
+      when: chain_spec_file is search("http")
+
+    - name: Copy chain spec file from local
+      copy:
+        src: "{{ chain_spec_file }}"
+        dest: ~/chain-spec.json
+      when: chain_spec_file is not search("http")
+
+    - name: Download and unarchive binary using link
+      unarchive:
+        src: "{{ binary_file }}"
+        dest: ~/
+        remote_src: yes
+      when: binary_file is search("http")
+
+    - name: Copy binary from local
+      copy:
+        src: "{{ binary_file }}"
+        dest: ~/joystream-node
+        mode: "0775"
+      when: binary_file is not search("http")
+
+    - name: Create a service file
+      template:
+        src: roles/node/templates/joystream-node.service.j2
+        dest: /etc/systemd/system/joystream-node.service
+      vars:
+        template_remote_chain_spec_path: "/home/ubuntu/chain-spec.json"
+        template_binary_path: "/home/ubuntu/joystream-node"
+      become: yes
+
+    - name: Start service joystream-node, if not started
+      service:
+        name: joystream-node
+        state: started
+      become: yes

+ 18 - 0
devops/infrastructure/roles/node/templates/joystream-node.service.j2

@@ -0,0 +1,18 @@
+[Unit]
+Description=Joystream Node
+After=network.target
+
+[Service]
+Type=simple
+User=ubuntu
+WorkingDirectory=/home/ubuntu/
+ExecStart={{ template_binary_path }} \
+        --chain {{ template_remote_chain_spec_path }} \
+        --pruning archive \
+        --log runtime,txpool,transaction-pool,trace=sync
+Restart=on-failure
+RestartSec=3
+LimitNOFILE=10000
+
+[Install]
+WantedBy=multi-user.target

+ 2 - 0
devops/infrastructure/single-instance.yml

@@ -100,6 +100,8 @@ Outputs:
   PublicIp:
     Description: The DNS name for the created instance
     Value:  !Sub "${Instance.PublicIp}"
+    Export:
+      Name: !Sub "${AWS::StackName}PublicIp"
 
   InstanceId:
     Description: The Instance ID