Matrix Docker Ansible eploy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

135 linhas
6.1 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. # Adds a new host to the inventory, creating the inventory files if necessary (e.g. `just add-inventory-host example.com 1.2.3.4`)
  14. add-inventory-host domain server_address:
  15. @{{ justfile_directory() }}/bin/add-inventory-host.sh {{ quote(domain) }} {{ quote(server_address) }}
  16. # Pulls external Ansible roles
  17. roles:
  18. #!/usr/bin/env sh
  19. echo "[NOTE] This command just updates the roles, but if you want to update everything at once (playbook, roles, etc.) - use 'just update'"
  20. if [ -x "$(command -v agru)" ]; then
  21. agru
  22. else
  23. rm -rf roles/galaxy
  24. ansible-galaxy install -r requirements.yml -p roles/galaxy/ --force
  25. fi
  26. # 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)
  27. update *flags: update-playbook-only
  28. #!/usr/bin/env sh
  29. if [ -x "$(command -v agru)" ]; then
  30. 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" } } }}
  31. agru {{ flags }}
  32. else
  33. 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"
  34. echo "Installing roles…"
  35. rm -rf roles/galaxy
  36. ansible-galaxy install -r requirements.yml -p roles/galaxy/ --force
  37. fi
  38. # Updates the playbook without installing/updating Ansible roles
  39. update-playbook-only:
  40. @echo "Updating playbook…"
  41. @git stash -q
  42. @git pull -q
  43. @-git stash pop -q
  44. # Invokes mise with the project-local data directory
  45. mise *args: _ensure_mise_data_directory
  46. #!/bin/sh
  47. export MISE_DATA_DIR="{{ mise_data_dir }}"
  48. export MISE_TRUSTED_CONFIG_PATHS="{{ mise_trusted_config_paths }}"
  49. export MISE_YES=1
  50. export PREK_HOME="{{ prek_home }}"
  51. mise {{ args }}
  52. # Runs prek (pre-commit hooks manager) with the given arguments
  53. prek *args: _ensure_mise_tools_installed
  54. @{{ just_executable() }} --justfile "{{ justfile() }}" mise exec -- prek {{ args }}
  55. # Runs pre-commit hooks on staged files
  56. prek-run-on-staged *args: _ensure_mise_tools_installed
  57. @{{ just_executable() }} --justfile "{{ justfile() }}" prek run {{ args }}
  58. # Runs pre-commit hooks on all files
  59. prek-run-on-all *args: _ensure_mise_tools_installed
  60. @{{ just_executable() }} --justfile "{{ justfile() }}" prek run --all-files {{ args }}
  61. # Installs the git pre-commit hook
  62. prek-install-git-pre-commit-hook: _ensure_mise_tools_installed
  63. #!/usr/bin/env sh
  64. set -eu
  65. {{ just_executable() }} --justfile "{{ justfile() }}" mise exec -- prek install
  66. hook="{{ justfile_directory() }}/.git/hooks/pre-commit"
  67. # The installed git hook runs later under Git, outside this just/mise environment.
  68. # Injecting PREK_HOME keeps prek's cache under var/prek instead of a global home dir,
  69. # which is more predictable and works better in sandboxed tools like Codex/OpenCode.
  70. if [ -f "$hook" ] && ! grep -q '^export PREK_HOME=' "$hook"; then
  71. sed -i '2iexport PREK_HOME="{{ prek_home }}"' "$hook"
  72. fi
  73. # Runs the playbook with --tags=install-all,ensure-matrix-users-created,start and optional arguments
  74. install-all *extra_args: (run-tags "install-all,ensure-matrix-users-created,start" extra_args)
  75. # Runs installation tasks for a single service
  76. install-service service *extra_args:
  77. {{ just_executable() }} --justfile "{{ justfile() }}" run \
  78. --tags=install-{{ service }},start-group \
  79. --extra-vars=group={{ service }} {{ extra_args }}
  80. # Runs the playbook with --tags=setup-all,ensure-matrix-users-created,start and optional arguments
  81. setup-all *extra_args: (run-tags "setup-all,ensure-matrix-users-created,start" extra_args)
  82. # Runs the playbook with the given list of arguments
  83. run +extra_args:
  84. ansible-playbook -i inventory/hosts setup.yml {{ extra_args }}
  85. # Runs the playbook with the given list of comma-separated tags and optional arguments
  86. run-tags tags *extra_args:
  87. {{ just_executable() }} --justfile "{{ justfile() }}" run --tags={{ tags }} {{ extra_args }}
  88. # Runs the playbook in user-registration mode
  89. register-user username password admin_yes_or_no *extra_args:
  90. ansible-playbook -i inventory/hosts setup.yml --tags=register-user --extra-vars="username={{ username }} password={{ password }} admin={{ admin_yes_or_no }}" {{ extra_args }}
  91. # Starts all services
  92. start-all *extra_args: (run-tags "start-all" extra_args)
  93. # Starts a specific service group
  94. start-group group *extra_args:
  95. @{{ just_executable() }} --justfile "{{ justfile() }}" run-tags start-group --extra-vars="group={{ group }}" {{ extra_args }}
  96. # Stops all services
  97. stop-all *extra_args: (run-tags "stop-all" extra_args)
  98. # Stops a specific service group
  99. stop-group group *extra_args:
  100. @{{ just_executable() }} --justfile "{{ justfile() }}" run-tags stop-group --extra-vars="group={{ group }}" {{ extra_args }}
  101. # Rebuilds the mautrix-meta-instagram Ansible role using the mautrix-meta-messenger role as a source
  102. rebuild-mautrix-meta-instagram:
  103. /bin/bash "{{ justfile_directory() }}/bin/rebuild-mautrix-meta-instagram.sh" "{{ justfile_directory() }}/roles/custom"
  104. # Internal - ensures var/mise and var/prek directories exist
  105. _ensure_mise_data_directory:
  106. @mkdir -p "{{ mise_data_dir }}"
  107. @mkdir -p "{{ prek_home }}"
  108. # Internal - ensures mise tools are installed
  109. _ensure_mise_tools_installed: _ensure_mise_data_directory
  110. @{{ just_executable() }} --justfile "{{ justfile() }}" mise install --quiet