build-and-push.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. # set "$0" so that tmux shows something more useful than "bash" in the statusbar
  4. desired0='b-a-p'
  5. if ! grep -q "$desired0" "/proc/$$/cmdline"; then
  6. exec -a "$desired0" "$SHELL" -- "$BASH_SOURCE" "$@"
  7. fi
  8. if [ "$#" -eq 0 ]; then
  9. self="$(basename "$0")"
  10. cat >&2 <<-EOF
  11. error: missing arguments
  12. usage: $self <build args>
  13. ie: $self debian ubuntu
  14. EOF
  15. exit 1
  16. fi
  17. # allow for specifying an alternate path to "bashbrew"
  18. : "${BASHBREW:=bashbrew}"
  19. # normalize "$@" to be the "--uniq" versions (and deduplicate)
  20. # also grab the list of associated repos in explicit build order (so we can build/push grouped by repo)
  21. IFS=$'\n'
  22. set -- $("$BASHBREW" list --uniq --repos "$@" | sort -u | xargs "$BASHBREW" list --uniq --repos --build-order)
  23. repos=( $(echo "$*" | cut -d: -f1 | xargs "$BASHBREW" list --repos --build-order) )
  24. unset IFS
  25. declare -A repoTags=()
  26. for repoTag; do
  27. repo="${repoTag%%:*}"
  28. repoTags[$repo]+=" $repoTag"
  29. done
  30. # fill "$@" back up with the corrected build order (especially for the "Children:" output)
  31. set --
  32. for repo in "${repos[@]}"; do
  33. set -- "$@" ${repoTags[$repo]}
  34. done
  35. children="$("$(dirname "$BASH_SOURCE")/children.sh" "$@")"
  36. echo
  37. echo
  38. echo "Children: (of $*)"
  39. echo "${children:-<none>}"
  40. echo
  41. echo
  42. for repo in "${repos[@]}"; do
  43. tags=( ${repoTags[$repo]} )
  44. (
  45. set -x
  46. time "$BASHBREW" build "${tags[@]}"
  47. time "$BASHBREW" tag "${tags[@]}"
  48. time "$BASHBREW" push "${tags[@]}"
  49. )
  50. done
  51. echo
  52. echo
  53. echo "Children: (of $*)"
  54. echo "${children:-<none>}"
  55. echo
  56. echo
  57. if [ "$children" ]; then
  58. echo 'Suggested command:'
  59. echo " ./children.sh $* | xargs ./build-and-push.sh"
  60. echo
  61. fi
  62. # end by printing only warnings (stderr) for images we skipped (such as "windowsservercore" when building on Linux)
  63. # this helps remind us to switch BASHBREW or servers
  64. "$BASHBREW" list --apply-constraints "$@" > /dev/null