Browse Source

Merge pull request #3140 from ahhda/query-node-cf

DevOps - Add query node to CloudFormation node-network deployment [WIP]
Mokhtar Naamani 3 years ago
parent
commit
77a0d58bb4

+ 17 - 0
devops/aws/cloudformation/infrastructure.yml

@@ -128,6 +128,23 @@ Resources:
             # Install the updates
             apt-get upgrade -y
 
+            apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
+
+            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
+
+            echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
+
+            apt-get update -y
+
+            apt-get install -y docker-ce docker-ce-cli containerd.io
+
+            usermod -aG docker ubuntu
+
+            # Update docker-compose to 1.28+
+            curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+            chmod +x /usr/local/bin/docker-compose
+            ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
+
             # Get latest cfn scripts and install them;
             apt-get install -y python3-setuptools
             mkdir -p /opt/aws/bin

+ 38 - 0
devops/aws/roles/rpc/tasks/main.yml

@@ -22,10 +22,48 @@
     enabled: yes
   become: yes
 
+- name: Build required packages
+  shell: yarn build:packages
+  args:
+    chdir: '{{ remote_code_path }}'
+  # Run in async fashion for max duration of 1 hr
+  async: 3600
+  poll: 0
+  register: build_result
+
+- name: Check on build async task
+  async_status:
+    jid: '{{ build_result.ansible_job_id }}'
+  register: job_result
+  until: job_result.finished
+  # Max number of times to check for status
+  retries: 36
+  # Check for the status every 100s
+  delay: 100
+
+- name: Run query node containers
+  command: yarn workspace query-node-root start:dev
+  args:
+    chdir: '{{ remote_code_path }}'
+  async: 1800
+  poll: 0
+  register: compose_result
+
+- name: Check on yarn start task
+  async_status:
+    jid: '{{ compose_result.ansible_job_id }}'
+  register: job_result
+  until: job_result.finished
+  # Max number of times to check for status
+  retries: 18
+  # Check for the status every 100s
+  delay: 100
+
 - name: Set websocket and http endpoint variables
   set_fact:
     ws_rpc: "{{ inventory_hostname }}.nip.io/ws-rpc"
     http_rpc: "{{ inventory_hostname }}.nip.io/http-rpc"
+    nip_domain: "{{ inventory_hostname }}.nip.io"
   run_once: yes
 
 - name: Install and configure Caddy

+ 14 - 0
devops/aws/roles/rpc/templates/Caddyfile.j2

@@ -5,3 +5,17 @@
 {{ http_rpc }} {
     reverse_proxy localhost:9933
 }
+
+{{ nip_domain }}/@apollographql/* {
+    reverse_proxy localhost:8081
+}
+
+{{ nip_domain }}/query-node/server* {
+    uri strip_prefix /query-node/server
+    reverse_proxy localhost:8081
+}
+
+{{ nip_domain }}/query-node/indexer* {
+    uri strip_prefix /query-node/indexer
+    reverse_proxy localhost:4000
+}