Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

175 righe
7.7 KiB

  1. # SPDX-FileCopyrightText: 2018 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2019 Dan Arnfield
  3. # SPDX-FileCopyrightText: 2019 Jan Christian Grünhage
  4. # SPDX-FileCopyrightText: 2019 Lyubomir Popov
  5. # SPDX-FileCopyrightText: 2020 - 2024 MDAD project contributors
  6. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  7. # SPDX-FileCopyrightText: 2020 Horvath Gergely
  8. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  9. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  10. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  11. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  12. # SPDX-FileCopyrightText: 2024 David Mehren
  13. #
  14. # SPDX-License-Identifier: AGPL-3.0-or-later
  15. ---
  16. # This will throw a Permission Denied error if already mounted using fuse
  17. - name: Check Synapse media store path
  18. ansible.builtin.stat:
  19. path: "{{ matrix_synapse_media_store_path }}"
  20. register: local_path_media_store_stat
  21. ignore_errors: true
  22. # This is separate and conditional, to ensure we don't execute it
  23. # if the path already exists or we failed to check, because it's mounted using fuse.
  24. - name: Ensure Synapse media store path exists
  25. ansible.builtin.file:
  26. path: "{{ matrix_synapse_media_store_path }}"
  27. state: directory
  28. mode: '0750'
  29. owner: "{{ matrix_synapse_uid }}"
  30. group: "{{ matrix_synapse_gid }}"
  31. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  32. - when: "matrix_synapse_container_image_self_build | bool"
  33. block:
  34. # 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.
  35. - name: Ensure Synapse repository ownership is correct on self-build
  36. ansible.builtin.file:
  37. path: "{{ matrix_synapse_container_src_files_path }}"
  38. state: directory
  39. owner: "{{ matrix_synapse_uid }}"
  40. group: "{{ matrix_synapse_gid }}"
  41. recurse: true
  42. - name: Ensure Synapse repository is present on self-build
  43. ansible.builtin.git:
  44. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  45. dest: "{{ matrix_synapse_container_src_files_path }}"
  46. version: "{{ matrix_synapse_container_image.split(':')[1] }}"
  47. force: "yes"
  48. become: true
  49. become_user: "{{ matrix_synapse_username }}"
  50. register: matrix_synapse_git_pull_results
  51. - name: Check if Synapse Docker image exists
  52. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_container_image }}'"
  53. register: matrix_synapse_container_image_check_result
  54. changed_when: false
  55. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  56. # because the latter does not support BuildKit.
  57. # See: https://github.com/ansible-collections/community.general/issues/514
  58. - name: Ensure Synapse Docker image is built
  59. ansible.builtin.shell:
  60. chdir: "{{ matrix_synapse_container_src_files_path }}"
  61. cmd: |
  62. {{ devture_systemd_docker_base_host_command_docker }} build \
  63. -t "{{ matrix_synapse_container_image }}" \
  64. -f docker/Dockerfile \
  65. .
  66. environment:
  67. DOCKER_BUILDKIT: 1
  68. changed_when: true
  69. when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_container_image_check_result.stdout == ''"
  70. - name: Ensure Synapse Docker image is pulled
  71. community.docker.docker_image_pull:
  72. name: "{{ matrix_synapse_container_image }}"
  73. pull: always
  74. when: "not matrix_synapse_container_image_self_build"
  75. register: result
  76. retries: "{{ devture_playbook_help_container_retries_count }}"
  77. delay: "{{ devture_playbook_help_container_retries_delay }}"
  78. until: result is not failed
  79. - when: "matrix_synapse_container_image_customizations_enabled | bool"
  80. block:
  81. - name: Ensure customizations Dockerfile is created
  82. ansible.builtin.template:
  83. src: "{{ role_path }}/templates/synapse/customizations/Dockerfile.j2"
  84. dest: "{{ matrix_synapse_customized_container_src_files_path }}/Dockerfile"
  85. owner: "{{ matrix_synapse_uid }}"
  86. group: "{{ matrix_synapse_gid }}"
  87. mode: '0640'
  88. register: matrix_synapse_container_image_customizations_dockerfile_result
  89. - name: Ensure customized Docker image for Synapse is built
  90. community.docker.docker_image_build:
  91. name: "{{ matrix_synapse_container_image_customized }}"
  92. dockerfile: Dockerfile
  93. path: "{{ matrix_synapse_customized_container_src_files_path }}"
  94. pull: false
  95. nocache: "{{ matrix_synapse_container_image_customized_build_nocache }}"
  96. rebuild: "{{ 'always' if (matrix_synapse_container_image_customizations_dockerfile_result.changed | bool or matrix_synapse_container_image_customized_force_source | bool) else 'never' }}"
  97. register: matrix_synapse_container_image_customized_build_result
  98. # We do this so that the signing key would get generated.
  99. #
  100. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  101. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  102. #
  103. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  104. # a very recent docker-py version, which is not available for a lot of people yet.
  105. - name: Generate initial Synapse config and signing key
  106. ansible.builtin.command:
  107. cmd: |
  108. {{ devture_systemd_docker_base_host_command_docker }} run
  109. --rm
  110. --name=matrix-config
  111. --user={{ matrix_synapse_uid }}:{{ matrix_synapse_gid }}
  112. --cap-drop=ALL
  113. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  114. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  115. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  116. -e SYNAPSE_REPORT_STATS=no
  117. {{ matrix_synapse_container_image }}
  118. generate
  119. creates: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  120. - name: Ensure Synapse homeserver config installed
  121. ansible.builtin.copy:
  122. content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}"
  123. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  124. mode: '0644'
  125. owner: "{{ matrix_synapse_uid }}"
  126. group: "{{ matrix_synapse_gid }}"
  127. - name: Ensure Synapse container network is created
  128. when: matrix_synapse_container_network != 'host'
  129. community.general.docker_network:
  130. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  131. name: "{{ matrix_synapse_container_network }}"
  132. driver: bridge
  133. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  134. - name: Ensure Synapse support files installed
  135. ansible.builtin.template:
  136. src: "{{ item.src }}"
  137. dest: "{{ item.dest }}"
  138. mode: "{{ item.mode }}"
  139. with_items:
  140. - src: "{{ matrix_synapse_template_synapse_log }}"
  141. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  142. mode: '0644'
  143. - src: "{{ role_path }}/templates/synapse/bin/register-user.j2"
  144. dest: "{{ matrix_synapse_bin_path }}/register-user"
  145. mode: '0755'
  146. - src: "{{ role_path }}/templates/synapse/labels.j2"
  147. dest: "{{ matrix_synapse_base_path }}/labels"
  148. mode: '0644'
  149. - src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  150. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-synapse.service"
  151. mode: '0644'
  152. - name: Generate sample prometheus.yml for external scraping
  153. ansible.builtin.template:
  154. src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2"
  155. dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example"
  156. owner: "{{ matrix_synapse_uid }}"
  157. group: "{{ matrix_synapse_gid }}"
  158. mode: '0644'
  159. when: matrix_synapse_metrics_proxying_enabled | bool