Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

150 lignes
6.6 KiB

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