run.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. [ "$DEBUG" ] && set -x
  3. set -eo pipefail
  4. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  5. image="$1"
  6. clientImage='buildpack-deps:stretch-curl'
  7. # Create an instance of the container-under-test
  8. serverImage="$("$dir/../image-name.sh" librarytest/haproxy-basics "$image")"
  9. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  10. FROM $image
  11. COPY dir/haproxy.cfg /usr/local/etc/haproxy/
  12. EOD
  13. cid="$(docker run -d "$serverImage")"
  14. trap "docker rm -vf $cid > /dev/null" EXIT
  15. _request() {
  16. local method="$1"
  17. shift
  18. local proto="$1"
  19. shift
  20. local url="${1#/}"
  21. shift
  22. if [ "$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null)" != 'true' ]; then
  23. echo >&2 "$image stopped unexpectedly!"
  24. ( set -x && docker logs "$cid" ) >&2 || true
  25. false
  26. fi
  27. docker run --rm --link "$cid":haproxy "$clientImage" \
  28. curl -fsSL -X"$method" --connect-to '::haproxy:' "$@" "$proto://example.com/$url"
  29. }
  30. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  31. # Check that we can request / (which is proxying example.com)
  32. _request GET http '/' |tac|tac| grep -q '<h1>Example Domain</h1>'
  33. _request GET https '/' |tac|tac| grep -q '<h1>Example Domain</h1>'