docker-setup-playbook.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: Creat 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. - name: Run docker-compose
  49. command: yarn start
  50. args:
  51. chdir: '{{ remote_code_path }}'
  52. environment:
  53. PERSIST: 'true'
  54. async: 1800
  55. poll: 0
  56. register: compose_result
  57. - name: Check on yarn start task
  58. async_status:
  59. jid: '{{ compose_result.ansible_job_id }}'
  60. register: job_result
  61. until: job_result.finished
  62. # Max number of times to check for status
  63. retries: 18
  64. # Check for the status every 100s
  65. delay: 100
  66. - name: Set nip.io domain with IP
  67. set_fact:
  68. nip_domain: '{{ inventory_hostname }}.nip.io'
  69. run_once: yes
  70. - name: Install and configure Caddy
  71. include_role:
  72. name: caddy_ansible.caddy_ansible
  73. apply:
  74. become: yes
  75. vars:
  76. caddy_config: "{{ lookup('template', 'templates/Caddyfile.j2') }}"
  77. caddy_systemd_capabilities_enabled: true
  78. caddy_update: false
  79. - name: Print endpoints
  80. debug:
  81. msg:
  82. - 'The services should now be accesible at:'
  83. - 'Pioneer: {{ nip_domain }}/pioneer/'
  84. - 'WebSocket RPC: {{ nip_domain }}/ws-rpc'
  85. - 'HTTP RPC: {{ nip_domain }}/http-rpc'
  86. - 'Colossus: {{ nip_domain }}/colossus'
  87. - 'Distributor: {{ nip_domain }}/distributor'
  88. - 'GraphQL server: {{ nip_domain }}/graphql'
  89. - 'Indexer: {{ nip_domain }}/indexer'