Matrix Docker Ansible eploy
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 lines
3.5 KiB

  1. # SPDX-FileCopyrightText: 2026 Slavi Pantaleev
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. # Stands up a stand-in homeserver on a container network, for scenarios whose
  6. # component contacts a homeserver while starting up.
  7. #
  8. # Include from a scenario's prepare.yml:
  9. #
  10. # - name: Ensure the homeserver stub is running
  11. # ansible.builtin.include_tasks:
  12. # file: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/tasks/homeserver-stub.yml"
  13. # vars:
  14. # molecule_shared_stub_network: "{{ <role>_container_network }}"
  15. # molecule_shared_stub_joined_rooms: ["!some-room:molecule.local"]
  16. #
  17. # The component should then be pointed at http://matrix.molecule.local:8008.
  18. #
  19. # See molecule-shared/homeserver-stub.py for what it answers and, more
  20. # importantly, for what it is not.
  21. - name: Ensure the homeserver stub script is present
  22. ansible.builtin.copy:
  23. src: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/../../../molecule-shared/homeserver-stub.py"
  24. dest: /root/molecule-homeserver-stub.py
  25. mode: "0755"
  26. - name: Ensure a previous homeserver stub is gone
  27. ansible.builtin.command:
  28. argv:
  29. - docker
  30. - rm
  31. - --force
  32. - "{{ molecule_shared_stub_name | default('matrix-homeserver-stub') }}"
  33. register: molecule_shared_stub_removal
  34. changed_when: molecule_shared_stub_removal.rc == 0
  35. failed_when: false
  36. # The alias is what the component resolves, so its configuration can name a
  37. # hostname rather than a container name.
  38. - name: Ensure the homeserver stub is running
  39. ansible.builtin.command:
  40. argv:
  41. - docker
  42. - run
  43. - --detach
  44. - --name={{ molecule_shared_stub_name | default('matrix-homeserver-stub') }}
  45. - --network={{ molecule_shared_stub_network }}
  46. - --network-alias={{ molecule_shared_stub_hostname | default('matrix.molecule.local') }}
  47. - --env=STUB_SERVER_NAME={{ molecule_shared_stub_server_name | default('molecule.local') }}
  48. - --env=STUB_JOINED_ROOMS={{ (molecule_shared_stub_joined_rooms | default([])) | join(',') }}
  49. # Appservices call /whoami on startup and refuse to run if the id
  50. # returned is not the bot user they were configured as, so a scenario
  51. # bridging anything has to tell the stub who it should claim to be.
  52. - --env=STUB_USER_ID={{ molecule_shared_stub_user_id | default('@stub:' + (molecule_shared_stub_server_name | default('molecule.local'))) }}
  53. # Off by default. Set molecule_shared_stub_verbose to "1" to have the stub
  54. # log every request it is asked for, which is both how you find out why a
  55. # component will not start and - for a component that exposes no port of
  56. # its own - the only place a scenario can observe it acting on what the
  57. # role configured.
  58. - --env=STUB_VERBOSE={{ molecule_shared_stub_verbose | default('') }}
  59. - --volume=/root/molecule-homeserver-stub.py:/stub.py:ro
  60. - "{{ molecule_shared_image_python }}"
  61. - python3
  62. - /stub.py
  63. register: molecule_shared_stub_start
  64. changed_when: molecule_shared_stub_start.rc == 0
  65. - name: Wait for the homeserver stub to answer
  66. ansible.builtin.command:
  67. argv:
  68. - docker
  69. - run
  70. - --rm
  71. - --network={{ molecule_shared_stub_network }}
  72. - "{{ molecule_shared_image_curl }}"
  73. - --silent
  74. - --fail
  75. - --max-time
  76. - "5"
  77. - "http://{{ molecule_shared_stub_hostname | default('matrix.molecule.local') }}:8008/_matrix/client/versions"
  78. register: molecule_shared_stub_ready
  79. changed_when: false
  80. until: molecule_shared_stub_ready.rc == 0
  81. retries: 12
  82. delay: 5