Matrix Docker Ansible eploy
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

138 lines
5.7 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Ensure Dendrite paths exist
  6. ansible.builtin.file:
  7. path: "{{ item.path }}"
  8. state: directory
  9. mode: 0750
  10. owner: "{{ matrix_user_username }}"
  11. group: "{{ matrix_user_groupname }}"
  12. with_items:
  13. - path: "{{ matrix_dendrite_config_dir_path }}"
  14. when: true
  15. - path: "{{ matrix_dendrite_bin_path }}"
  16. when: true
  17. - path: "{{ matrix_dendrite_ext_path }}"
  18. when: true
  19. - path: "{{ matrix_dendrite_nats_storage_path }}"
  20. when: true
  21. - path: "{{ matrix_dendrite_docker_src_files_path }}"
  22. when: "{{ matrix_dendrite_container_image_self_build }}"
  23. when: "item.when | bool"
  24. # This will throw a Permission Denied error if already mounted using fuse
  25. - name: Check Dendrite media store path
  26. ansible.builtin.stat:
  27. path: "{{ matrix_dendrite_media_store_path }}"
  28. register: local_path_media_store_stat
  29. ignore_errors: true
  30. # This is separate and conditional, to ensure we don't execute it
  31. # if the path already exists or we failed to check, because it's mounted using fuse.
  32. - name: Ensure Dendrite media store path exists
  33. ansible.builtin.file:
  34. path: "{{ matrix_dendrite_media_store_path }}"
  35. state: directory
  36. mode: 0750
  37. owner: "{{ matrix_user_username }}"
  38. group: "{{ matrix_user_groupname }}"
  39. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  40. - name: Ensure Dendrite Docker image is pulled
  41. community.docker.docker_image:
  42. name: "{{ matrix_dendrite_docker_image }}"
  43. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  44. force_source: "{{ matrix_dendrite_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  45. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dendrite_docker_image_force_pull }}"
  46. when: "not matrix_dendrite_container_image_self_build | bool"
  47. register: result
  48. retries: "{{ devture_playbook_help_container_retries_count }}"
  49. delay: "{{ devture_playbook_help_container_retries_delay }}"
  50. until: result is not failed
  51. # We do this so that the signing key would get generated.
  52. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  53. # a very recent version, which is not available for a lot of people yet.
  54. - name: Generate Dendrite signing key
  55. ansible.builtin.command:
  56. cmd: |
  57. docker run
  58. --rm
  59. --name=matrix-dendrite-config
  60. --entrypoint=generate-keys
  61. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data
  62. {{ matrix_dendrite_docker_image }} --private-key=/data/{{ matrix_server_fqn_matrix }}.signing.pem
  63. generate
  64. creates: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  65. - name: Ensure Dendrite server key exists
  66. ansible.builtin.file:
  67. path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem"
  68. mode: 0644
  69. owner: "{{ matrix_user_username }}"
  70. group: "{{ matrix_user_groupname }}"
  71. - name: Ensure Dendrite configuration installed
  72. ansible.builtin.copy:
  73. content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}"
  74. dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml"
  75. mode: 0644
  76. owner: "{{ matrix_user_username }}"
  77. group: "{{ matrix_user_groupname }}"
  78. - when: "matrix_dendrite_container_image_self_build | bool"
  79. block:
  80. - name: Ensure Dendrite repository is present on self-build
  81. ansible.builtin.git:
  82. repo: "{{ matrix_dendrite_container_image_self_build_repo }}"
  83. dest: "{{ matrix_dendrite_docker_src_files_path }}"
  84. version: "{{ matrix_dendrite_docker_image.split(':')[1] }}"
  85. force: "yes"
  86. become: true
  87. become_user: "{{ matrix_user_username }}"
  88. register: matrix_dendrite_git_pull_results
  89. - name: Check if Dendrite Docker image exists
  90. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_dendrite_docker_image }}'"
  91. register: matrix_dendrite_docker_image_check_result
  92. changed_when: false
  93. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  94. # because the latter does not support BuildKit.
  95. # See: https://github.com/ansible-collections/community.general/issues/514
  96. - name: Ensure Dendrite Docker image is built
  97. ansible.builtin.command:
  98. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_dendrite_docker_image }} {{ matrix_dendrite_docker_src_files_path }}"
  99. environment:
  100. DOCKER_BUILDKIT: 1
  101. changed_when: true
  102. when: "matrix_dendrite_git_pull_results.changed | bool or matrix_dendrite_docker_image_check_result.stdout == ''"
  103. - name: Ensure Dendrite container network is created
  104. community.general.docker_network:
  105. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  106. name: "{{ matrix_dendrite_container_network }}"
  107. driver: bridge
  108. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  109. - name: Ensure Dendrite support files installed
  110. ansible.builtin.template:
  111. src: "{{ item.src }}"
  112. dest: "{{ item.dest }}"
  113. mode: "{{ item.mode }}"
  114. owner: "{{ matrix_user_username }}"
  115. group: "{{ matrix_user_groupname }}"
  116. with_items:
  117. - src: labels.j2
  118. dest: "{{ matrix_dendrite_base_path }}/labels"
  119. mode: "0640"
  120. - src: bin/create-account.j2
  121. dest: "{{ matrix_dendrite_bin_path }}/create-account"
  122. mode: "0750"
  123. - src: systemd/matrix-dendrite.service.j2
  124. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dendrite.service"
  125. mode: "0644"