Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

153 řádky
7.1 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Ensure media-repo 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_media_repo_base_path }}"
  14. when: true
  15. - path: "{{ matrix_media_repo_config_path }}"
  16. when: true
  17. - path: "{{ matrix_media_repo_data_path }}"
  18. when: true
  19. - path: "{{ matrix_media_repo_docker_src_files_path }}"
  20. when: "{{ matrix_media_repo_container_image_self_build }}"
  21. when: "item.when | bool"
  22. - name: Ensure media-repo support files installed
  23. ansible.builtin.template:
  24. src: "{{ role_path }}/templates/media-repo/{{ item }}.j2"
  25. dest: "{{ matrix_media_repo_base_path }}/{{ item }}"
  26. mode: 0640
  27. owner: "{{ matrix_user_username }}"
  28. group: "{{ matrix_user_groupname }}"
  29. with_items:
  30. - env
  31. - labels
  32. - name: Ensure media-repo configuration installed
  33. ansible.builtin.template:
  34. src: "{{ role_path }}/templates/media-repo/media-repo.yaml.j2"
  35. dest: "{{ matrix_media_repo_config_path }}/media-repo.yaml"
  36. mode: 0640
  37. owner: "{{ matrix_user_username }}"
  38. group: "{{ matrix_user_groupname }}"
  39. - name: Ensure media-repo Docker image is pulled
  40. community.docker.docker_image:
  41. name: "{{ matrix_media_repo_docker_image }}"
  42. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  43. force_source: "{{ matrix_media_repo_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  44. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_media_repo_docker_image_force_pull }}"
  45. when: "not matrix_media_repo_container_image_self_build | bool"
  46. register: result
  47. retries: "{{ devture_playbook_help_container_retries_count }}"
  48. delay: "{{ devture_playbook_help_container_retries_delay }}"
  49. until: result is not failed
  50. - when: "matrix_media_repo_container_image_self_build | bool"
  51. block:
  52. - name: Ensure media-repo repository is present on self-build
  53. ansible.builtin.git:
  54. repo: "{{ matrix_media_repo_container_image_self_build_repo }}"
  55. dest: "{{ matrix_media_repo_docker_src_files_path }}"
  56. version: "{{ matrix_media_repo_docker_image.split(':')[1] }}"
  57. force: "yes"
  58. become: true
  59. become_user: "{{ matrix_user_username }}"
  60. register: matrix_media_repo_git_pull_results
  61. - name: Check if media-repo Docker image exists
  62. ansible.builtin.command: "{{ devture_systemd_docker_base_host_command_docker }} images --quiet --filter 'reference={{ matrix_media_repo_docker_image }}'"
  63. register: matrix_media_repo_docker_image_check_result
  64. changed_when: false
  65. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  66. # because the latter does not support BuildKit.
  67. # See: https://github.com/ansible-collections/community.general/issues/514
  68. - name: Ensure media-repo Docker image is built
  69. ansible.builtin.command:
  70. cmd: "{{ devture_systemd_docker_base_host_command_docker }} build -t {{ matrix_media_repo_docker_image }} {{ matrix_media_repo_docker_src_files_path }}"
  71. environment:
  72. DOCKER_BUILDKIT: 1
  73. changed_when: true
  74. when: "matrix_media_repo_git_pull_results.changed | bool or matrix_media_repo_docker_image_check_result.stdout == ''"
  75. - name: Check existence of media-repo signing key
  76. ansible.builtin.stat:
  77. path: "{{ matrix_media_repo_config_path }}/{{ matrix_media_repo_identifier }}.signing.key"
  78. register: matrix_media_repo_signing_key_stat
  79. - when: "matrix_media_repo_generate_signing_key | bool and not (matrix_media_repo_signing_key_stat.stat.exists | bool)"
  80. block:
  81. - name: Generate media-repo signing key
  82. ansible.builtin.command:
  83. cmd: |
  84. {{ devture_systemd_docker_base_host_command_docker }} run
  85. --rm
  86. --name={{ matrix_media_repo_identifier }}-temp
  87. --user={{ matrix_synapse_uid }}:{{ matrix_synapse_gid }}
  88. --cap-drop=ALL
  89. --mount type=bind,src={{ matrix_media_repo_config_path }},dst=/config
  90. --workdir='/config'
  91. --entrypoint='generate_signing_key'
  92. {{ matrix_media_repo_docker_image }}
  93. -output {{ matrix_media_repo_identifier }}.signing.key.TEMP
  94. creates: "{{ matrix_media_repo_config_path }}/{{ matrix_media_repo_identifier }}.signing.key.TEMP"
  95. - name: Merge media-repo signing key with homeserver signing key
  96. ansible.builtin.command:
  97. cmd: |
  98. {{ devture_systemd_docker_base_host_command_docker }} run
  99. --rm
  100. --name={{ matrix_media_repo_identifier }}-temp
  101. --user={{ matrix_synapse_uid }}:{{ matrix_synapse_gid }}
  102. --cap-drop=ALL
  103. --mount type=bind,src={{ matrix_media_repo_config_path }},dst=/config
  104. --mount type=bind,src={{ matrix_media_repo_homeserver_signing_key | dirname }},dst=/homeserver-signing-key-dir
  105. --workdir='/config'
  106. --entrypoint='combine_signing_keys'
  107. {{ matrix_media_repo_docker_image }}
  108. -format {{ matrix_homeserver_implementation }} -output /homeserver-signing-key-dir/{{ matrix_media_repo_homeserver_signing_key | basename }}.merged /homeserver-signing-key-dir/{{ matrix_media_repo_homeserver_signing_key | basename }} {{ matrix_media_repo_identifier }}.signing.key.TEMP
  109. creates: "{{ matrix_media_repo_homeserver_signing_key }}.merged"
  110. - name: Backup existing homeserver signing key before replacing it
  111. ansible.builtin.copy:
  112. remote_src: true
  113. src: "{{ matrix_media_repo_homeserver_signing_key }}"
  114. dest: "{{ matrix_media_repo_homeserver_signing_key }}.{{ matrix_homeserver_implementation }}.backup"
  115. mode: 0644
  116. owner: "{{ matrix_user_username }}"
  117. group: "{{ matrix_user_groupname }}"
  118. - name: Replace homeserver signing key with merged signing key
  119. ansible.builtin.command:
  120. cmd: "mv {{ matrix_media_repo_homeserver_signing_key }}.merged {{ matrix_media_repo_homeserver_signing_key }}"
  121. removes: "{{ matrix_media_repo_homeserver_signing_key }}.merged"
  122. - name: Finalize media-repo signing key setup
  123. ansible.builtin.command:
  124. cmd: "mv {{ matrix_media_repo_config_path }}/{{ matrix_media_repo_identifier }}.signing.key.TEMP {{ matrix_media_repo_config_path }}/{{ matrix_media_repo_identifier }}.signing.key"
  125. removes: "{{ matrix_media_repo_config_path }}/{{ matrix_media_repo_identifier }}.signing.key.TEMP"
  126. - name: Ensure media-repo container network is created
  127. community.general.docker_network:
  128. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  129. name: "{{ matrix_media_repo_container_network }}"
  130. driver: bridge
  131. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  132. - name: Ensure media-repo service installed
  133. ansible.builtin.template:
  134. src: "{{ role_path }}/templates/media-repo/systemd/matrix-media-repo.service.j2"
  135. dest: "{{ devture_systemd_docker_base_systemd_path }}/{{ matrix_media_repo_identifier }}.service"
  136. mode: 0640