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.
 
 

133 lines
5.9 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_registration_requires_restart: false
  7. - when: "matrix_registration_database_engine == 'postgres'"
  8. block:
  9. - name: Check if an SQLite database already exists
  10. ansible.builtin.stat:
  11. path: "{{ matrix_registration_sqlite_database_path_local }}"
  12. register: matrix_registration_sqlite_database_path_local_stat_result
  13. - when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists | bool"
  14. block:
  15. - ansible.builtin.include_role:
  16. name: galaxy/postgres
  17. tasks_from: migrate_db_to_postgres
  18. vars:
  19. postgres_db_migration_request:
  20. src: "{{ matrix_registration_sqlite_database_path_local }}"
  21. dst: "{{ matrix_registration_database_connection_string }}"
  22. caller: "{{ role_path | basename }}"
  23. engine_variable_name: 'matrix_registration_database_engine'
  24. engine_old: 'sqlite'
  25. systemd_services_to_stop: ['matrix-registration.service']
  26. # pgloader makes `ex_date` of type `TIMESTAMP WITH TIMEZONE`,
  27. # which makes matrix-registration choke on it later on when comparing dates.
  28. additional_psql_statements_list:
  29. - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE;
  30. additional_psql_statements_db_name: "{{ matrix_registration_database_name }}"
  31. - ansible.builtin.set_fact:
  32. matrix_registration_requires_restart: true
  33. - name: Ensure matrix-registration paths exist
  34. ansible.builtin.file:
  35. path: "{{ item.path }}"
  36. state: directory
  37. mode: 0750
  38. owner: "{{ matrix_user_username }}"
  39. group: "{{ matrix_user_groupname }}"
  40. with_items:
  41. - {path: "{{ matrix_registration_base_path }}", when: true}
  42. - {path: "{{ matrix_registration_config_path }}", when: true}
  43. - {path: "{{ matrix_registration_data_path }}", when: true}
  44. - {path: "{{ matrix_registration_docker_src_files_path }}", when: "{{ matrix_registration_container_image_self_build }}"}
  45. when: "item.when | bool"
  46. - name: Ensure matrix-registration image is pulled
  47. community.docker.docker_image:
  48. name: "{{ matrix_registration_docker_image }}"
  49. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  50. force_source: "{{ matrix_registration_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  51. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_registration_docker_image_force_pull }}"
  52. when: "not matrix_registration_container_image_self_build | bool"
  53. register: result
  54. retries: "{{ devture_playbook_help_container_retries_count }}"
  55. delay: "{{ devture_playbook_help_container_retries_delay }}"
  56. until: result is not failed
  57. - name: Ensure matrix-registration repository is present when self-building
  58. ansible.builtin.git:
  59. repo: "{{ matrix_registration_container_image_self_build_repo }}"
  60. dest: "{{ matrix_registration_docker_src_files_path }}"
  61. version: "{{ matrix_registration_container_image_self_build_branch }}"
  62. force: "yes"
  63. become: true
  64. become_user: "{{ matrix_user_username }}"
  65. register: matrix_registration_git_pull_results
  66. when: "matrix_registration_container_image_self_build | bool"
  67. # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1864
  68. - name: Patch setup.py to allow self-built version to work
  69. ansible.builtin.lineinfile:
  70. path: "{{ matrix_registration_docker_src_files_path }}/setup.py"
  71. regexp: 'flask-limiter'
  72. line: '"flask-limiter~=1.1.0", "Markupsafe<2.1",'
  73. when: "matrix_registration_container_image_self_build | bool and matrix_registration_container_image_self_build_python_dependencies_patch_enabled | bool"
  74. - name: Ensure matrix-registration Docker image is built
  75. community.docker.docker_image:
  76. name: "{{ matrix_registration_docker_image }}"
  77. source: build
  78. force_source: "{{ matrix_registration_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  79. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_registration_git_pull_results.changed }}"
  80. build:
  81. dockerfile: Dockerfile
  82. path: "{{ matrix_registration_docker_src_files_path }}"
  83. pull: true
  84. when: "matrix_registration_container_image_self_build | bool"
  85. - name: Ensure matrix-registration config installed
  86. ansible.builtin.copy:
  87. content: "{{ matrix_registration_configuration | to_nice_yaml(indent=2, width=999999) }}"
  88. dest: "{{ matrix_registration_config_path }}/config.yaml"
  89. mode: 0644
  90. owner: "{{ matrix_user_username }}"
  91. group: "{{ matrix_user_groupname }}"
  92. - name: Ensure matrix-registration support files installed
  93. ansible.builtin.template:
  94. src: "{{ role_path }}/templates/{{ item }}.j2"
  95. dest: "{{ matrix_registration_base_path }}/{{ item }}"
  96. mode: 0640
  97. owner: "{{ matrix_user_username }}"
  98. group: "{{ matrix_user_groupname }}"
  99. with_items:
  100. - labels
  101. - name: Ensure matrix-registration container network is created
  102. community.general.docker_network:
  103. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  104. name: "{{ matrix_registration_container_network }}"
  105. driver: bridge
  106. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  107. - name: Ensure matrix-registration.service installed
  108. ansible.builtin.template:
  109. src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2"
  110. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-registration.service"
  111. mode: 0644
  112. - name: Ensure matrix-registration.service restarted, if necessary
  113. ansible.builtin.service:
  114. name: "matrix-registration.service"
  115. state: restarted
  116. daemon_reload: true
  117. when: "matrix_registration_requires_restart | bool"