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

129 строки
5.5 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. # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module,
  32. # because the latter does not support BuildKit.
  33. # See: https://github.com/ansible-collections/community.general/issues/514
  34. - name: Ensure Synapse Docker image is built
  35. # Adding the Installcommand for https://github.com/matrix-org/synapse-s3-storage-provider
  36. # to the Dockerfile https://github.com/matrix-org/synapse-s3-storage-provider/issues/14#issuecomment-847146994
  37. lineinfile:
  38. path: "{{ matrix_synapse_docker_src_files_path }}/docker/Dockerfile"
  39. line: RUN pip install --prefix="/install" --no-deps --no-warn-script-location synapse-s3-storage-provider
  40. insertafter: /synapse.*
  41. when: "matrix_synapse_s3_media_store_enabled|bool"
  42. shell:
  43. chdir: "{{ matrix_synapse_docker_src_files_path }}"
  44. cmd: |
  45. {{ matrix_host_command_docker }} build \
  46. -t "{{ matrix_synapse_docker_image }}" \
  47. -f docker/Dockerfile \
  48. .
  49. environment:
  50. DOCKER_BUILDKIT: 1
  51. when: "matrix_synapse_git_pull_results.changed|bool or matrix_synapse_docker_image_check_result.stdout == ''"
  52. when: "matrix_synapse_container_image_self_build|bool or matrix_synapse_s3_media_store_enabled|bool"
  53. - name: Ensure Synapse Docker image is pulled
  54. docker_image:
  55. name: "{{ matrix_synapse_docker_image }}"
  56. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  57. force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  58. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}"
  59. when: "not matrix_synapse_container_image_self_build"
  60. register: result
  61. retries: "{{ matrix_container_retries_count }}"
  62. delay: "{{ matrix_container_retries_delay }}"
  63. until: result is not failed
  64. - name: Check if a Synapse signing key exists
  65. stat:
  66. path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key"
  67. register: matrix_synapse_signing_key_stat
  68. # We do this so that the signing key would get generated.
  69. #
  70. # This will also generate a default homeserver.yaml configuration file and a log configuration file.
  71. # We don't care about those configuration files, as we replace them with our own anyway (see below).
  72. #
  73. # We don't use the `docker_container` module, because using it with `cap_drop` requires
  74. # a very recent docker-py version, which is not available for a lot of people yet.
  75. - name: Generate initial Synapse config and signing key
  76. command: |
  77. docker run
  78. --rm
  79. --name=matrix-config
  80. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  81. --cap-drop=ALL
  82. --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
  83. -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
  84. -e SYNAPSE_SERVER_NAME={{ matrix_server_fqn_matrix }}
  85. -e SYNAPSE_REPORT_STATS=no
  86. {{ matrix_synapse_docker_image }}
  87. generate
  88. when: "not matrix_synapse_signing_key_stat.stat.exists"
  89. - name: Ensure Synapse homeserver config installed
  90. copy:
  91. content: "{{ matrix_synapse_configuration|to_nice_yaml(indent=2, width=999999) }}"
  92. dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml"
  93. mode: 0644
  94. owner: "{{ matrix_user_username }}"
  95. group: "{{ matrix_user_groupname }}"
  96. - name: Ensure Synapse log config installed
  97. template:
  98. src: "{{ matrix_synapse_template_synapse_log }}"
  99. dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config"
  100. mode: 0644
  101. - name: Ensure matrix-synapse.service installed
  102. template:
  103. src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2"
  104. dest: "{{ matrix_systemd_path }}/matrix-synapse.service"
  105. mode: 0644
  106. register: matrix_synapse_systemd_service_result
  107. - name: Ensure systemd reloaded after matrix-synapse.service installation
  108. service:
  109. daemon_reload: true
  110. when: "matrix_synapse_systemd_service_result.changed"
  111. - name: Ensure matrix-synapse-register-user script created
  112. template:
  113. src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2"
  114. dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user"
  115. mode: 0755