Matrix Docker Ansible eploy
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

138 linhas
5.7 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  3. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  6. # SPDX-FileCopyrightText: 2024 David Mehren
  7. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - ansible.builtin.set_fact:
  12. matrix_bot_honoroit_migration_requires_restart: false
  13. - when: "matrix_bot_honoroit_database_engine == 'postgres'"
  14. block:
  15. - name: Check if an SQLite database already exists
  16. ansible.builtin.stat:
  17. path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  18. register: matrix_bot_honoroit_sqlite_database_path_local_stat_result
  19. - when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists | bool"
  20. block:
  21. - ansible.builtin.include_role:
  22. name: galaxy/postgres
  23. tasks_from: migrate_db_to_postgres
  24. vars:
  25. postgres_db_migration_request:
  26. src: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  27. dst: "{{ matrix_bot_honoroit_database_connection_string }}"
  28. caller: "{{ role_path | basename }}"
  29. engine_variable_name: 'matrix_bot_honoroit_database_engine'
  30. engine_old: 'sqlite'
  31. systemd_services_to_stop: ['matrix-bot-honoroit.service']
  32. - ansible.builtin.set_fact:
  33. matrix_bot_honoroit_migration_requires_restart: true
  34. - name: Ensure Honoroit paths exist
  35. ansible.builtin.file:
  36. path: "{{ item.path }}"
  37. state: directory
  38. mode: '0750'
  39. owner: "{{ matrix_user_name }}"
  40. group: "{{ matrix_group_name }}"
  41. with_items:
  42. - {path: "{{ matrix_bot_honoroit_config_path }}", when: true}
  43. - {path: "{{ matrix_bot_honoroit_data_path }}", when: true}
  44. - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true}
  45. - {path: "{{ matrix_bot_honoroit_container_src_files_path }}", when: true}
  46. when: "item.when | bool"
  47. - name: Ensure Honoroit support files installed
  48. ansible.builtin.template:
  49. src: "{{ role_path }}/templates/{{ item }}.j2"
  50. dest: "{{ matrix_bot_honoroit_config_path }}/{{ item }}"
  51. owner: "{{ matrix_user_name }}"
  52. group: "{{ matrix_group_name }}"
  53. mode: '0640'
  54. with_items:
  55. - env
  56. - labels
  57. register: matrix_bot_honoroit_support_files_result
  58. - name: Ensure Honoroit image is pulled
  59. community.docker.docker_image_pull:
  60. name: "{{ matrix_bot_honoroit_container_image }}"
  61. pull: always
  62. when: "not matrix_bot_honoroit_container_image_self_build | bool"
  63. register: matrix_bot_honoroit_container_image_pull_result
  64. retries: "{{ devture_playbook_help_container_retries_count }}"
  65. delay: "{{ devture_playbook_help_container_retries_delay }}"
  66. until: matrix_bot_honoroit_container_image_pull_result is not failed
  67. # A checkout owned by a different user (a uid change, an earlier clone by another user, etc.) would make the git task below fail on ownership or permissions.
  68. - name: Ensure Honoroit repository ownership is correct on self-build
  69. ansible.builtin.file:
  70. path: "{{ matrix_bot_honoroit_container_src_files_path }}"
  71. state: directory
  72. owner: "{{ matrix_user_name }}"
  73. group: "{{ matrix_group_name }}"
  74. recurse: true
  75. when: "matrix_bot_honoroit_container_image_self_build | bool"
  76. - name: Ensure Honoroit repository is present on self-build
  77. ansible.builtin.git:
  78. repo: "{{ matrix_bot_honoroit_container_repo }}"
  79. version: "{{ matrix_bot_honoroit_container_repo_version }}"
  80. dest: "{{ matrix_bot_honoroit_container_src_files_path }}"
  81. force: "yes"
  82. become: true
  83. become_user: "{{ matrix_user_name }}"
  84. register: matrix_bot_honoroit_git_pull_results
  85. when: "matrix_bot_honoroit_container_image_self_build | bool"
  86. - name: Ensure Honoroit image is built
  87. community.docker.docker_image_build:
  88. name: "{{ matrix_bot_honoroit_container_image }}"
  89. dockerfile: Dockerfile
  90. path: "{{ matrix_bot_honoroit_container_src_files_path }}"
  91. pull: true
  92. rebuild: "{{ 'always' if matrix_bot_honoroit_git_pull_results.changed | bool else 'never' }}"
  93. when: "matrix_bot_honoroit_container_image_self_build | bool"
  94. register: matrix_bot_honoroit_container_image_build_result
  95. - name: Ensure Honoroit container network is created
  96. when: matrix_bot_honoroit_container_network != 'host'
  97. community.general.docker_network:
  98. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  99. name: "{{ matrix_bot_honoroit_container_network }}"
  100. driver: bridge
  101. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  102. - name: Ensure matrix-bot-honoroit.service installed
  103. ansible.builtin.template:
  104. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  105. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-honoroit.service"
  106. mode: '0644'
  107. register: matrix_bot_honoroit_systemd_service_result
  108. - name: Determine whether Honoroit needs a restart
  109. ansible.builtin.set_fact:
  110. matrix_bot_honoroit_restart_necessary: >-
  111. {{
  112. matrix_bot_honoroit_migration_requires_restart | default(false)
  113. or matrix_bot_honoroit_support_files_result.changed | default(false)
  114. or matrix_bot_honoroit_systemd_service_result.changed | default(false)
  115. or matrix_bot_honoroit_container_image_pull_result.changed | default(false)
  116. or matrix_bot_honoroit_container_image_build_result.changed | default(false)
  117. }}
  118. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  119. ansible.builtin.service:
  120. name: "matrix-bot-honoroit.service"
  121. state: restarted
  122. daemon_reload: true
  123. when: "matrix_bot_honoroit_migration_requires_restart | bool"