Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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