deploy-playground-playbook.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ---
  2. # Run the docker-compose setup on a new EC2 instance
  3. - name: Setup EC2 instance and start docker-compose services
  4. hosts: all
  5. gather_facts: yes
  6. tasks:
  7. - name: Get code from git repo
  8. include_role:
  9. name: common
  10. tasks_from: get-code-git
  11. - name: Create bash profile file
  12. command: 'touch /home/ubuntu/.bash_profile'
  13. - name: Run setup script
  14. command: ./setup.sh
  15. args:
  16. chdir: '{{ remote_code_path }}'
  17. - name: Copy bash_profile content
  18. shell: cat ~/.bash_profile
  19. register: bash_data
  20. - name: Copy bash_profile content to bashrc for non-interactive sessions
  21. blockinfile:
  22. block: '{{ bash_data.stdout }}'
  23. path: ~/.bashrc
  24. insertbefore: BOF
  25. - name: Make sure docker is running
  26. command: systemctl start docker
  27. become: yes
  28. - name: Build packages
  29. command: yarn build:packages
  30. args:
  31. chdir: '{{ remote_code_path }}'
  32. async: 3600
  33. poll: 0
  34. register: build_result
  35. - name: Check on build async task
  36. async_status:
  37. jid: '{{ build_result.ansible_job_id }}'
  38. register: job_result
  39. until: job_result.finished
  40. # Max number of times to check for status
  41. retries: 36
  42. # Check for the status every 100s
  43. delay: 100
  44. - name: Build Node image
  45. command: yarn build:node:docker
  46. args:
  47. chdir: '{{ remote_code_path }}'
  48. environment:
  49. RUNTIME_PROFILE: '{{ runtime_profile }}'
  50. async: 3600
  51. poll: 0
  52. register: node_build_result
  53. - name: Check on build node image async task
  54. async_status:
  55. jid: '{{ node_build_result.ansible_job_id }}'
  56. register: job_result
  57. until: job_result.finished
  58. # Max number of times to check for status
  59. retries: 36
  60. # Check for the status every 100s
  61. delay: 100
  62. - name: Run docker-compose
  63. command: yarn start
  64. args:
  65. chdir: '{{ remote_code_path }}'
  66. environment:
  67. RUNTIME_PROFILE: '{{ runtime_profile }}'
  68. PERSIST: 'true'
  69. COLOSSUS_1_URL: 'https://{{ inventory_hostname }}.nip.io/colossus-1/'
  70. DISTRIBUTOR_1_URL: 'https://{{ inventory_hostname }}.nip.io/distributor-1/'
  71. SKIP_CHAIN_SETUP: '{{ skip_chain_setup }}'
  72. async: 1800
  73. poll: 0
  74. register: compose_result
  75. - name: Check on yarn start task
  76. async_status:
  77. jid: '{{ compose_result.ansible_job_id }}'
  78. register: job_result
  79. until: job_result.finished
  80. # Max number of times to check for status
  81. retries: 18
  82. # Check for the status every 100s
  83. delay: 100
  84. - name: Set nip.io domain with IP
  85. set_fact:
  86. nip_domain: '{{ inventory_hostname }}.nip.io'
  87. run_once: yes
  88. - name: Install and configure Caddy
  89. include_role:
  90. name: caddy_ansible.caddy_ansible
  91. apply:
  92. become: yes
  93. vars:
  94. caddy_config: "{{ lookup('template', 'templates/Playground-Caddyfile.j2') }}"
  95. caddy_systemd_capabilities_enabled: true
  96. caddy_update: false
  97. - name: Set endpoints
  98. set_fact:
  99. all_services: |
  100. websocket_rpc: wss://{{ nip_domain }}/ws-rpc
  101. http_rpc: https://{{ nip_domain }}/http-rpc
  102. colossus: https://{{ nip_domain }}/colossus-1
  103. distributor: https://{{ nip_domain }}/distributor-1
  104. graphql_server: https://{{ nip_domain }}/query-node/server/graphql
  105. graphql_server_websocket: wss://{{ nip_domain }}/query-node/server/graphql
  106. indexer: https://{{ nip_domain }}/query-node/indexer/graphql
  107. member_faucet: https://{{ nip_domain }}/member-faucet/register
  108. orion: https://{{ nip_domain }}/orion/graphql
  109. config: https://{{ nip_domain }}/network/config.json
  110. stack_name: {{ stack_name }}
  111. run_once: yes
  112. - name: Print endpoints
  113. debug:
  114. msg: '{{ all_services | from_yaml }}'
  115. run_once: yes
  116. - name: Create config.json to serve as Caddy endpoint
  117. copy:
  118. content: '{{ all_services | from_yaml | to_json }}'
  119. dest: '/home/ubuntu/config.json'
  120. - name: Save output as file on local
  121. copy:
  122. content: '{{ all_services | from_yaml | to_json }}'
  123. dest: 'endpoints.json'
  124. delegate_to: localhost