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.
 
 

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