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.
 
 

147 wiersze
6.1 KiB

  1. ---
  2. # This will throw a Permission Denied error if already mounted using fuse
  3. - name: Check Synapse media store path
  4. stat:
  5. path: "{{ matrix_synapse_media_store_path }}"
  6. register: local_path_media_store_stat
  7. ignore_errors: true
  8. # This is separate and conditional, to ensure we don't execute it
  9. # if the path already exists or we failed to check, because it's mounted using fuse.
  10. - name: Ensure Synapse media store path exists
  11. file:
  12. path: "{{ matrix_synapse_media_store_path }}"
  13. state: directory
  14. mode: 0750
  15. owner: "{{ matrix_user_username }}"
  16. group: "{{ matrix_user_groupname }}"
  17. when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists"
  18. - block:
  19. - name: Ensure Synapse repository is present on self-build
  20. git:
  21. repo: "{{ matrix_synapse_container_image_self_build_repo }}"
  22. dest: "{{ matrix_synapse_docker_src_files_path }}"
  23. version: "{{ matrix_synapse_docker_image.split(':')[1] }}"
  24. force: "yes"
  25. become: true
  26. become_user: "{{ matrix_user_username }}"
  27. register: matrix_synapse_git_pull_results
  28. - name: Check if Synapse Docker image exists
  29. command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'"
  30. register: matrix_synapse_docker_image_check_result
  31. # Adding the Installcommand for https://github.com/matrix-org/synapse-s3-storage-provider
  32. # to the Dockerfile https://github.com/matrix-org/synapse-s3-storage-provider/issues/14#issuecomment-847146994
  33. - name: Adding the S3 Install Command
  34. lineinfile:
  35. path: "{{ matrix_synapse_docker_src_files_path }}/docker/Dockerfile"
  36. line: RUN pip install --no-deps --no-warn-script-location synapse-s3-storage-provider boto3 botocore humanize jmespath s3transfer tqdm typing-extensions
  37. insertafter: /synapse.*
  38. when: "matrix_synapse_media_storage_provider_s3_enabled|bool"
  39. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  40. # because the latter does not support BuildKit.
  41. # See: https://github.com/ansible-collections/community.general/issues/514
  42. - name: Ensure Synapse Docker image is built
  43. shell:
  44. chdir: "{{ matrix_synapse_docker_src_files_path }}"
  45. cmd: |
  46. {{ matrix_host_command_docker }} build \
  47. -t "{{ matrix_synapse_docker_image }}" \
  48. -f docker/Dockerfile \
  49. .
  50. environment:
  51. DOCKER_BUILDKIT: 1
  52. when: "matrix_synapse_git_pull_results.changed|bool or matrix_synapse_docker_image_check_result.stdout == ''"
  53. when: "matrix_synapse_container_image_self_build|bool"
  54. - name: Ensure Synapse Docker image is pulled
  55. docker_image:
  56. name: "{{ matrix_synapse_docker_image }}"
  57. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  58. force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  59. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}"
  60. when: "not matrix_synapse_container_image_self_build"
  61. register: result
  62. retries: "{{ matrix_container_retries_count }}"
  63. delay: "{{ matrix_container_retries_delay }}"
  64. until: result is not failed
  65. - name: Check if a Synapse signing key exists
  66. stat:
  67. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  68. register: matrix_synapse_signing_key_stat
  69. # We do this so that the signing key would get generated.
  70. #
  71. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  72. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  73. #
  74. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  75. # a very recent docker-py version, which is not available for a lot of people yet.
  76. - name: Generate initial Synapse config and signing key
  77. command: |
  78. docker run
  79. --rm
  80. --name=matrix-config
  81. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  82. --cap-drop=ALL
  83. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  84. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  85. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  86. -e SYNAPSE_REPORT_STATS=no
  87. {{ matrix_synapse_docker_image }}
  88. generate
  89. when: "not matrix_synapse_signing_key_stat.stat.exists"
  90. - name: Ensure Synapse homeserver config installed
  91. copy:
  92. content: "{{ matrix_synapse_configuration|to_nice_yaml(indent=2, width=999999) }}"
  93. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  94. mode: 0644
  95. owner: "{{ matrix_user_username }}"
  96. group: "{{ matrix_user_groupname }}"
  97. - name: Ensure Synapse log config installed
  98. template:
  99. src: "{{ matrix_synapse_template_synapse_log }}"
  100. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  101. mode: 0644
  102. - name: Ensure matrix-synapse.service installed
  103. template:
  104. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  105. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  106. mode: 0644
  107. register: matrix_synapse_systemd_service_result
  108. - name: Ensure systemd reloaded after matrix-synapse.service installation
  109. service:
  110. daemon_reload: true
  111. when: "matrix_synapse_systemd_service_result.changed"
  112. - name: Ensure matrix-synapse-register-user script created
  113. template:
  114. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  115. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  116. mode: 0755
  117. - set_fact:
  118. matrix_synapse_media_storage_providers: |
  119. {{
  120. matrix_synapse_media_storage_providers|default([])
  121. +
  122. [
  123. {
  124. "module": "s3_storage_provider.S3StorageProviderBackend",
  125. "store_local": matrix_synapse_s3_media_store_on_s3,
  126. "store_remote": matrix_synapse_s3_media_store_on_local_filesystem,
  127. "store_synchronous": matrix_synapse_media_storage_provider_s3_store_synchronous,
  128. "config": matrix_synapse_media_storage_provider_s3_config
  129. }
  130. ]
  131. }}