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

174 строки
7.2 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  3. # SPDX-FileCopyrightText: 2022 Jip J. Dekker
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  6. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  7. # SPDX-FileCopyrightText: 2023 Isaiah Becker-Mayer
  8. # SPDX-FileCopyrightText: 2024 David Mehren
  9. #
  10. # SPDX-License-Identifier: AGPL-3.0-or-later
  11. ---
  12. - name: Ensure Dendrite paths exist
  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_dendrite_config_dir_path }}"
  21. when: true
  22. - path: "{{ matrix_dendrite_bin_path }}"
  23. when: true
  24. - path: "{{ matrix_dendrite_ext_path }}"
  25. when: true
  26. - path: "{{ matrix_dendrite_nats_storage_path }}"
  27. when: true
  28. - path: "{{ matrix_dendrite_container_src_files_path }}"
  29. when: "{{ matrix_dendrite_container_image_self_build }}"
  30. when: "item.when | bool"
  31. # This will throw a Permission Denied error if already mounted using fuse
  32. - name: Check Dendrite media store path
  33. ansible.builtin.stat:
  34. path: "{{ matrix_dendrite_media_store_path }}"
  35. register: local_path_media_store_stat
  36. ignore_errors: true
  37. # This is separate and conditional, to ensure we don't execute it
  38. # if the path already exists or we failed to check, because it's mounted using fuse.
  39. - name: Ensure Dendrite media store path exists
  40. ansible.builtin.file:
  41. path: "{{ matrix_dendrite_media_store_path }}"
  42. state: directory
  43. mode: '0750'
  44. owner: "{{ matrix_user_name }}"
  45. group: "{{ matrix_group_name }}"
  46. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  47. - name: Ensure Dendrite Docker image is pulled
  48. community.docker.docker_image_pull:
  49. name: "{{ matrix_dendrite_container_image }}"
  50. pull: always
  51. when: "not matrix_dendrite_container_image_self_build | bool"
  52. register: matrix_dendrite_container_image_pull_result
  53. retries: "{{ devture_playbook_help_container_retries_count }}"
  54. delay: "{{ devture_playbook_help_container_retries_delay }}"
  55. until: matrix_dendrite_container_image_pull_result is not failed
  56. # We do this so that the signing key would get generated.
  57. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  58. # a very recent version, which is not available for a lot of people yet.
  59. - name: Generate Dendrite signing key
  60. ansible.builtin.command:
  61. cmd: |
  62. docker run
  63. --rm
  64. --name=matrix-dendrite-config
  65. --entrypoint=generate-keys
  66. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  67. {{ matrix_dendrite_container_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  68. generate
  69. creates: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  70. - name: Ensure Dendrite server key exists
  71. ansible.builtin.file:
  72. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  73. mode: '0644'
  74. owner: "{{ matrix_user_name }}"
  75. group: "{{ matrix_group_name }}"
  76. - name: Ensure Dendrite configuration installed
  77. ansible.builtin.copy:
  78. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  79. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  80. mode: '0644'
  81. owner: "{{ matrix_user_name }}"
  82. group: "{{ matrix_group_name }}"
  83. register: matrix_dendrite_config_result
  84. - when: "matrix_dendrite_container_image_self_build | bool"
  85. block:
  86. # 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.
  87. - name: Ensure Dendrite repository ownership is correct on self-build
  88. ansible.builtin.file:
  89. path: "{{ matrix_dendrite_container_src_files_path }}"
  90. state: directory
  91. owner: "{{ matrix_user_name }}"
  92. group: "{{ matrix_group_name }}"
  93. recurse: true
  94. - name: Ensure Dendrite repository is present on self-build
  95. ansible.builtin.git:
  96. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  97. dest: "{{ matrix_dendrite_container_src_files_path }}"
  98. version: "{{ matrix_dendrite_container_image.split(':')[1] }}"
  99. force: "yes"
  100. become: true
  101. become_user: "{{ matrix_user_name }}"
  102. # Keep this even though the task above normalizes ownership. Git may still see an ownership mismatch when Ansible becomes an unprivileged user (see #5065).
  103. environment:
  104. GIT_CONFIG_COUNT: "1"
  105. GIT_CONFIG_KEY_0: safe.directory
  106. GIT_CONFIG_VALUE_0: "{{ matrix_dendrite_container_src_files_path }}"
  107. register: matrix_dendrite_git_pull_results
  108. - name: Check if Dendrite Docker image exists
  109. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_container_image }}'"
  110. register: matrix_dendrite_container_image_check_result
  111. changed_when: false
  112. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  113. # because the latter does not support BuildKit.
  114. # See: https://github.com/ansible-collections/community.general/issues/514
  115. - name: Ensure Dendrite Docker image is built
  116. ansible.builtin.command:
  117. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_container_image }} {{ matrix_dendrite_container_src_files_path }}"
  118. environment:
  119. DOCKER_BUILDKIT: 1
  120. changed_when: true
  121. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_container_image_check_result.stdout == ''"
  122. - name: Ensure Dendrite container network is created
  123. when: matrix_dendrite_container_network != 'host'
  124. community.general.docker_network:
  125. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  126. name: "{{ matrix_dendrite_container_network }}"
  127. driver: bridge
  128. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  129. - name: Ensure Dendrite support files installed
  130. ansible.builtin.template:
  131. src: "{{ item.src }}"
  132. dest: "{{ item.dest }}"
  133. mode: "{{ item.mode }}"
  134. owner: "{{ matrix_user_name }}"
  135. group: "{{ matrix_group_name }}"
  136. with_items:
  137. - src: labels.j2
  138. dest: "{{ matrix_dendrite_base_path }}/labels"
  139. mode: "0640"
  140. - src: bin/create-account.j2
  141. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  142. mode: "0750"
  143. register: matrix_dendrite_support_files_result
  144. - name: Ensure matrix-dendrite.service installed
  145. ansible.builtin.template:
  146. src: "{{ role_path }}/templates/systemd/matrix-dendrite.service.j2"
  147. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  148. mode: '0644'
  149. register: matrix_dendrite_systemd_service_result
  150. - name: Determine whether Dendrite needs a restart
  151. ansible.builtin.set_fact:
  152. matrix_dendrite_restart_necessary: >-
  153. {{
  154. matrix_dendrite_config_result.changed | default(false)
  155. or matrix_dendrite_support_files_result.changed | default(false)
  156. or matrix_dendrite_systemd_service_result.changed | default(false)
  157. or matrix_dendrite_container_image_pull_result.changed | default(false)
  158. }}