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

91 строка
2.4 KiB

  1. #!/bin/bash
  2. # Removes what `just molecule` leaves under var/.
  3. #
  4. # Called through `just molecule-clean [--idle-days N]`.
  5. #
  6. # Two things accumulate. The per-role Ansible homes are ~7 MB each and are
  7. # rewritten on every run rather than growing, so they are bounded by the number
  8. # of roles that have a scenario. The shared virtualenv is the bulk of it (over
  9. # 500 MB) and is recreated on the next run, which costs a pip install.
  10. #
  11. # Usage:
  12. # just molecule-clean # everything, after showing what and how much
  13. # just molecule-clean --idle-days 14 # only what has not been touched in 14 days
  14. # just molecule-clean --yes # skip the confirmation
  15. #
  16. # --idle-days is what makes this safe to run unattended: a scenario you ran this
  17. # morning keeps its cache, and only roles you have not touched in a while lose
  18. # theirs.
  19. set -euo pipefail
  20. repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  21. var_dir="${repo_dir}/var"
  22. idle_days=""
  23. assume_yes="false"
  24. while [ $# -gt 0 ]; do
  25. case "$1" in
  26. --idle-days)
  27. idle_days="${2:-}"
  28. if ! [[ "${idle_days}" =~ ^[0-9]+$ ]]; then
  29. echo "--idle-days needs a whole number of days" >&2
  30. exit 1
  31. fi
  32. shift 2
  33. ;;
  34. --yes|-y)
  35. assume_yes="true"
  36. shift
  37. ;;
  38. *)
  39. echo "Unknown argument: $1" >&2
  40. echo "Usage: just molecule-clean [--idle-days N] [--yes]" >&2
  41. exit 1
  42. ;;
  43. esac
  44. done
  45. # Only ever the two directories bin/molecule.sh creates, named explicitly. `var/`
  46. # holds other things and must never be removed wholesale.
  47. targets=()
  48. for candidate in "${var_dir}/molecule-ansible-home" "${var_dir}/molecule-venv"; do
  49. [ -d "${candidate}" ] || continue
  50. if [ -n "${idle_days}" ] && [ -z "$(find "${candidate}" -maxdepth 0 -mtime "+${idle_days}")" ]; then
  51. continue
  52. fi
  53. targets+=("${candidate}")
  54. done
  55. if [ ${#targets[@]} -eq 0 ]; then
  56. if [ -n "${idle_days}" ]; then
  57. echo "Nothing idle for more than ${idle_days} day(s)."
  58. else
  59. echo "Nothing to clean."
  60. fi
  61. exit 0
  62. fi
  63. echo "Would remove:"
  64. for target in "${targets[@]}"; do
  65. printf ' %s %s\n' "$(du -sh "${target}" | cut -f1)" "${target/#$HOME/\~}"
  66. done
  67. if [ "${assume_yes}" != "true" ]; then
  68. read -r -p "Remove these? [y/N] " reply
  69. case "${reply}" in
  70. y|Y|yes|YES) ;;
  71. *) echo "Left alone."; exit 0 ;;
  72. esac
  73. fi
  74. for target in "${targets[@]}"; do
  75. rm -rf "${target}"
  76. echo "Removed ${target/#$HOME/\~}"
  77. done
  78. echo "The virtualenv is recreated on the next \`just molecule\` run."