Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

174 righe
7.7 KiB

  1. ---
  2. - name: Ensure ma1sd paths exist
  3. ansible.builtin.file:
  4. path: "{{ item.path }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - {path: "{{ matrix_ma1sd_config_path }}", when: true}
  11. - {path: "{{ matrix_ma1sd_data_path }}", when: true}
  12. - {path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"}
  13. when: "item.when | bool"
  14. - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml"
  15. # These (SQLite -> Postgres) migration tasks are usually at the top,
  16. # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist.
  17. - ansible.builtin.set_fact:
  18. matrix_ma1sd_requires_restart: false
  19. - when: "matrix_ma1sd_database_engine == 'postgres'"
  20. block:
  21. - name: Check if an SQLite database already exists
  22. ansible.builtin.stat:
  23. path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  24. register: matrix_ma1sd_sqlite_database_path_local_stat_result
  25. - when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists | bool"
  26. block:
  27. - ansible.builtin.set_fact:
  28. matrix_postgres_db_migration_request:
  29. src: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  30. dst: "{{ matrix_ma1sd_database_connection_string }}"
  31. caller: "{{ role_path | basename }}"
  32. engine_variable_name: 'matrix_ma1sd_database_engine'
  33. engine_old: 'sqlite'
  34. systemd_services_to_stop: ['matrix-ma1sd.service']
  35. pgloader_options: ['--with "quote identifiers"']
  36. - ansible.builtin.import_role:
  37. name: custom/matrix-postgres
  38. tasks_from: migrate_db_to_postgres
  39. - ansible.builtin.set_fact:
  40. matrix_ma1sd_requires_restart: true
  41. - name: Ensure ma1sd image is pulled
  42. community.docker.docker_image:
  43. name: "{{ matrix_ma1sd_docker_image }}"
  44. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  45. force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  46. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
  47. when: "not matrix_ma1sd_container_image_self_build | bool"
  48. register: result
  49. retries: "{{ devture_playbook_help_container_retries_count }}"
  50. delay: "{{ devture_playbook_help_container_retries_delay }}"
  51. until: result is not failed
  52. - when: "matrix_ma1sd_container_image_self_build | bool"
  53. block:
  54. - name: Ensure gradle is installed for self-building (Debian)
  55. ansible.builtin.apt:
  56. name:
  57. - gradle
  58. state: present
  59. update_cache: true
  60. when: (ansible_os_family == 'Debian')
  61. - name: Ensure gradle is installed for self-building (RedHat)
  62. ansible.builtin.fail:
  63. msg: "Installing gradle on RedHat ({{ ansible_distribution }}) is currently not supported, so self-building ma1sd cannot happen at this time"
  64. when: ansible_os_family == 'RedHat'
  65. - ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/ensure_gradle_installed_archlinux.yml"
  66. when: "ansible_distribution == 'Archlinux'"
  67. - name: Ensure ma1sd repository is present on self-build
  68. ansible.builtin.git:
  69. repo: "{{ matrix_ma1sd_container_image_self_build_repo }}"
  70. dest: "{{ matrix_ma1sd_docker_src_files_path }}"
  71. version: "{{ matrix_ma1sd_container_image_self_build_branch }}"
  72. force: "yes"
  73. become: true
  74. become_user: "{{ matrix_user_username }}"
  75. register: matrix_ma1sd_git_pull_results
  76. - name: Ensure ma1sd Docker image is built
  77. ansible.builtin.command:
  78. cmd: ./gradlew dockerBuild
  79. chdir: "{{ matrix_ma1sd_docker_src_files_path }}"
  80. environment:
  81. DOCKER_BUILDKIT: 1
  82. when: matrix_ma1sd_git_pull_results.changed
  83. - name: Ensure ma1sd Docker image is tagged correctly
  84. community.docker.docker_image:
  85. # The build script always tags the image with 2 tags:
  86. # - based on the branch/version: e.g. `ma1uta/ma1sd:2.4.0` (when on `2.4.0`)
  87. # or `ma1uta/ma1sd:2.4.0-19-ga71d32b` (when on a given commit for a pre-release)
  88. # - generic one: `ma1uta/ma1sd:latest-dev`
  89. #
  90. # It's hard to predict the first one, so we'll use the latter.
  91. name: "ma1uta/ma1sd:latest-dev"
  92. repository: "{{ matrix_ma1sd_docker_image }}"
  93. force_tag: true
  94. source: local
  95. - name: Ensure ma1sd config installed
  96. ansible.builtin.copy:
  97. content: "{{ matrix_ma1sd_configuration | to_nice_yaml(indent=2, width=999999) }}"
  98. dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
  99. mode: 0644
  100. owner: "{{ matrix_user_username }}"
  101. group: "{{ matrix_user_groupname }}"
  102. - name: Ensure custom view templates are installed, if any
  103. ansible.builtin.copy:
  104. content: "{{ item.value }}"
  105. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  106. mode: 0644
  107. owner: "{{ matrix_user_username }}"
  108. group: "{{ matrix_user_groupname }}"
  109. with_items:
  110. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'}
  111. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'}
  112. when: "matrix_ma1sd_view_session_custom_templates_enabled | bool and item.value"
  113. - name: Ensure custom email templates are installed, if any
  114. ansible.builtin.copy:
  115. content: "{{ item.value }}"
  116. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  117. mode: 0644
  118. owner: "{{ matrix_user_username }}"
  119. group: "{{ matrix_user_groupname }}"
  120. with_items:
  121. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  122. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  123. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  124. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  125. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  126. # Only cleaning up for people who define the respective templates
  127. - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/)
  128. ansible.builtin.file:
  129. path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
  130. state: absent
  131. with_items:
  132. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  133. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  134. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  135. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  136. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  137. - name: Ensure matrix-ma1sd.service installed
  138. ansible.builtin.template:
  139. src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
  140. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-ma1sd.service"
  141. mode: 0644
  142. register: matrix_ma1sd_systemd_service_result
  143. - name: Ensure systemd reloaded after matrix-ma1sd.service installation
  144. ansible.builtin.service:
  145. daemon_reload: true
  146. when: "matrix_ma1sd_systemd_service_result.changed | bool"
  147. - name: Ensure matrix-ma1sd.service restarted, if necessary
  148. ansible.builtin.service:
  149. name: "matrix-ma1sd.service"
  150. state: restarted
  151. when: "matrix_ma1sd_requires_restart | bool"