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.
 
 

156 rivejä
6.9 KiB

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