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

165 строки
7.2 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. - name: Ensure Synapse repository is present on self-build
  35. ansible.builtin.git:
  36. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  37. dest: "{{ matrix_synapse_container_src_files_path }}"
  38. version: "{{ matrix_synapse_container_image.split(':')[1] }}"
  39. force: "yes"
  40. become: true
  41. become_user: "{{ matrix_synapse_username }}"
  42. register: matrix_synapse_git_pull_results
  43. - name: Check if Synapse Docker image exists
  44. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_container_image }}'"
  45. register: matrix_synapse_container_image_check_result
  46. changed_when: false
  47. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  48. # because the latter does not support BuildKit.
  49. # See: https://github.com/ansible-collections/community.general/issues/514
  50. - name: Ensure Synapse Docker image is built
  51. ansible.builtin.shell:
  52. chdir: "{{ matrix_synapse_container_src_files_path }}"
  53. cmd: |
  54. {{ devture_systemd_docker_base_host_command_docker }} build \
  55. -t "{{ matrix_synapse_container_image }}" \
  56. -f docker/Dockerfile \
  57. .
  58. environment:
  59. DOCKER_BUILDKIT: 1
  60. changed_when: true
  61. when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_container_image_check_result.stdout == ''"
  62. - name: Ensure Synapse Docker image is pulled
  63. community.docker.docker_image_pull:
  64. name: "{{ matrix_synapse_container_image }}"
  65. pull: always
  66. when: "not matrix_synapse_container_image_self_build"
  67. register: result
  68. retries: "{{ devture_playbook_help_container_retries_count }}"
  69. delay: "{{ devture_playbook_help_container_retries_delay }}"
  70. until: result is not failed
  71. - when: "matrix_synapse_container_image_customizations_enabled | bool"
  72. block:
  73. - name: Ensure customizations Dockerfile is created
  74. ansible.builtin.template:
  75. src: "{{ role_path }}/templates/synapse/customizations/Dockerfile.j2"
  76. dest: "{{ matrix_synapse_customized_container_src_files_path }}/Dockerfile"
  77. owner: "{{ matrix_synapse_uid }}"
  78. group: "{{ matrix_synapse_gid }}"
  79. mode: '0640'
  80. register: matrix_synapse_container_image_customizations_dockerfile_result
  81. - name: Ensure customized Docker image for Synapse is built
  82. community.docker.docker_image_build:
  83. name: "{{ matrix_synapse_container_image_customized }}"
  84. dockerfile: Dockerfile
  85. path: "{{ matrix_synapse_customized_container_src_files_path }}"
  86. pull: false
  87. nocache: "{{ matrix_synapse_container_image_customized_build_nocache }}"
  88. rebuild: "{{ 'always' if (matrix_synapse_container_image_customizations_dockerfile_result.changed | bool or matrix_synapse_container_image_customized_force_source | bool) else 'never' }}"
  89. register: matrix_synapse_container_image_customized_build_result
  90. # We do this so that the signing key would get generated.
  91. #
  92. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  93. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  94. #
  95. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  96. # a very recent docker-py version, which is not available for a lot of people yet.
  97. - name: Generate initial Synapse config and signing key
  98. ansible.builtin.command:
  99. cmd: |
  100. {{ devture_systemd_docker_base_host_command_docker }} run
  101. --rm
  102. --name=matrix-config
  103. --user={{ matrix_synapse_uid }}:{{ matrix_synapse_gid }}
  104. --cap-drop=ALL
  105. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  106. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  107. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  108. -e SYNAPSE_REPORT_STATS=no
  109. {{ matrix_synapse_container_image }}
  110. generate
  111. creates: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  112. - name: Ensure Synapse homeserver config installed
  113. ansible.builtin.copy:
  114. content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}"
  115. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  116. mode: '0644'
  117. owner: "{{ matrix_synapse_uid }}"
  118. group: "{{ matrix_synapse_gid }}"
  119. - name: Ensure Synapse container network is created
  120. community.general.docker_network:
  121. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  122. name: "{{ matrix_synapse_container_network }}"
  123. driver: bridge
  124. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  125. - name: Ensure Synapse support files installed
  126. ansible.builtin.template:
  127. src: "{{ item.src }}"
  128. dest: "{{ item.dest }}"
  129. mode: "{{ item.mode }}"
  130. with_items:
  131. - src: "{{ matrix_synapse_template_synapse_log }}"
  132. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  133. mode: '0644'
  134. - src: "{{ role_path }}/templates/synapse/bin/register-user.j2"
  135. dest: "{{ matrix_synapse_bin_path }}/register-user"
  136. mode: '0755'
  137. - src: "{{ role_path }}/templates/synapse/labels.j2"
  138. dest: "{{ matrix_synapse_base_path }}/labels"
  139. mode: '0644'
  140. - src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  141. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-synapse.service"
  142. mode: '0644'
  143. - name: Generate sample prometheus.yml for external scraping
  144. ansible.builtin.template:
  145. src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2"
  146. dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example"
  147. owner: "{{ matrix_synapse_uid }}"
  148. group: "{{ matrix_synapse_gid }}"
  149. mode: '0644'
  150. when: matrix_synapse_metrics_proxying_enabled | bool