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.
 
 

154 lines
6.5 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. register: matrix_client_element_git_pull_results
  50. when: "matrix_client_element_container_image_self_build | bool"
  51. # See:
  52. # - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1357
  53. # - https://github.com/element-hq/element-web/issues/19544
  54. - name: Patch webpack.config.js to support building on low-memory (<4G RAM) devices
  55. ansible.builtin.lineinfile:
  56. path: "{{ matrix_client_element_container_src_files_path }}/webpack.config.js"
  57. regexp: '(\s+)splitChunks: \{'
  58. line: '\1splitChunks: { maxSize: 100000,'
  59. backrefs: true
  60. owner: root
  61. group: root
  62. mode: '0644'
  63. when: "matrix_client_element_container_image_self_build | bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled | bool"
  64. - name: Ensure Element Web Docker image is built
  65. ansible.builtin.command:
  66. cmd: |-
  67. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  68. --tag={{ matrix_client_element_container_image }}
  69. --file={{ matrix_client_element_container_src_dockerfile_path }}
  70. {{ matrix_client_element_container_src_files_path }}
  71. changed_when: true
  72. when: matrix_client_element_container_image_self_build | bool
  73. - name: Ensure Element Web configuration installed
  74. ansible.builtin.copy:
  75. content: "{{ matrix_client_element_configuration | to_nice_json }}"
  76. dest: "{{ matrix_client_element_data_path }}/config.json"
  77. mode: '0644'
  78. owner: "{{ matrix_user_name }}"
  79. group: "{{ matrix_group_name }}"
  80. register: matrix_client_element_config_result
  81. - name: Ensure Element location sharing map style installed
  82. when: matrix_client_element_location_sharing_enabled | bool
  83. ansible.builtin.copy:
  84. content: "{{ matrix_client_element_location_sharing_map_style | to_nice_json }}"
  85. dest: "{{ matrix_client_element_data_path }}/map_style.json"
  86. mode: '0644'
  87. owner: "{{ matrix_user_name }}"
  88. group: "{{ matrix_group_name }}"
  89. register: matrix_client_element_config_map_style_result
  90. - name: Ensure Element Web config files installed
  91. ansible.builtin.template:
  92. src: "{{ item.src }}"
  93. dest: "{{ matrix_client_element_data_path }}/{{ item.name }}"
  94. mode: '0644'
  95. owner: "{{ matrix_user_name }}"
  96. group: "{{ matrix_group_name }}"
  97. with_items:
  98. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  99. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  100. - {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
  101. when: "item.src is not none"
  102. register: matrix_client_element_support_files_result
  103. - name: Ensure Element Web nginx.conf file is removed
  104. ansible.builtin.file:
  105. path: "{{ matrix_client_element_data_path }}/nginx.conf"
  106. state: absent
  107. - name: Ensure Element Web config files removed
  108. ansible.builtin.file:
  109. path: "{{ matrix_client_element_data_path }}/{{ item.name }}"
  110. state: absent
  111. with_items:
  112. - {src: "{{ matrix_client_element_embedded_pages_home_path }}", name: "home.html"}
  113. # The playbook no longer ships a custom welcome.html (Element Web renders its own built-in welcome page).
  114. - {src: ~, name: "welcome.html"}
  115. when: "item.src is none"
  116. - name: Ensure Element Web container network is created
  117. when: matrix_client_element_container_network != 'host'
  118. community.general.docker_network:
  119. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  120. name: "{{ matrix_client_element_container_network }}"
  121. driver: bridge
  122. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  123. - name: Ensure matrix-client-element.service installed
  124. ansible.builtin.template:
  125. src: "{{ role_path }}/templates/systemd/matrix-client-element.service.j2"
  126. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-element.service"
  127. mode: '0644'
  128. register: matrix_client_element_systemd_service_result
  129. - name: Determine whether Element Web needs a restart
  130. ansible.builtin.set_fact:
  131. matrix_client_element_restart_necessary: >-
  132. {{
  133. matrix_client_element_config_result.changed | default(false)
  134. or matrix_client_element_config_map_style_result.changed | default(false)
  135. or matrix_client_element_support_files_result.changed | default(false)
  136. or matrix_client_element_systemd_service_result.changed | default(false)
  137. or matrix_client_element_container_image_pull_result.changed | default(false)
  138. }}