build-and-push.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. children="$("$(dirname "$BASH_SOURCE")/children.sh" "$@")"
  31. echo
  32. echo
  33. echo "Children: (of $*)"
  34. echo "${children:-<none>}"
  35. echo
  36. echo
  37. for repo in "${repos[@]}"; do
  38. tags=( ${repoTags[$repo]} )
  39. (
  40. set -x
  41. time "$BASHBREW" build "${tags[@]}"
  42. time "$BASHBREW" tag "${tags[@]}"
  43. time "$BASHBREW" push "${tags[@]}"
  44. )
  45. done
  46. echo
  47. echo
  48. echo "Children: (of $*)"
  49. echo "${children:-<none>}"
  50. echo
  51. echo
  52. if [ "$children" ]; then
  53. echo 'Suggested command:'
  54. echo " ./children.sh $* | xargs ./build-and-push.sh"
  55. echo
  56. fi
  57. # end by printing only warnings (stderr) for images we skipped (such as "windowsservercore" when building on Linux)
  58. # this helps remind us to switch BASHBREW or servers
  59. "$BASHBREW" list --apply-constraints "$@" > /dev/null