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.
 
 

163 lines
8.0 KiB

  1. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2020 Stuart Mumford
  3. # SPDX-FileCopyrightText: 2021 MDAD project contributors
  4. # SPDX-FileCopyrightText: 2021 Yannick Goossens
  5. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  6. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  7. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  8. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  9. # SPDX-FileCopyrightText: 2024 David Mehren
  10. # SPDX-FileCopyrightText: 2025 Suguru Hirahara
  11. #
  12. # SPDX-License-Identifier: AGPL-3.0-or-later
  13. ---
  14. - ansible.builtin.set_fact:
  15. matrix_dimension_requires_restart: false
  16. - when: "matrix_dimension_database_engine == 'postgres'"
  17. block:
  18. - name: Check if an SQLite database already exists
  19. ansible.builtin.stat:
  20. path: "{{ matrix_dimension_sqlite_database_path_local }}"
  21. register: matrix_dimension_sqlite_database_path_local_stat_result
  22. - when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists | bool"
  23. block:
  24. # pgloader makes a few columns `smallint`, instead of `boolean`.
  25. # We need to fix them up.
  26. - ansible.builtin.set_fact:
  27. matrix_dimension_pgloader_additional_psql_statements_list: []
  28. - ansible.builtin.set_fact:
  29. matrix_dimension_pgloader_additional_psql_statements_list: |
  30. {{
  31. matrix_dimension_pgloader_additional_psql_statements_list
  32. +
  33. ([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" DROP default;'])
  34. +
  35. (['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" TYPE BOOLEAN USING("' + item.column + '"::text::boolean);'])
  36. +
  37. ([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" SET default ' + item.default + ';'])
  38. }}
  39. with_items:
  40. - {'table': 'dimension_widgets', 'column': 'isEnabled', 'default': ''}
  41. - {'table': 'dimension_widgets', 'column': 'isPublic', 'default': ''}
  42. - {'table': 'dimension_webhook_bridges', 'column': 'isEnabled', 'default': ''}
  43. - {'table': 'dimension_user_sticker_packs', 'column': 'isSelected', 'default': ''}
  44. - {'table': 'dimension_scalar_tokens', 'column': 'isDimensionToken', 'default': ''}
  45. - {'table': 'dimension_users', 'column': 'isSelfBot', 'default': 'false'}
  46. - {'table': 'dimension_telegram_bridges', 'column': 'allowTgPuppets', 'default': ''}
  47. - {'table': 'dimension_telegram_bridges', 'column': 'allowMxPuppets', 'default': ''}
  48. - {'table': 'dimension_telegram_bridges', 'column': 'isEnabled', 'default': ''}
  49. - {'table': 'dimension_sticker_packs', 'column': 'isEnabled', 'default': ''}
  50. - {'table': 'dimension_sticker_packs', 'column': 'isPublic', 'default': ''}
  51. - {'table': 'dimension_slack_bridges', 'column': 'isEnabled', 'default': ''}
  52. - {'table': 'dimension_neb_integrations', 'column': 'isPublic', 'default': ''}
  53. - {'table': 'dimension_neb_integrations', 'column': 'isEnabled', 'default': ''}
  54. - {'table': 'dimension_irc_bridges', 'column': 'isEnabled', 'default': ''}
  55. - {'table': 'dimension_irc_bridge_networks', 'column': 'isEnabled', 'default': ''}
  56. - {'table': 'dimension_gitter_bridges', 'column': 'isEnabled', 'default': ''}
  57. - {'table': 'dimension_custom_simple_bots', 'column': 'isEnabled', 'default': ''}
  58. - {'table': 'dimension_custom_simple_bots', 'column': 'isPublic', 'default': ''}
  59. - {'table': 'dimension_bridges', 'column': 'isEnabled', 'default': ''}
  60. - {'table': 'dimension_bridges', 'column': 'isPublic', 'default': ''}
  61. - ansible.builtin.include_role:
  62. name: galaxy/postgres
  63. tasks_from: migrate_db_to_postgres
  64. vars:
  65. postgres_db_migration_request:
  66. src: "{{ matrix_dimension_sqlite_database_path_local }}"
  67. dst: "{{ matrix_dimension_database_connection_string }}"
  68. caller: "{{ role_path | basename }}"
  69. engine_variable_name: 'matrix_dimension_database_engine'
  70. engine_old: 'sqlite'
  71. systemd_services_to_stop: ['matrix-dimension.service']
  72. pgloader_options: ['--with "quote identifiers"']
  73. additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}"
  74. additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}"
  75. - ansible.builtin.set_fact:
  76. matrix_dimension_requires_restart: true
  77. - name: Ensure Dimension base path exists
  78. ansible.builtin.file:
  79. path: "{{ matrix_dimension_base_path }}"
  80. state: directory
  81. mode: 0770
  82. owner: "{{ matrix_user_name }}"
  83. group: "{{ matrix_dimension_user_gid }}"
  84. - name: Ensure Dimension config installed
  85. ansible.builtin.copy:
  86. content: "{{ matrix_dimension_configuration | to_nice_yaml(indent=2, width=999999) }}"
  87. dest: "{{ matrix_dimension_base_path }}/config.yaml"
  88. mode: 0640
  89. owner: "{{ matrix_user_name }}"
  90. group: "{{ matrix_dimension_user_gid }}"
  91. - name: Ensure Dimension labels installed
  92. ansible.builtin.template:
  93. src: "{{ role_path }}/templates/labels.j2"
  94. dest: "{{ matrix_dimension_base_path }}/labels"
  95. mode: 0640
  96. owner: "{{ matrix_user_name }}"
  97. group: "{{ matrix_group_name }}"
  98. - name: Ensure Dimension image is pulled
  99. community.docker.docker_image:
  100. name: "{{ matrix_dimension_docker_image }}"
  101. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  102. force_source: "{{ matrix_dimension_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  103. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dimension_docker_image_force_pull }}"
  104. when: "not matrix_dimension_container_image_self_build | bool"
  105. register: matrix_dimension_pull_results
  106. retries: "{{ devture_playbook_help_container_retries_count }}"
  107. delay: "{{ devture_playbook_help_container_retries_delay }}"
  108. until: matrix_dimension_pull_results is not failed
  109. - name: Ensure Dimension repository is present on self-build
  110. ansible.builtin.git:
  111. repo: "{{ matrix_dimension_container_image_self_build_repo }}"
  112. dest: "{{ matrix_dimension_docker_src_files_path }}"
  113. version: "{{ matrix_dimension_container_image_self_build_branch }}"
  114. force: "yes"
  115. become: true
  116. become_user: "{{ matrix_user_name }}"
  117. when: "matrix_dimension_container_image_self_build | bool"
  118. register: matrix_dimension_git_pull_results
  119. - name: Ensure Dimension Docker image is built
  120. community.docker.docker_image:
  121. name: "{{ matrix_dimension_docker_image }}"
  122. source: build
  123. force_source: "{{ matrix_dimension_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  124. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dimension_git_pull_results.changed }}"
  125. build:
  126. dockerfile: Dockerfile
  127. path: "{{ matrix_dimension_docker_src_files_path }}"
  128. pull: true
  129. when: "matrix_dimension_container_image_self_build | bool"
  130. - name: Ensure Dimension container network is created
  131. community.general.docker_network:
  132. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  133. name: "{{ matrix_dimension_container_network }}"
  134. driver: bridge
  135. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  136. - name: Ensure matrix-dimension.service installed
  137. ansible.builtin.template:
  138. src: "{{ role_path }}/templates/systemd/matrix-dimension.service.j2"
  139. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-dimension.service"
  140. mode: 0644
  141. - name: Ensure matrix-dimension.service restarted, if necessary
  142. ansible.builtin.service:
  143. name: "matrix-dimension.service"
  144. state: restarted
  145. daemon_reload: true
  146. when: "matrix_dimension_requires_restart | bool"