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.
 
 

159 rivejä
6.4 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. - name: Ensure Dendrite repository is present on self-build
  87. ansible.builtin.git:
  88. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  89. dest: "{{ matrix_dendrite_container_src_files_path }}"
  90. version: "{{ matrix_dendrite_container_image.split(':')[1] }}"
  91. force: "yes"
  92. become: true
  93. become_user: "{{ matrix_user_name }}"
  94. register: matrix_dendrite_git_pull_results
  95. - name: Check if Dendrite Docker image exists
  96. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_container_image }}'"
  97. register: matrix_dendrite_container_image_check_result
  98. changed_when: false
  99. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  100. # because the latter does not support BuildKit.
  101. # See: https://github.com/ansible-collections/community.general/issues/514
  102. - name: Ensure Dendrite Docker image is built
  103. ansible.builtin.command:
  104. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_container_image }} {{ matrix_dendrite_container_src_files_path }}"
  105. environment:
  106. DOCKER_BUILDKIT: 1
  107. changed_when: true
  108. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_container_image_check_result.stdout == ''"
  109. - name: Ensure Dendrite container network is created
  110. community.general.docker_network:
  111. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  112. name: "{{ matrix_dendrite_container_network }}"
  113. driver: bridge
  114. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  115. - name: Ensure Dendrite support files installed
  116. ansible.builtin.template:
  117. src: "{{ item.src }}"
  118. dest: "{{ item.dest }}"
  119. mode: "{{ item.mode }}"
  120. owner: "{{ matrix_user_name }}"
  121. group: "{{ matrix_group_name }}"
  122. with_items:
  123. - src: labels.j2
  124. dest: "{{ matrix_dendrite_base_path }}/labels"
  125. mode: "0640"
  126. - src: bin/create-account.j2
  127. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  128. mode: "0750"
  129. register: matrix_dendrite_support_files_result
  130. - name: Ensure matrix-dendrite.service installed
  131. ansible.builtin.template:
  132. src: "{{ role_path }}/templates/systemd/matrix-dendrite.service.j2"
  133. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  134. mode: '0644'
  135. register: matrix_dendrite_systemd_service_result
  136. - name: Determine whether Dendrite needs a restart
  137. ansible.builtin.set_fact:
  138. matrix_dendrite_restart_necessary: >-
  139. {{
  140. matrix_dendrite_config_result.changed | default(false)
  141. or matrix_dendrite_support_files_result.changed | default(false)
  142. or matrix_dendrite_systemd_service_result.changed | default(false)
  143. or matrix_dendrite_container_image_pull_result.changed | default(false)
  144. }}