Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

168 lines
7.4 KiB

  1. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  3. # SPDX-FileCopyrightText: 2020 Marcel Partap
  4. # SPDX-FileCopyrightText: 2020 Matt Cengia
  5. # SPDX-FileCopyrightText: 2020 Stuart Mumford
  6. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  7. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  8. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  9. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  10. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  11. # SPDX-FileCopyrightText: 2024 David Mehren
  12. #
  13. # SPDX-License-Identifier: AGPL-3.0-or-later
  14. ---
  15. - name: Ensure ma1sd paths exist
  16. ansible.builtin.file:
  17. path: "{{ item.path }}"
  18. state: directory
  19. mode: 0750
  20. owner: "{{ matrix_user_name }}"
  21. group: "{{ matrix_group_name }}"
  22. with_items:
  23. - {path: "{{ matrix_ma1sd_config_path }}", when: true}
  24. - {path: "{{ matrix_ma1sd_data_path }}", when: true}
  25. - {path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"}
  26. when: "item.when | bool"
  27. # These (SQLite -> Postgres) migration tasks are usually at the top,
  28. # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist.
  29. - ansible.builtin.set_fact:
  30. matrix_ma1sd_requires_restart: false
  31. - when: "matrix_ma1sd_database_engine == 'postgres'"
  32. block:
  33. - name: Check if an SQLite database already exists
  34. ansible.builtin.stat:
  35. path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  36. register: matrix_ma1sd_sqlite_database_path_local_stat_result
  37. - when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists | bool"
  38. block:
  39. - ansible.builtin.include_role:
  40. name: galaxy/postgres
  41. tasks_from: migrate_db_to_postgres
  42. vars:
  43. postgres_db_migration_request:
  44. src: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  45. dst: "{{ matrix_ma1sd_database_connection_string }}"
  46. caller: "{{ role_path | basename }}"
  47. engine_variable_name: 'matrix_ma1sd_database_engine'
  48. engine_old: 'sqlite'
  49. systemd_services_to_stop: ['matrix-ma1sd.service']
  50. pgloader_options: ['--with "quote identifiers"']
  51. - ansible.builtin.set_fact:
  52. matrix_ma1sd_requires_restart: true
  53. - name: Ensure ma1sd image is pulled
  54. community.docker.docker_image:
  55. name: "{{ matrix_ma1sd_docker_image }}"
  56. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  57. force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  58. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
  59. when: "not matrix_ma1sd_container_image_self_build | bool"
  60. register: result
  61. retries: "{{ devture_playbook_help_container_retries_count }}"
  62. delay: "{{ devture_playbook_help_container_retries_delay }}"
  63. until: result is not failed
  64. - when: "matrix_ma1sd_container_image_self_build | bool"
  65. block:
  66. - name: Ensure ma1sd repository is present on self-build
  67. ansible.builtin.git:
  68. repo: "{{ matrix_ma1sd_container_image_self_build_repo }}"
  69. dest: "{{ matrix_ma1sd_docker_src_files_path }}"
  70. version: "{{ matrix_ma1sd_container_image_self_build_branch }}"
  71. force: "yes"
  72. become: true
  73. become_user: "{{ matrix_user_name }}"
  74. register: matrix_ma1sd_git_pull_results
  75. - name: Ensure ma1sd container image is built
  76. ansible.builtin.command:
  77. cmd: |-
  78. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  79. --tag={{ matrix_ma1sd_docker_image }}
  80. --file={{ matrix_ma1sd_docker_src_files_path }}/Dockerfile
  81. {{ matrix_ma1sd_docker_src_files_path }}
  82. changed_when: true
  83. - name: Ensure ma1sd config installed
  84. ansible.builtin.copy:
  85. content: "{{ matrix_ma1sd_configuration | to_nice_yaml(indent=2, width=999999) }}"
  86. dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
  87. mode: 0644
  88. owner: "{{ matrix_user_name }}"
  89. group: "{{ matrix_group_name }}"
  90. - name: Ensure custom view templates are installed, if any
  91. ansible.builtin.copy:
  92. content: "{{ item.value }}"
  93. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  94. mode: 0644
  95. owner: "{{ matrix_user_name }}"
  96. group: "{{ matrix_group_name }}"
  97. with_items:
  98. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'}
  99. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'}
  100. when: "matrix_ma1sd_view_session_custom_templates_enabled | bool and item.value"
  101. - name: Ensure custom email templates are installed, if any
  102. ansible.builtin.copy:
  103. content: "{{ item.value }}"
  104. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  105. mode: 0644
  106. owner: "{{ matrix_user_name }}"
  107. group: "{{ matrix_group_name }}"
  108. with_items:
  109. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  110. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  111. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  112. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  113. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  114. # Only cleaning up for people who define the respective templates
  115. - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/)
  116. ansible.builtin.file:
  117. path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
  118. state: absent
  119. with_items:
  120. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  121. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  122. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  123. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  124. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  125. - name: Ensure ma1sd support files installed
  126. ansible.builtin.template:
  127. src: "{{ role_path }}/templates/{{ item }}.j2"
  128. dest: "{{ matrix_ma1sd_base_path }}/{{ item }}"
  129. mode: 0640
  130. owner: "{{ matrix_user_name }}"
  131. group: "{{ matrix_group_name }}"
  132. with_items:
  133. - labels
  134. - name: Ensure ma1sd container network is created
  135. community.general.docker_network:
  136. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  137. name: "{{ matrix_ma1sd_container_network }}"
  138. driver: bridge
  139. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  140. - name: Ensure matrix-ma1sd.service installed
  141. ansible.builtin.template:
  142. src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
  143. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-ma1sd.service"
  144. mode: 0644
  145. - name: Ensure matrix-ma1sd.service restarted, if necessary
  146. ansible.builtin.service:
  147. name: "matrix-ma1sd.service"
  148. state: restarted
  149. daemon_reload: true
  150. when: "matrix_ma1sd_requires_restart | bool"