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.

145 lines
6.0 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_docker_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:
  49. name: "{{ matrix_dendrite_docker_image }}"
  50. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  51. force_source: "{{ matrix_dendrite_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  52. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dendrite_docker_image_force_pull }}"
  53. when: "not matrix_dendrite_container_image_self_build | bool"
  54. register: result
  55. retries: "{{ devture_playbook_help_container_retries_count }}"
  56. delay: "{{ devture_playbook_help_container_retries_delay }}"
  57. until: result is not failed
  58. # We do this so that the signing key would get generated.
  59. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  60. # a very recent version, which is not available for a lot of people yet.
  61. - name: Generate Dendrite signing key
  62. ansible.builtin.command:
  63. cmd: |
  64. docker run
  65. --rm
  66. --name=matrix-dendrite-config
  67. --entrypoint=generate-keys
  68. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  69. {{ matrix_dendrite_docker_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  70. generate
  71. creates: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  72. - name: Ensure Dendrite server key exists
  73. ansible.builtin.file:
  74. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  75. mode: 0644
  76. owner: "{{ matrix_user_name }}"
  77. group: "{{ matrix_group_name }}"
  78. - name: Ensure Dendrite configuration installed
  79. ansible.builtin.copy:
  80. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  81. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  82. mode: 0644
  83. owner: "{{ matrix_user_name }}"
  84. group: "{{ matrix_group_name }}"
  85. - when: "matrix_dendrite_container_image_self_build | bool"
  86. block:
  87. - name: Ensure Dendrite repository is present on self-build
  88. ansible.builtin.git:
  89. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  90. dest: "{{ matrix_dendrite_docker_src_files_path }}"
  91. version: "{{ matrix_dendrite_docker_image.split(':')[1] }}"
  92. force: "yes"
  93. become: true
  94. become_user: "{{ matrix_user_name }}"
  95. register: matrix_dendrite_git_pull_results
  96. - name: Check if Dendrite Docker image exists
  97. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_docker_image }}'"
  98. register: matrix_dendrite_docker_image_check_result
  99. changed_when: false
  100. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  101. # because the latter does not support BuildKit.
  102. # See: https://github.com/ansible-collections/community.general/issues/514
  103. - name: Ensure Dendrite Docker image is built
  104. ansible.builtin.command:
  105. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_docker_image }} {{ matrix_dendrite_docker_src_files_path }}"
  106. environment:
  107. DOCKER_BUILDKIT: 1
  108. changed_when: true
  109. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_docker_image_check_result.stdout == ''"
  110. - name: Ensure Dendrite container network is created
  111. community.general.docker_network:
  112. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  113. name: "{{ matrix_dendrite_container_network }}"
  114. driver: bridge
  115. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  116. - name: Ensure Dendrite support files installed
  117. ansible.builtin.template:
  118. src: "{{ item.src }}"
  119. dest: "{{ item.dest }}"
  120. mode: "{{ item.mode }}"
  121. owner: "{{ matrix_user_name }}"
  122. group: "{{ matrix_group_name }}"
  123. with_items:
  124. - src: labels.j2
  125. dest: "{{ matrix_dendrite_base_path }}/labels"
  126. mode: "0640"
  127. - src: bin/create-account.j2
  128. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  129. mode: "0750"
  130. - src: systemd/matrix-dendrite.service.j2
  131. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  132. mode: "0644"