Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

132 wiersze
5.5 KiB

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