Matrix Docker Ansible eploy
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

127 Zeilen
5.7 KiB

  1. # SPDX-FileCopyrightText: 2023 - 2024 MDAD project contributors
  2. # SPDX-FileCopyrightText: 2023 Catalan Lover <catalanlover@protonmail.com>
  3. # SPDX-FileCopyrightText: 2024 David Mehren
  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_bot_draupnir_migration_requires_restart: false
  11. - name: Ensure matrix-bot-draupnir 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_bot_draupnir_base_path }}", when: true}
  20. - {path: "{{ matrix_bot_draupnir_config_path }}", when: true}
  21. - {path: "{{ matrix_bot_draupnir_data_path }}", when: true}
  22. - {path: "{{ matrix_bot_draupnir_container_src_files_path }}", when: "{{ matrix_bot_draupnir_container_image_self_build }}"}
  23. when: "item.when | bool"
  24. - name: Ensure matrix-bot-draupnir support files installed
  25. ansible.builtin.template:
  26. src: "{{ item.src }}"
  27. dest: "{{ item.dest }}"
  28. owner: "{{ matrix_user_name }}"
  29. group: "{{ matrix_group_name }}"
  30. mode: '0644'
  31. with_items:
  32. - src: "{{ role_path }}/templates/labels.j2"
  33. dest: "{{ matrix_bot_draupnir_base_path }}/labels"
  34. register: matrix_bot_draupnir_support_files_result
  35. - name: Ensure Draupnir Docker image is pulled
  36. community.docker.docker_image_pull:
  37. name: "{{ matrix_bot_draupnir_container_image }}"
  38. pull: always
  39. when: "not matrix_bot_draupnir_container_image_self_build | bool"
  40. register: matrix_bot_draupnir_container_image_pull_result
  41. retries: "{{ devture_playbook_help_container_retries_count }}"
  42. delay: "{{ devture_playbook_help_container_retries_delay }}"
  43. until: matrix_bot_draupnir_container_image_pull_result is not failed
  44. - name: Ensure Draupnir repository is present on self-build
  45. ansible.builtin.git:
  46. repo: "{{ matrix_bot_draupnir_container_image_self_build_repo }}"
  47. dest: "{{ matrix_bot_draupnir_container_src_files_path }}"
  48. version: "{{ matrix_bot_draupnir_container_image.split(':')[1] }}"
  49. force: "yes"
  50. become: true
  51. become_user: "{{ matrix_user_name }}"
  52. register: matrix_bot_draupnir_git_pull_results
  53. when: "matrix_bot_draupnir_container_image_self_build | bool"
  54. - name: Ensure Draupnir Docker image is built
  55. # Using docker_image_build with BuildKit for modern, efficient builds.
  56. # Rebuild when the git checkout advanced to a new commit; otherwise keep the build idempotent.
  57. # Technically the idempotency of rebuilds is more that if a build has already been executed for that name:tag
  58. # then we won't rebuild while in idempotent mode even if git moved. That's what the force rebuild logic is for.
  59. community.docker.docker_image_build:
  60. name: "{{ matrix_bot_draupnir_container_image }}"
  61. dockerfile: Dockerfile
  62. path: "{{ matrix_bot_draupnir_container_src_files_path }}"
  63. pull: true
  64. rebuild: "{{ 'always' if matrix_bot_draupnir_git_pull_results.changed | bool else 'never' }}"
  65. when: "matrix_bot_draupnir_container_image_self_build | bool"
  66. register: matrix_bot_draupnir_container_image_build_result
  67. - name: Ensure matrix-bot-draupnir config installed
  68. ansible.builtin.copy:
  69. content: "{{ matrix_bot_draupnir_configuration | to_nice_yaml(indent=2, width=999999) }}"
  70. dest: "{{ matrix_bot_draupnir_config_path }}/production.yaml"
  71. mode: '0644'
  72. owner: "{{ matrix_user_name }}"
  73. group: "{{ matrix_group_name }}"
  74. register: matrix_bot_draupnir_config_result
  75. - name: Ensure matrix-bot-draupnir container network is created
  76. community.general.docker_network:
  77. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  78. name: "{{ matrix_bot_draupnir_container_network }}"
  79. driver: bridge
  80. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  81. - name: Ensure matrix-bot-draupnir.service installed
  82. ansible.builtin.template:
  83. src: "{{ role_path }}/templates/systemd/matrix-bot-draupnir.service.j2"
  84. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-draupnir.service"
  85. mode: '0644'
  86. register: matrix_bot_draupnir_systemd_service_result
  87. # matrix-bot-draupnir and matrix-appservice-draupnir-for-all share the
  88. # same upstream container image. When both are enabled and force-pull is
  89. # on, the second role to run sees the image as already up-to-date (the
  90. # first role just pulled it), so its pull_result.changed is false and
  91. # conditional restart would skip it. To avoid that, we also treat
  92. # force-pull itself as a restart trigger for this role. The downside is
  93. # that both Draupnir services restart on every run when force-pull is
  94. # enabled (e.g. with rolling tags like `latest` or `main`), even when the
  95. # upstream image has not moved. That is wasteful but acceptable.
  96. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/5186
  97. - name: Determine whether Draupnir needs a restart
  98. ansible.builtin.set_fact:
  99. matrix_bot_draupnir_restart_necessary: >-
  100. {{
  101. matrix_bot_draupnir_migration_requires_restart | default(false)
  102. or matrix_bot_draupnir_support_files_result.changed | default(false)
  103. or matrix_bot_draupnir_config_result.changed | default(false)
  104. or matrix_bot_draupnir_systemd_service_result.changed | default(false)
  105. or matrix_bot_draupnir_container_image_pull_result.changed | default(false)
  106. or matrix_bot_draupnir_container_image_build_result.changed | default(false)
  107. or matrix_bot_draupnir_force_restart | bool
  108. }}
  109. - name: Ensure matrix-bot-draupnir.service restarted, if necessary
  110. ansible.builtin.service:
  111. name: "matrix-bot-draupnir.service"
  112. state: restarted
  113. daemon_reload: true
  114. when: "matrix_bot_draupnir_migration_requires_restart | bool"