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

134 строки
7.0 KiB

  1. # SPDX-FileCopyrightText: 2024 David Mehren
  2. # SPDX-FileCopyrightText: 2024 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2024 - 2026 Catalan Lover <catalanlover@protonmail.com>
  4. # SPDX-FileCopyrightText: 2024 Slavi Pantaleev
  5. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  6. #
  7. # SPDX-License-Identifier: AGPL-3.0-or-later
  8. ---
  9. - ansible.builtin.set_fact:
  10. matrix_appservice_draupnir_for_all_migration_requires_restart: false
  11. - name: Ensure matrix-appservice-draupnir-for-all paths exist
  12. ansible.builtin.file:
  13. path: "{{ item.path }}"
  14. state: directory
  15. mode: '0750'
  16. owner: "{{ matrix_user_name }}"
  17. group: "{{ matrix_group_name }}"
  18. with_items:
  19. - {path: "{{ matrix_appservice_draupnir_for_all_base_path }}", when: true}
  20. - {path: "{{ matrix_appservice_draupnir_for_all_config_path }}", when: true}
  21. - {path: "{{ matrix_appservice_draupnir_for_all_data_path }}", when: true}
  22. - {path: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}", when: "{{ matrix_appservice_draupnir_for_all_container_image_self_build }}"}
  23. when: "item.when | bool"
  24. - name: Ensure Draupnir Docker image is pulled
  25. community.docker.docker_image_pull:
  26. name: "{{ matrix_appservice_draupnir_for_all_container_image }}"
  27. pull: always
  28. when: "not matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  29. register: matrix_appservice_draupnir_for_all_container_image_pull_result
  30. retries: "{{ devture_playbook_help_container_retries_count }}"
  31. delay: "{{ devture_playbook_help_container_retries_delay }}"
  32. until: matrix_appservice_draupnir_for_all_container_image_pull_result is not failed
  33. - name: Ensure Draupnir repository is present on self-build
  34. ansible.builtin.git:
  35. repo: "{{ matrix_appservice_draupnir_for_all_container_image_self_build_repo }}"
  36. dest: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}"
  37. version: "{{ matrix_appservice_draupnir_for_all_container_image.split(':')[1] }}"
  38. force: "yes"
  39. become: true
  40. become_user: "{{ matrix_user_name }}"
  41. register: matrix_appservice_draupnir_for_all_git_pull_results
  42. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  43. - name: Ensure Draupnir Docker image is built
  44. # Using docker_image_build with BuildKit for modern, efficient builds.
  45. # Rebuild when the git checkout advanced to a new commit; otherwise keep the build idempotent.
  46. # Technically the idempotency of rebuilds is more that if a build has already been executed for that name:tag
  47. # then we won't rebuild while in idempotent mode even if git moved. That's what the force rebuild logic is for.
  48. community.docker.docker_image_build:
  49. name: "{{ matrix_appservice_draupnir_for_all_container_image }}"
  50. dockerfile: Dockerfile
  51. path: "{{ matrix_appservice_draupnir_for_all_container_src_files_path }}"
  52. pull: true
  53. rebuild: "{{ 'always' if matrix_appservice_draupnir_for_all_git_pull_results.changed | bool else 'never' }}"
  54. when: "matrix_appservice_draupnir_for_all_container_image_self_build | bool"
  55. register: matrix_appservice_draupnir_for_all_container_image_build_result
  56. - name: Ensure matrix-appservice-draupnir-for-all appservice config installed
  57. ansible.builtin.copy:
  58. content: "{{ matrix_appservice_draupnir_for_all_configuration_appservice | to_nice_yaml(indent=2, width=999999) }}"
  59. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-appservice.yaml"
  60. mode: '0644'
  61. owner: "{{ matrix_user_name }}"
  62. group: "{{ matrix_group_name }}"
  63. register: matrix_appservice_draupnir_for_all_appservice_config_result
  64. - name: Ensure matrix-appservice-draupnir-for-all bot config installed
  65. ansible.builtin.copy:
  66. content: "{{ matrix_appservice_draupnir_for_all_configuration | to_nice_yaml(indent=2, width=999999) }}"
  67. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/production-bots.yaml"
  68. mode: '0644'
  69. owner: "{{ matrix_user_name }}"
  70. group: "{{ matrix_group_name }}"
  71. register: matrix_appservice_draupnir_for_all_bot_config_result
  72. - name: Ensure matrix-appservice-draupnir-for-all registration.yaml installed
  73. ansible.builtin.copy:
  74. content: "{{ matrix_appservice_draupnir_for_all_registration | to_nice_yaml(indent=2, width=999999) }}"
  75. dest: "{{ matrix_appservice_draupnir_for_all_config_path }}/draupnir-for-all-registration.yaml"
  76. mode: '0644'
  77. owner: "{{ matrix_user_name }}"
  78. group: "{{ matrix_group_name }}"
  79. register: matrix_appservice_draupnir_for_all_registration_config_result
  80. - name: Ensure matrix-appservice-draupnir-for-all container network is created
  81. community.general.docker_network:
  82. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  83. name: "{{ matrix_appservice_draupnir_for_all_container_network }}"
  84. driver: bridge
  85. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  86. - name: Ensure matrix-appservice-draupnir-for-all.service installed
  87. ansible.builtin.template:
  88. src: "{{ role_path }}/templates/systemd/matrix-appservice-draupnir-for-all.service.j2"
  89. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-draupnir-for-all.service"
  90. mode: '0644'
  91. register: matrix_appservice_draupnir_for_all_systemd_service_result
  92. # matrix-appservice-draupnir-for-all and matrix-bot-draupnir share the
  93. # same upstream container image. When both are enabled and force-pull is
  94. # on, the second role to run sees the image as already up-to-date (the
  95. # first role just pulled it), so its pull_result.changed is false and
  96. # conditional restart would skip it. To avoid that, we also treat
  97. # force-pull itself as a restart trigger for this role. The downside is
  98. # that both Draupnir services restart on every run when force-pull is
  99. # enabled (e.g. with rolling tags like `latest` or `main`), even when the
  100. # upstream image has not moved. That is wasteful but acceptable.
  101. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5186
  102. - name: Determine whether Draupnir for All needs a restart
  103. ansible.builtin.set_fact:
  104. matrix_appservice_draupnir_for_all_restart_necessary: >-
  105. {{
  106. matrix_appservice_draupnir_for_all_migration_requires_restart | default(false)
  107. or matrix_appservice_draupnir_for_all_appservice_config_result.changed | default(false)
  108. or matrix_appservice_draupnir_for_all_bot_config_result.changed | default(false)
  109. or matrix_appservice_draupnir_for_all_registration_config_result.changed | default(false)
  110. or matrix_appservice_draupnir_for_all_systemd_service_result.changed | default(false)
  111. or matrix_appservice_draupnir_for_all_container_image_pull_result.changed | default(false)
  112. or matrix_appservice_draupnir_for_all_container_image_build_result.changed | default(false)
  113. or matrix_appservice_draupnir_for_all_force_restart | bool
  114. }}
  115. - name: Ensure matrix-appservice-draupnir-for-all.service restarted, if necessary
  116. ansible.builtin.service:
  117. name: "matrix-appservice-draupnir-for-all.service"
  118. state: restarted
  119. daemon_reload: true
  120. when: "matrix_appservice_draupnir_for_all_migration_requires_restart | bool"