Matrix Docker Ansible eploy
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

154 satır
7.6 KiB

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