Browse Source

Extract variables out of playbooks, add branch checkout feature

Anuj Bansal 3 years ago
parent
commit
28ba8501ec

+ 6 - 2
devops/infrastructure/configure.yml → devops/infrastructure/build-code.yml

@@ -1,7 +1,10 @@
 ---
 
-- name: Configure Joystream Node
+- name: Get latest Joystream code and build it
   hosts: all
+  vars:
+    # branch_name can be sha1, tag, branch
+    branch_name: "master"
   tasks:
     - name: Creat bash profile file
       command: "touch /home/ubuntu/.bash_profile"
@@ -9,11 +12,12 @@
       ansible.builtin.git:
         repo: 'https://github.com/Joystream/joystream.git'
         dest: ~/joystream
+        version: "{{ branch_name }}"
     - name: Run setup script
       command: ./setup.sh
       args:
         chdir: ~/joystream
     - name: Build joystream node
-      shell: . ~/.bash_profile && yarn cargo-build >> output.log
+      shell: . ~/.bash_profile && yarn cargo-build
       args:
         chdir: ~/joystream

+ 14 - 8
devops/infrastructure/chain-spec-configuration.yml

@@ -1,12 +1,14 @@
 - name: Configure chain spec on the deployed servers
   hosts: all
   vars:
-    base_dir: ~/Joystream/joystream
-    random_suffix: 5154
-    change_spec_path: ./data/chainspec.json
+    local_dir: ~/Joystream/joystream
+    # Generates random number between 1000..9999
+    random_suffix: "{{ 10000 | random(1000) }}"
+    data_path: ./data
+    change_spec_path: "{{ data_path }}/chainspec.json"
   tasks:
   - name: Run subkey to generate node keys
-    local_action: ansible.builtin.command {{ base_dir }}/target/release/chain-spec-builder generate -a 2 --chain-spec-path {{ change_spec_path }} --deployment live --endowed 1 --keystore-path ./data/
+    local_action: ansible.builtin.command {{ local_dir }}/target/release/chain-spec-builder generate -a 2 --chain-spec-path {{ change_spec_path }} --deployment live --endowed 1 --keystore-path {{ data_path }}
     register: chain_spec_output
     run_once: true
 
@@ -21,9 +23,12 @@
       - "Private Key: {{ subkey_output.stdout }}"
 
   - name: Print to stdout chain spec
-    debug: var=chain_spec_output
+    debug: var=chain_spec_output.stdout
     run_once: true
 
+  - name: Save output of chain spec to local file
+    local_action: copy content={{ chain_spec_output.stdout }} dest=./chain_spec_output.txt
+
   - name: Change chain spec name, id, protocolId
     delegate_to: localhost
     json_modify:
@@ -33,8 +38,9 @@
     register: result
     run_once: true
 
-  - debug:
-      var: result
+  - name: Print output of modified chainspec
+    debug:
+      var: result.result
 
   - name: Copying chain spec file to server
     copy:
@@ -55,5 +61,5 @@
 
   - name: Copy auth directory to remote host
     copy:
-      src: "./data/auth-{{ ansible_play_batch.index(inventory_hostname) }}/"
+      src: "{{ data_path }}/auth-{{ ansible_play_batch.index(inventory_hostname) }}/"
       dest: "~/joystream/chains/{{ result.result.id }}/keystore/"

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

@@ -3,7 +3,11 @@
 STACK_NAME=joystream-node
 REGION=us-east-1
 CLI_PROFILE=joystream-user
-KEY_PATH=""
+KEY_PATH="./joystream-key.pem"
+
+BRANCH_NAME=sumer
+
+LOCAL_CODE_PATH="~/Joystream/joystream"
 
 EC2_INSTANCE_TYPE=t2.xlarge
 
@@ -19,7 +23,7 @@ aws cloudformation deploy \
   --parameter-overrides \
     EC2InstanceType=$EC2_INSTANCE_TYPE
 
-# If the deploy succeeded, show the DNS name of the created instance
+# If the deploy succeeded, get the IP, create inventory and configure the created instances
 if [ $? -eq 0 ]; then
   aws cloudformation list-exports \
     --profile $CLI_PROFILE \
@@ -27,8 +31,8 @@ if [ $? -eq 0 ]; then
     --output text | sed 's/\t\t*/\n/g' > inventory
 
   echo -e "\n\n=========== Configuring the servers ==========="
-  ansible-playbook -i inventory -v --private-key $KEY_PATH configure.yml
+  ansible-playbook -i inventory -v --private-key $KEY_PATH build-code.yml --extra-vars "branch_name=$BRANCH_NAME"
 
   echo -e "\n\n=========== Configuring the chain spec file ==========="
-  ansible-playbook -i inventory -v --private-key $KEY_PATH chain-spec-configuration.yml
+  ansible-playbook -i inventory -v --private-key $KEY_PATH chain-spec-configuration.yml --extra-vars "local_dir=$LOCAL_CODE_PATH"
 fi