Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

128 lines
5.4 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 on self-build
  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. force: "yes"
  36. become: true
  37. become_user: "{{ matrix_user_name }}"
  38. register: matrix_client_commet_git_pull_results
  39. - name: Capture git hash
  40. ansible.builtin.command:
  41. cmd: git -C {{ matrix_client_commet_container_src_path }} rev-parse --short HEAD
  42. register: matrix_client_commet_git_hash_result
  43. changed_when: false
  44. when: matrix_client_commet_container_image_self_build | bool
  45. - name: Set git hash fact
  46. ansible.builtin.set_fact:
  47. matrix_client_commet_container_image_self_build_git_hash: "{{ matrix_client_commet_git_hash_result.stdout | trim }}"
  48. when: matrix_client_commet_container_image_self_build | bool
  49. - name: Build Commet Docker image
  50. ansible.builtin.command:
  51. cmd: |-
  52. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  53. --tag={{ matrix_client_commet_container_image }}
  54. --build-arg GIT_HASH={{ matrix_client_commet_container_image_self_build_git_hash }}
  55. --build-arg VERSION_TAG={{ matrix_client_commet_container_image_self_build_version_tag }}
  56. --build-arg BUILD_DATE={{ ansible_date_time.epoch }}
  57. --file={{ matrix_client_commet_container_src_path }}/Dockerfile
  58. {{ matrix_client_commet_container_src_path }}
  59. changed_when: true
  60. register: matrix_client_commet_image_build_result
  61. when: matrix_client_commet_container_image_self_build | bool
  62. - name: Ensure Commet container image is pulled
  63. community.docker.docker_image:
  64. name: "{{ matrix_client_commet_container_image }}"
  65. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  66. force_source: "{{ matrix_client_commet_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  67. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_client_commet_container_image_force_pull }}"
  68. when: "not matrix_client_commet_container_image_self_build | bool"
  69. register: matrix_client_commet_image_pull_result
  70. retries: "{{ devture_playbook_help_container_retries_count }}"
  71. delay: "{{ devture_playbook_help_container_retries_delay }}"
  72. until: matrix_client_commet_image_pull_result is not failed
  73. - name: Ensure Commet global_config.json is installed
  74. ansible.builtin.template:
  75. src: "{{ role_path }}/templates/global_config.json.j2"
  76. dest: "{{ matrix_client_commet_config_path }}/global_config.json"
  77. mode: "0644"
  78. owner: "{{ matrix_user_name }}"
  79. group: "{{ matrix_group_name }}"
  80. register: matrix_client_commet_config_result
  81. - name: Ensure Commet support files are installed
  82. ansible.builtin.template:
  83. src: "{{ item.src }}"
  84. dest: "{{ matrix_client_commet_base_path }}/{{ item.name }}"
  85. mode: "0644"
  86. owner: "{{ matrix_user_name }}"
  87. group: "{{ matrix_group_name }}"
  88. with_items:
  89. - {src: "{{ role_path }}/templates/labels.j2", name: "labels"}
  90. - {src: "{{ role_path }}/templates/env.j2", name: "env"}
  91. register: matrix_client_commet_support_files_result
  92. - name: Ensure Commet container network is created
  93. community.general.docker_network:
  94. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  95. name: "{{ matrix_client_commet_container_network }}"
  96. driver: bridge
  97. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  98. - name: Ensure matrix-client-commet.service is installed
  99. ansible.builtin.template:
  100. src: "{{ role_path }}/templates/systemd/matrix-client-commet.service.j2"
  101. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-client-commet.service"
  102. mode: "0644"
  103. register: matrix_client_commet_systemd_service_result
  104. - name: Determine whether Commet needs a restart
  105. ansible.builtin.set_fact:
  106. matrix_client_commet_restart_necessary: >-
  107. {{
  108. matrix_client_commet_config_result.changed | default(false)
  109. or matrix_client_commet_support_files_result.changed | default(false)
  110. or matrix_client_commet_systemd_service_result.changed | default(false)
  111. or matrix_client_commet_image_build_result.changed | default(false)
  112. or matrix_client_commet_image_pull_result.changed | default(false)
  113. }}