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.
 
 

150 lines
6.5 KiB

  1. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2020 Stuart Mumford
  3. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  4. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  5. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  6. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  7. # SPDX-FileCopyrightText: 2024 David Mehren
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - ansible.builtin.set_fact:
  12. matrix_registration_migration_requires_restart: false
  13. - when: "matrix_registration_database_engine == 'postgres'"
  14. block:
  15. - name: Check if an SQLite database already exists
  16. ansible.builtin.stat:
  17. path: "{{ matrix_registration_sqlite_database_path_local }}"
  18. register: matrix_registration_sqlite_database_path_local_stat_result
  19. - when: "matrix_registration_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_registration_sqlite_database_path_local }}"
  27. dst: "{{ matrix_registration_database_connection_string }}"
  28. caller: "{{ role_path | basename }}"
  29. engine_variable_name: 'matrix_registration_database_engine'
  30. engine_old: 'sqlite'
  31. systemd_services_to_stop: ['matrix-registration.service']
  32. # pgloader makes `ex_date` of type `TIMESTAMP WITH TIMEZONE`,
  33. # which makes matrix-registration choke on it later on when comparing dates.
  34. additional_psql_statements_list:
  35. - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE;
  36. additional_psql_statements_db_name: "{{ matrix_registration_database_name }}"
  37. - ansible.builtin.set_fact:
  38. matrix_registration_migration_requires_restart: true
  39. - name: Ensure matrix-registration paths exist
  40. ansible.builtin.file:
  41. path: "{{ item.path }}"
  42. state: directory
  43. mode: '0750'
  44. owner: "{{ matrix_user_name }}"
  45. group: "{{ matrix_group_name }}"
  46. with_items:
  47. - {path: "{{ matrix_registration_base_path }}", when: true}
  48. - {path: "{{ matrix_registration_config_path }}", when: true}
  49. - {path: "{{ matrix_registration_data_path }}", when: true}
  50. - {path: "{{ matrix_registration_container_src_files_path }}", when: "{{ matrix_registration_container_image_self_build }}"}
  51. when: "item.when | bool"
  52. - name: Ensure matrix-registration image is pulled
  53. community.docker.docker_image_pull:
  54. name: "{{ matrix_registration_container_image }}"
  55. pull: always
  56. when: "not matrix_registration_container_image_self_build | bool"
  57. register: matrix_registration_container_image_pull_result
  58. retries: "{{ devture_playbook_help_container_retries_count }}"
  59. delay: "{{ devture_playbook_help_container_retries_delay }}"
  60. until: matrix_registration_container_image_pull_result is not failed
  61. - name: Ensure matrix-registration repository is present when self-building
  62. ansible.builtin.git:
  63. repo: "{{ matrix_registration_container_image_self_build_repo }}"
  64. dest: "{{ matrix_registration_container_src_files_path }}"
  65. version: "{{ matrix_registration_container_image_self_build_branch }}"
  66. force: "yes"
  67. become: true
  68. become_user: "{{ matrix_user_name }}"
  69. register: matrix_registration_git_pull_results
  70. when: "matrix_registration_container_image_self_build | bool"
  71. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1864
  72. - name: Patch setup.py to allow self-built version to work
  73. ansible.builtin.lineinfile:
  74. path: "{{ matrix_registration_container_src_files_path }}/setup.py"
  75. regexp: 'flask-limiter'
  76. line: '"flask-limiter~=1.1.0", "Markupsafe<2.1",'
  77. when: "matrix_registration_container_image_self_build | bool and matrix_registration_container_image_self_build_python_dependencies_patch_enabled | bool"
  78. - name: Ensure matrix-registration Docker image is built
  79. community.docker.docker_image_build:
  80. name: "{{ matrix_registration_container_image }}"
  81. dockerfile: Dockerfile
  82. path: "{{ matrix_registration_container_src_files_path }}"
  83. pull: true
  84. rebuild: "{{ 'always' if matrix_registration_git_pull_results.changed | bool else 'never' }}"
  85. when: "matrix_registration_container_image_self_build | bool"
  86. register: matrix_registration_container_image_build_result
  87. - name: Ensure matrix-registration config installed
  88. ansible.builtin.copy:
  89. content: "{{ matrix_registration_configuration | to_nice_yaml(indent=2, width=999999) }}"
  90. dest: "{{ matrix_registration_config_path }}/config.yaml"
  91. mode: '0644'
  92. owner: "{{ matrix_user_name }}"
  93. group: "{{ matrix_group_name }}"
  94. register: matrix_registration_config_result
  95. - name: Ensure matrix-registration support files installed
  96. ansible.builtin.template:
  97. src: "{{ role_path }}/templates/{{ item }}.j2"
  98. dest: "{{ matrix_registration_base_path }}/{{ item }}"
  99. mode: '0640'
  100. owner: "{{ matrix_user_name }}"
  101. group: "{{ matrix_group_name }}"
  102. with_items:
  103. - labels
  104. register: matrix_registration_support_files_result
  105. - name: Ensure matrix-registration container network is created
  106. community.general.docker_network:
  107. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  108. name: "{{ matrix_registration_container_network }}"
  109. driver: bridge
  110. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  111. - name: Ensure matrix-registration.service installed
  112. ansible.builtin.template:
  113. src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2"
  114. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-registration.service"
  115. mode: '0644'
  116. register: matrix_registration_systemd_service_result
  117. - name: Determine whether matrix-registration needs a restart
  118. ansible.builtin.set_fact:
  119. matrix_registration_restart_necessary: >-
  120. {{
  121. matrix_registration_migration_requires_restart | default(false)
  122. or matrix_registration_config_result.changed | default(false)
  123. or matrix_registration_support_files_result.changed | default(false)
  124. or matrix_registration_systemd_service_result.changed | default(false)
  125. or matrix_registration_container_image_pull_result.changed | default(false)
  126. or matrix_registration_container_image_build_result.changed | default(false)
  127. }}
  128. - name: Ensure matrix-registration.service restarted, if necessary
  129. ansible.builtin.service:
  130. name: "matrix-registration.service"
  131. state: restarted
  132. daemon_reload: true
  133. when: "matrix_registration_migration_requires_restart | bool"