Matrix Docker Ansible eploy
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

130 righe
5.5 KiB

  1. # SPDX-FileCopyrightText: 2025 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2026 MDAD project contributors
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. ---
  6. - name: Ensure Commet paths exist
  7. ansible.builtin.file:
  8. path: "{{ item }}"
  9. state: directory
  10. mode: "0750"
  11. owner: "{{ matrix_user_name }}"
  12. group: "{{ matrix_group_name }}"
  13. with_items:
  14. - "{{ matrix_client_commet_base_path }}"
  15. - "{{ matrix_client_commet_config_path }}"
  16. # Self-build tasks — skipped when using a pre-built registry image
  17. - name: Check Commet git remote configuration
  18. ansible.builtin.command:
  19. cmd: git -C "{{ matrix_client_commet_container_src_path }}" remote get-url origin
  20. register: matrix_client_commet_git_remote_check
  21. failed_when: false
  22. changed_when: false
  23. when: matrix_client_commet_container_image_self_build | bool
  24. - name: Remove Commet source directory if git remote is misconfigured
  25. ansible.builtin.file:
  26. path: "{{ matrix_client_commet_container_src_path }}"
  27. state: absent
  28. when: matrix_client_commet_container_image_self_build | bool and matrix_client_commet_git_remote_check.rc != 0
  29. become: true
  30. - name: Ensure Commet repository is present
  31. ansible.builtin.git:
  32. repo: "{{ matrix_client_commet_container_image_self_build_repo }}"
  33. dest: "{{ matrix_client_commet_container_src_path }}"
  34. version: "{{ matrix_client_commet_version }}"
  35. depth: 1
  36. force: true
  37. become: true
  38. become_user: "{{ matrix_user_name }}"
  39. register: matrix_client_commet_git_result
  40. when: matrix_client_commet_container_image_self_build | bool
  41. - name: Capture git hash
  42. ansible.builtin.command:
  43. cmd: git -C {{ matrix_client_commet_container_src_path }} rev-parse --short HEAD
  44. register: matrix_client_commet_git_hash_result
  45. changed_when: false
  46. when: matrix_client_commet_container_image_self_build | bool
  47. - name: Set git hash fact
  48. ansible.builtin.set_fact:
  49. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_hash_result.stdout | trim }}"
  50. when: matrix_client_commet_container_image_self_build | bool
  51. - name: Build Commet Docker image
  52. ansible.builtin.command:
  53. cmd: |-
  54. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  55. --tag={{ matrix_client_commet_container_image }}
  56. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  57. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  58. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  59. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  60. {{ matrix_client_commet_container_src_path }}
  61. changed_when: true
  62. register: matrix_client_commet_image_build_result
  63. when: matrix_client_commet_container_image_self_build | bool
  64. - name: Ensure Commet container image is pulled
  65. community.docker.docker_image:
  66. name: "{{ matrix_client_fluffychat_container_image }}"
  67. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  68. force_source: "{{ matrix_client_fluffychat_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  69. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_client_fluffychat_container_image_force_pull }}"
  70. when: "not matrix_client_fluffychat_container_image_self_build | bool"
  71. register: matrix_client_commet_image_pull_result
  72. retries: "{{ devture_playbook_help_container_retries_count }}"
  73. delay: "{{ devture_playbook_help_container_retries_delay }}"
  74. until: matrix_client_commet_image_pull_result is not failed
  75. - name: Ensure Commet global_config.json is installed
  76. ansible.builtin.template:
  77. src: "{{ role_path }}/templates/global_config.json.j2"
  78. dest: "{{ matrix_client_commet_config_path }}/global_config.json"
  79. mode: "0644"
  80. owner: "{{ matrix_user_name }}"
  81. group: "{{ matrix_group_name }}"
  82. register: matrix_client_commet_config_result
  83. - name: Ensure Commet support files are installed
  84. ansible.builtin.template:
  85. src: "{{ item.src }}"
  86. dest: "{{ matrix_client_commet_base_path }}/{{ item.name }}"
  87. mode: "0644"
  88. owner: "{{ matrix_user_name }}"
  89. group: "{{ matrix_group_name }}"
  90. with_items:
  91. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  92. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  93. register: matrix_client_commet_support_files_result
  94. - name: Ensure Commet container network is created
  95. community.general.docker_network:
  96. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  97. name: "{{ matrix_client_commet_container_network }}"
  98. driver: bridge
  99. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  100. - name: Ensure matrix-client-commet.service is installed
  101. ansible.builtin.template:
  102. src: "{{ role_path }}/templates/systemd/matrix-client-commet.service.j2"
  103. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-commet.service"
  104. mode: "0644"
  105. register: matrix_client_commet_systemd_service_result
  106. - name: Determine whether Commet needs a restart
  107. ansible.builtin.set_fact:
  108. matrix_client_commet_restart_necessary: >-
  109. {{
  110. matrix_client_commet_config_result.changed | default(false)
  111. or matrix_client_commet_support_files_result.changed | default(false)
  112. or matrix_client_commet_systemd_service_result.changed | default(false)
  113. or matrix_client_commet_image_build_result.changed | default(false)
  114. or matrix_client_commet_image_pull_result.changed | default(false)
  115. }}