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

169 строки
6.9 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. register: matrix_dendrite_git_pull_results
  103. - name: Check if Dendrite Docker image exists
  104. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_container_image }}'"
  105. register: matrix_dendrite_container_image_check_result
  106. changed_when: false
  107. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  108. # because the latter does not support BuildKit.
  109. # See: https://github.com/ansible-collections/community.general/issues/514
  110. - name: Ensure Dendrite Docker image is built
  111. ansible.builtin.command:
  112. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_container_image }} {{ matrix_dendrite_container_src_files_path }}"
  113. environment:
  114. DOCKER_BUILDKIT: 1
  115. changed_when: true
  116. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_container_image_check_result.stdout == ''"
  117. - name: Ensure Dendrite container network is created
  118. when: matrix_dendrite_container_network != 'host'
  119. community.general.docker_network:
  120. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  121. name: "{{ matrix_dendrite_container_network }}"
  122. driver: bridge
  123. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  124. - name: Ensure Dendrite support files installed
  125. ansible.builtin.template:
  126. src: "{{ item.src }}"
  127. dest: "{{ item.dest }}"
  128. mode: "{{ item.mode }}"
  129. owner: "{{ matrix_user_name }}"
  130. group: "{{ matrix_group_name }}"
  131. with_items:
  132. - src: labels.j2
  133. dest: "{{ matrix_dendrite_base_path }}/labels"
  134. mode: "0640"
  135. - src: bin/create-account.j2
  136. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  137. mode: "0750"
  138. register: matrix_dendrite_support_files_result
  139. - name: Ensure matrix-dendrite.service installed
  140. ansible.builtin.template:
  141. src: "{{ role_path }}/templates/systemd/matrix-dendrite.service.j2"
  142. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  143. mode: '0644'
  144. register: matrix_dendrite_systemd_service_result
  145. - name: Determine whether Dendrite needs a restart
  146. ansible.builtin.set_fact:
  147. matrix_dendrite_restart_necessary: >-
  148. {{
  149. matrix_dendrite_config_result.changed | default(false)
  150. or matrix_dendrite_support_files_result.changed | default(false)
  151. or matrix_dendrite_systemd_service_result.changed | default(false)
  152. or matrix_dendrite_container_image_pull_result.changed | default(false)
  153. }}