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

161 строка
6.8 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:
  49. name: "{{ matrix_dendrite_container_image }}"
  50. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  51. force_source: "{{ matrix_dendrite_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  52. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dendrite_container_image_force_pull }}"
  53. when: "not matrix_dendrite_container_image_self_build | bool"
  54. register: matrix_dendrite_container_image_pull_result
  55. retries: "{{ devture_playbook_help_container_retries_count }}"
  56. delay: "{{ devture_playbook_help_container_retries_delay }}"
  57. until: matrix_dendrite_container_image_pull_result is not failed
  58. # We do this so that the signing key would get generated.
  59. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  60. # a very recent version, which is not available for a lot of people yet.
  61. - name: Generate Dendrite signing key
  62. ansible.builtin.command:
  63. cmd: |
  64. docker run
  65. --rm
  66. --name=matrix-dendrite-config
  67. --entrypoint=generate-keys
  68. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  69. {{ matrix_dendrite_container_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  70. generate
  71. creates: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  72. - name: Ensure Dendrite server key exists
  73. ansible.builtin.file:
  74. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  75. mode: '0644'
  76. owner: "{{ matrix_user_name }}"
  77. group: "{{ matrix_group_name }}"
  78. - name: Ensure Dendrite configuration installed
  79. ansible.builtin.copy:
  80. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  81. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  82. mode: '0644'
  83. owner: "{{ matrix_user_name }}"
  84. group: "{{ matrix_group_name }}"
  85. register: matrix_dendrite_config_result
  86. - when: "matrix_dendrite_container_image_self_build | bool"
  87. block:
  88. - name: Ensure Dendrite repository is present on self-build
  89. ansible.builtin.git:
  90. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  91. dest: "{{ matrix_dendrite_container_src_files_path }}"
  92. version: "{{ matrix_dendrite_container_image.split(':')[1] }}"
  93. force: "yes"
  94. become: true
  95. become_user: "{{ matrix_user_name }}"
  96. register: matrix_dendrite_git_pull_results
  97. - name: Check if Dendrite Docker image exists
  98. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_container_image }}'"
  99. register: matrix_dendrite_container_image_check_result
  100. changed_when: false
  101. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  102. # because the latter does not support BuildKit.
  103. # See: https://github.com/ansible-collections/community.general/issues/514
  104. - name: Ensure Dendrite Docker image is built
  105. ansible.builtin.command:
  106. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_container_image }} {{ matrix_dendrite_container_src_files_path }}"
  107. environment:
  108. DOCKER_BUILDKIT: 1
  109. changed_when: true
  110. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_container_image_check_result.stdout == ''"
  111. - name: Ensure Dendrite container network is created
  112. community.general.docker_network:
  113. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  114. name: "{{ matrix_dendrite_container_network }}"
  115. driver: bridge
  116. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  117. - name: Ensure Dendrite support files installed
  118. ansible.builtin.template:
  119. src: "{{ item.src }}"
  120. dest: "{{ item.dest }}"
  121. mode: "{{ item.mode }}"
  122. owner: "{{ matrix_user_name }}"
  123. group: "{{ matrix_group_name }}"
  124. with_items:
  125. - src: labels.j2
  126. dest: "{{ matrix_dendrite_base_path }}/labels"
  127. mode: "0640"
  128. - src: bin/create-account.j2
  129. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  130. mode: "0750"
  131. register: matrix_dendrite_support_files_result
  132. - name: Ensure matrix-dendrite.service installed
  133. ansible.builtin.template:
  134. src: "{{ role_path }}/templates/systemd/matrix-dendrite.service.j2"
  135. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  136. mode: '0644'
  137. register: matrix_dendrite_systemd_service_result
  138. - name: Determine whether Dendrite needs a restart
  139. ansible.builtin.set_fact:
  140. matrix_dendrite_restart_necessary: >-
  141. {{
  142. matrix_dendrite_config_result.changed | default(false)
  143. or matrix_dendrite_support_files_result.changed | default(false)
  144. or matrix_dendrite_systemd_service_result.changed | default(false)
  145. or matrix_dendrite_container_image_pull_result.changed | default(false)
  146. }}