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.
 
 
 

85 linhas
2.5 KiB

  1. #!/bin/bash
  2. # Runs a role's Molecule scenario locally.
  3. #
  4. # Called through `just molecule [role] [args...]`. With no role, lists the roles
  5. # that have a scenario.
  6. #
  7. # The same scenarios run in CI (.github/workflows/molecule.yml), but running one
  8. # here is the faster loop while writing or fixing a role: CI only tells you after
  9. # a push, and only about the roles that push touched.
  10. #
  11. # Deliberately NOT wired into prek. A run takes minutes, pulls container images
  12. # and needs a working Docker - which is fine when you ask for it, and not fine on
  13. # every commit.
  14. #
  15. # Usage:
  16. # just molecule # list roles that have a scenario
  17. # just molecule matrix-alertmanager-receiver
  18. # just molecule matrix-alertmanager-receiver converge # any molecule subcommand
  19. #
  20. # Environment:
  21. # MOLECULE_DISTRO base image to test on (default: ubuntu2604)
  22. set -euo pipefail
  23. repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  24. roles_dir="${repo_dir}/roles/custom"
  25. venv_dir="${repo_dir}/var/molecule-venv"
  26. list_roles() {
  27. find "${roles_dir}" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
  28. | while read -r candidate; do
  29. if [ -f "${roles_dir}/${candidate}/molecule/default/molecule.yml" ]; then
  30. echo "${candidate}"
  31. fi
  32. done \
  33. | sort
  34. }
  35. role="${1:-}"
  36. if [ -z "${role}" ]; then
  37. echo "Roles with a Molecule scenario:"
  38. found="$(list_roles)"
  39. if [ -z "${found}" ]; then
  40. echo " (none yet)"
  41. else
  42. printf ' %s\n' ${found}
  43. fi
  44. echo
  45. echo "Run one with: just molecule <role>"
  46. exit 0
  47. fi
  48. shift || true
  49. if [ ! -f "${roles_dir}/${role}/molecule/default/molecule.yml" ]; then
  50. echo "No Molecule scenario at roles/custom/${role}/molecule/default" >&2
  51. echo >&2
  52. echo "Roles that have one:" >&2
  53. list_roles | sed 's/^/ /' >&2
  54. exit 1
  55. fi
  56. # The virtualenv lives under var/, which is gitignored, and is shared by every
  57. # role - the dependencies are the same for all of them.
  58. if [ ! -x "${venv_dir}/bin/molecule" ]; then
  59. echo "Creating the Molecule virtualenv in ${venv_dir/#$HOME/\~} ..."
  60. python3 -m venv "${venv_dir}"
  61. "${venv_dir}/bin/pip" install --quiet --upgrade pip
  62. "${venv_dir}/bin/pip" install --quiet -r "${repo_dir}/molecule-shared/requirements.txt"
  63. fi
  64. export MOLECULE_DISTRO="${MOLECULE_DISTRO:-ubuntu2604}"
  65. export PY_COLORS="${PY_COLORS:-1}"
  66. export ANSIBLE_FORCE_COLOR="${ANSIBLE_FORCE_COLOR:-1}"
  67. echo "Running Molecule for ${role} on ${MOLECULE_DISTRO} ..."
  68. cd "${roles_dir}/${role}"
  69. if [ $# -eq 0 ]; then
  70. exec "${venv_dir}/bin/molecule" test --scenario-name default
  71. fi
  72. exec "${venv_dir}/bin/molecule" "$@" --scenario-name default