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

159 строки
6.8 KiB

  1. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  4. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  5. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  6. # SPDX-FileCopyrightText: 2023 Pierre 'McFly' Marty
  7. # SPDX-FileCopyrightText: 2024 David Mehren
  8. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  9. #
  10. # SPDX-License-Identifier: AGPL-3.0-or-later
  11. ---
  12. - name: Ensure Element Web paths exists
  13. ansible.builtin.file:
  14. path: "{{ item.path }}"
  15. state: directory
  16. mode: '0750'
  17. owner: "{{ matrix_user_name }}"
  18. group: "{{ matrix_group_name }}"
  19. with_items:
  20. - {path: "{{ matrix_client_element_data_path }}", when: true}
  21. - {path: "{{ matrix_client_element_container_src_files_path }}", when: "{{ matrix_client_element_container_image_self_build }}"}
  22. when: "item.when | bool"
  23. - name: Ensure Element Web Docker image is pulled
  24. community.docker.docker_image_pull:
  25. name: "{{ matrix_client_element_container_image }}"
  26. pull: always
  27. when: "not matrix_client_element_container_image_self_build | bool"
  28. register: matrix_client_element_container_image_pull_result
  29. retries: "{{ devture_playbook_help_container_retries_count }}"
  30. delay: "{{ devture_playbook_help_container_retries_delay }}"
  31. until: matrix_client_element_container_image_pull_result is not failed
  32. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  33. - name: Ensure Element Web repository ownership is correct on self-build
  34. ansible.builtin.file:
  35. path: "{{ matrix_client_element_container_src_files_path }}"
  36. state: directory
  37. owner: "{{ matrix_user_name }}"
  38. group: "{{ matrix_group_name }}"
  39. recurse: true
  40. when: "matrix_client_element_container_image_self_build | bool"
  41. - name: Ensure Element Web repository is present on self-build
  42. ansible.builtin.git:
  43. repo: "{{ matrix_client_element_container_image_self_build_repo }}"
  44. dest: "{{ matrix_client_element_container_src_files_path }}"
  45. version: "{{ matrix_client_element_container_image.split(':')[1] }}"
  46. force: "yes"
  47. become: true
  48. become_user: "{{ matrix_user_name }}"
  49. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  50. environment:
  51. GIT_CONFIG_COUNT: "1"
  52. GIT_CONFIG_KEY_0: safe.directory
  53. GIT_CONFIG_VALUE_0: "{{ matrix_client_element_container_src_files_path }}"
  54. register: matrix_client_element_git_pull_results
  55. when: "matrix_client_element_container_image_self_build | bool"
  56. # See:
  57. # - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1357
  58. # - https://github.com/element-hq/element-web/issues/19544
  59. - name: Patch webpack.config.js to support building on low-memory (<4G RAM) devices
  60. ansible.builtin.lineinfile:
  61. path: "{{ matrix_client_element_container_src_files_path }}/webpack.config.js"
  62. regexp: '(\s+)splitChunks: \{'
  63. line: '\1splitChunks: { maxSize: 100000,'
  64. backrefs: true
  65. owner: root
  66. group: root
  67. mode: '0644'
  68. when: "matrix_client_element_container_image_self_build | bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled | bool"
  69. - name: Ensure Element Web Docker image is built
  70. ansible.builtin.command:
  71. cmd: |-
  72. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  73. --tag={{ matrix_client_element_container_image }}
  74. --file={{ matrix_client_element_container_src_dockerfile_path }}
  75. {{ matrix_client_element_container_src_files_path }}
  76. changed_when: true
  77. when: matrix_client_element_container_image_self_build | bool
  78. - name: Ensure Element Web configuration installed
  79. ansible.builtin.copy:
  80. content: "{{ matrix_client_element_configuration | to_nice_json }}"
  81. dest: "{{ matrix_client_element_data_path }}/config.json"
  82. mode: '0644'
  83. owner: "{{ matrix_user_name }}"
  84. group: "{{ matrix_group_name }}"
  85. register: matrix_client_element_config_result
  86. - name: Ensure Element location sharing map style installed
  87. when: matrix_client_element_location_sharing_enabled | bool
  88. ansible.builtin.copy:
  89. content: "{{ matrix_client_element_location_sharing_map_style | to_nice_json }}"
  90. dest: "{{ matrix_client_element_data_path }}/map_style.json"
  91. mode: '0644'
  92. owner: "{{ matrix_user_name }}"
  93. group: "{{ matrix_group_name }}"
  94. register: matrix_client_element_config_map_style_result
  95. - name: Ensure Element Web config files installed
  96. ansible.builtin.template:
  97. src: "{{ item.src }}"
  98. dest: "{{ matrix_client_element_data_path }}/{{ item.name }}"
  99. mode: '0644'
  100. owner: "{{ matrix_user_name }}"
  101. group: "{{ matrix_group_name }}"
  102. with_items:
  103. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  104. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  105. - {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
  106. when: "item.src is not none"
  107. register: matrix_client_element_support_files_result
  108. - name: Ensure Element Web nginx.conf file is removed
  109. ansible.builtin.file:
  110. path: "{{ matrix_client_element_data_path }}/nginx.conf"
  111. state: absent
  112. - name: Ensure Element Web config files removed
  113. ansible.builtin.file:
  114. path: "{{ matrix_client_element_data_path }}/{{ item.name }}"
  115. state: absent
  116. with_items:
  117. - {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
  118. # The playbook no longer ships a custom welcome.html (Element Web renders its own built-in welcome page).
  119. - {src: ~, name: "welcome.html"}
  120. when: "item.src is none"
  121. - name: Ensure Element Web container network is created
  122. when: matrix_client_element_container_network != 'host'
  123. community.general.docker_network:
  124. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  125. name: "{{ matrix_client_element_container_network }}"
  126. driver: bridge
  127. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  128. - name: Ensure matrix-client-element.service installed
  129. ansible.builtin.template:
  130. src: "{{ role_path }}/templates/systemd/matrix-client-element.service.j2"
  131. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-element.service"
  132. mode: '0644'
  133. register: matrix_client_element_systemd_service_result
  134. - name: Determine whether Element Web needs a restart
  135. ansible.builtin.set_fact:
  136. matrix_client_element_restart_necessary: >-
  137. {{
  138. matrix_client_element_config_result.changed | default(false)
  139. or matrix_client_element_config_map_style_result.changed | default(false)
  140. or matrix_client_element_support_files_result.changed | default(false)
  141. or matrix_client_element_systemd_service_result.changed | default(false)
  142. or matrix_client_element_container_image_pull_result.changed | default(false)
  143. }}