Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

149 строки
7.0 KiB

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