Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

151 строка
6.6 KiB

  1. # SPDX-FileCopyrightText: 2023 - 2024 Nikita Chernyi
  2. # SPDX-FileCopyrightText: 2023 - 2024 Slavi Pantaleev
  3. # SPDX-FileCopyrightText: 2024 Suguru Hirahara
  4. #
  5. # SPDX-License-Identifier: AGPL-3.0-or-later
  6. # mise (dev tool version manager)
  7. mise_data_dir := env("MISE_DATA_DIR", justfile_directory() / "var/mise")
  8. mise_trusted_config_paths := justfile_directory() / "mise.toml"
  9. prek_home := env("PREK_HOME", justfile_directory() / "var/prek")
  10. # Shows help
  11. default:
  12. @{{ just_executable() }} --list --justfile "{{ justfile() }}"
  13. # Initialize inventory files
  14. inventory domain ip:
  15. #!/usr/bin/env sh
  16. VARS_DIR="inventory/host_vars/{{ domain }}"
  17. VARS_FILE="inventory/host_vars/{{ domain }}/vars.yml"
  18. HOSTS_FILE="inventory/hosts"
  19. mkdir -p "$VARS_DIR"
  20. cp examples/vars.yml "$VARS_FILE"
  21. cp examples/hosts inventory/hosts
  22. sed -i 's/^matrix_domain:.*/matrix_domain: {{ domain }}/' "$VARS_FILE"
  23. PASSWORD=`openssl rand -base64 64 | head -c 64`; \
  24. sed -i "s#^matrix_homeserver_generic_secret_key:.*#matrix_homeserver_generic_secret_key: '$PASSWORD'#" "$VARS_FILE"
  25. sed -i 's/^matrix\.example\.com/{{ domain }}/' "$HOSTS_FILE"
  26. sed -i 's/ansible_host=<[^>]\+>/ansible_host={{ ip }}/' "$HOSTS_FILE"
  27. echo "Check and configure your files at:"
  28. echo $VARS_FILE
  29. echo $HOSTS_FILE
  30. # Pulls external Ansible roles
  31. roles:
  32. #!/usr/bin/env sh
  33. echo "[NOTE] This command just updates the roles, but if you want to update everything at once (playbook, roles, etc.) - use 'just update'"
  34. if [ -x "$(command -v agru)" ]; then
  35. agru
  36. else
  37. rm -rf roles/galaxy
  38. ansible-galaxy install -r requirements.yml -p roles/galaxy/ --force
  39. fi
  40. # Updates the playbook and installs the necessary Ansible roles pinned in requirements.yml. If a -u flag is passed, also updates the requirements.yml file with new role versions (if available)
  41. update *flags: update-playbook-only
  42. #!/usr/bin/env sh
  43. if [ -x "$(command -v agru)" ]; then
  44. echo {{ if flags == "" { "Installing roles pinned in requirements.yml…" } else { if flags == "-u" { "Updating roles and pinning new versions in requirements.yml…" } else { "Unknown flags passed" } } }}
  45. agru {{ flags }}
  46. else
  47. echo "[NOTE] You are using the standard ansible-galaxy tool to install roles, which is slow and lacks other features. We recommend installing the 'agru' tool to speed up the process: https://github.com/etkecc/agru#where-to-get"
  48. echo "Installing roles…"
  49. rm -rf roles/galaxy
  50. ansible-galaxy install -r requirements.yml -p roles/galaxy/ --force
  51. fi
  52. # Updates the playbook without installing/updating Ansible roles
  53. update-playbook-only:
  54. @echo "Updating playbook…"
  55. @git stash -q
  56. @git pull -q
  57. @-git stash pop -q
  58. # Invokes mise with the project-local data directory
  59. mise *args: _ensure_mise_data_directory
  60. #!/bin/sh
  61. export MISE_DATA_DIR="{{ mise_data_dir }}"
  62. export MISE_TRUSTED_CONFIG_PATHS="{{ mise_trusted_config_paths }}"
  63. export MISE_YES=1
  64. export PREK_HOME="{{ prek_home }}"
  65. mise {{ args }}
  66. # Runs prek (pre-commit hooks manager) with the given arguments
  67. prek *args: _ensure_mise_tools_installed
  68. @{{ just_executable() }} --justfile "{{ justfile() }}" mise exec -- prek {{ args }}
  69. # Runs pre-commit hooks on staged files
  70. prek-run-on-staged *args: _ensure_mise_tools_installed
  71. @{{ just_executable() }} --justfile "{{ justfile() }}" prek run {{ args }}
  72. # Runs pre-commit hooks on all files
  73. prek-run-on-all *args: _ensure_mise_tools_installed
  74. @{{ just_executable() }} --justfile "{{ justfile() }}" prek run --all-files {{ args }}
  75. # Installs the git pre-commit hook
  76. prek-install-git-pre-commit-hook: _ensure_mise_tools_installed
  77. #!/usr/bin/env sh
  78. set -eu
  79. {{ just_executable() }} --justfile "{{ justfile() }}" mise exec -- prek install
  80. hook="{{ justfile_directory() }}/.git/hooks/pre-commit"
  81. # The installed git hook runs later under Git, outside this just/mise environment.
  82. # Injecting PREK_HOME keeps prek's cache under var/prek instead of a global home dir,
  83. # which is more predictable and works better in sandboxed tools like Codex/OpenCode.
  84. if [ -f "$hook" ] && ! grep -q '^export PREK_HOME=' "$hook"; then
  85. sed -i '2iexport PREK_HOME="{{ prek_home }}"' "$hook"
  86. fi
  87. # Runs the playbook with --tags=install-all,ensure-matrix-users-created,start and optional arguments
  88. install-all *extra_args: (run-tags "install-all,ensure-matrix-users-created,start" extra_args)
  89. # Runs installation tasks for a single service
  90. install-service service *extra_args:
  91. {{ just_executable() }} --justfile "{{ justfile() }}" run \
  92. --tags=install-{{ service }},start-group \
  93. --extra-vars=group={{ service }} {{ extra_args }}
  94. # Runs the playbook with --tags=setup-all,ensure-matrix-users-created,start and optional arguments
  95. setup-all *extra_args: (run-tags "setup-all,ensure-matrix-users-created,start" extra_args)
  96. # Runs the playbook with the given list of arguments
  97. run +extra_args:
  98. ansible-playbook -i inventory/hosts setup.yml {{ extra_args }}
  99. # Runs the playbook with the given list of comma-separated tags and optional arguments
  100. run-tags tags *extra_args:
  101. {{ just_executable() }} --justfile "{{ justfile() }}" run --tags={{ tags }} {{ extra_args }}
  102. # Runs the playbook in user-registration mode
  103. register-user username password admin_yes_or_no *extra_args:
  104. ansible-playbook -i inventory/hosts setup.yml --tags=register-user --extra-vars="username={{ username }} password={{ password }} admin={{ admin_yes_or_no }}" {{ extra_args }}
  105. # Starts all services
  106. start-all *extra_args: (run-tags "start-all" extra_args)
  107. # Starts a specific service group
  108. start-group group *extra_args:
  109. @{{ just_executable() }} --justfile "{{ justfile() }}" run-tags start-group --extra-vars="group={{ group }}" {{ extra_args }}
  110. # Stops all services
  111. stop-all *extra_args: (run-tags "stop-all" extra_args)
  112. # Stops a specific service group
  113. stop-group group *extra_args:
  114. @{{ just_executable() }} --justfile "{{ justfile() }}" run-tags stop-group --extra-vars="group={{ group }}" {{ extra_args }}
  115. # Rebuilds the mautrix-meta-instagram Ansible role using the mautrix-meta-messenger role as a source
  116. rebuild-mautrix-meta-instagram:
  117. /bin/bash "{{ justfile_directory() }}/bin/rebuild-mautrix-meta-instagram.sh" "{{ justfile_directory() }}/roles/custom"
  118. # Internal - ensures var/mise and var/prek directories exist
  119. _ensure_mise_data_directory:
  120. @mkdir -p "{{ mise_data_dir }}"
  121. @mkdir -p "{{ prek_home }}"
  122. # Internal - ensures mise tools are installed
  123. _ensure_mise_tools_installed: _ensure_mise_data_directory
  124. @{{ just_executable() }} --justfile "{{ justfile() }}" mise install --quiet