Matrix Docker Ansible eploy
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

175 Zeilen
7.4 KiB

  1. ---
  2. - name: Ensure ma1sd paths exist
  3. 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. - 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. - set_fact:
  18. matrix_ma1sd_requires_restart: false
  19. - block:
  20. - name: Check if an SQLite database already exists
  21. stat:
  22. path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  23. register: matrix_ma1sd_sqlite_database_path_local_stat_result
  24. - block:
  25. - 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. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  35. - set_fact:
  36. matrix_ma1sd_requires_restart: true
  37. when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists|bool"
  38. when: "matrix_ma1sd_database_engine == 'postgres'"
  39. - name: Ensure ma1sd image is pulled
  40. docker_image:
  41. name: "{{ matrix_ma1sd_docker_image }}"
  42. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  43. force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  44. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
  45. when: "not matrix_ma1sd_container_image_self_build|bool"
  46. register: result
  47. retries: "{{ matrix_container_retries_count }}"
  48. delay: "{{ matrix_container_retries_delay }}"
  49. until: result is not failed
  50. - block:
  51. - name: Ensure gradle is installed for self-building (Debian)
  52. apt:
  53. name:
  54. - gradle
  55. state: present
  56. update_cache: true
  57. when: (ansible_os_family == 'Debian')
  58. - name: Ensure gradle is installed for self-building (RedHat)
  59. fail:
  60. msg: "Installing gradle on RedHat ({{ ansible_distribution }}) is currently not supported, so self-building ma1sd cannot happen at this time"
  61. when: ansible_os_family == 'RedHat'
  62. - name: Ensure gradle is installed for self-building (Archlinux)
  63. pacman:
  64. name:
  65. - gradle
  66. state: latest
  67. update_cache: true
  68. when: ansible_distribution == 'Archlinux'
  69. - name: Ensure ma1sd repository is present on self-build
  70. git:
  71. repo: "{{ matrix_ma1sd_container_image_self_build_repo }}"
  72. dest: "{{ matrix_ma1sd_docker_src_files_path }}"
  73. version: "{{ matrix_ma1sd_container_image_self_build_branch }}"
  74. force: "yes"
  75. become: true
  76. become_user: "{{ matrix_user_username }}"
  77. register: matrix_ma1sd_git_pull_results
  78. - name: Ensure ma1sd Docker image is built
  79. shell: "DOCKER_BUILDKIT=1 ./gradlew dockerBuild"
  80. args:
  81. chdir: "{{ matrix_ma1sd_docker_src_files_path }}"
  82. when: matrix_ma1sd_git_pull_results.changed
  83. - name: Ensure ma1sd Docker image is tagged correctly
  84. 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. when: "matrix_ma1sd_container_image_self_build|bool"
  96. - name: Ensure ma1sd config installed
  97. copy:
  98. content: "{{ matrix_ma1sd_configuration|to_nice_yaml(indent=2, width=999999) }}"
  99. dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
  100. mode: 0644
  101. owner: "{{ matrix_user_username }}"
  102. group: "{{ matrix_user_groupname }}"
  103. - name: Ensure custom view templates are installed, if any
  104. copy:
  105. content: "{{ item.value }}"
  106. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  107. mode: 0644
  108. owner: "{{ matrix_user_username }}"
  109. group: "{{ matrix_user_groupname }}"
  110. with_items:
  111. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'}
  112. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'}
  113. when: "matrix_ma1sd_view_session_custom_templates_enabled|bool and item.value"
  114. - name: Ensure custom email templates are installed, if any
  115. copy:
  116. content: "{{ item.value }}"
  117. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  118. mode: 0644
  119. owner: "{{ matrix_user_username }}"
  120. group: "{{ matrix_user_groupname }}"
  121. with_items:
  122. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  123. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  124. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  125. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  126. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value"
  127. # Only cleaning up for people who define the respective templates
  128. - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/)
  129. file:
  130. path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
  131. state: absent
  132. with_items:
  133. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  134. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  135. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  136. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  137. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value"
  138. - name: Ensure matrix-ma1sd.service installed
  139. template:
  140. src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
  141. dest: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
  142. mode: 0644
  143. register: matrix_ma1sd_systemd_service_result
  144. - name: Ensure systemd reloaded after matrix-ma1sd.service installation
  145. service:
  146. daemon_reload: true
  147. when: "matrix_ma1sd_systemd_service_result.changed|bool"
  148. - name: Ensure matrix-ma1sd.service restarted, if necessary
  149. service:
  150. name: "matrix-ma1sd.service"
  151. state: restarted
  152. when: "matrix_ma1sd_requires_restart|bool"