run.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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:bookworm-curl'
  7. # ensure the clientImage is ready and available
  8. if ! docker image inspect "$clientImage" &> /dev/null; then
  9. docker pull "$clientImage" > /dev/null
  10. fi
  11. # Create an instance of the container-under-test
  12. serverImage="$("$dir/../image-name.sh" librarytest/haproxy-basics "$image")"
  13. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  14. FROM $image
  15. COPY dir/haproxy.cfg /usr/local/etc/haproxy/
  16. EOD
  17. cid="$(docker run -d --sysctl net.ipv4.ip_unprivileged_port_start=0 "$serverImage")"
  18. trap "docker rm -vf $cid > /dev/null" EXIT
  19. _request() {
  20. local method="$1"
  21. shift
  22. local proto="$1"
  23. shift
  24. local url="${1#/}"
  25. shift
  26. if [ "$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null)" != 'true' ]; then
  27. echo >&2 "$image stopped unexpectedly!"
  28. ( set -x && docker logs "$cid" ) >&2 || true
  29. false
  30. fi
  31. docker run --rm \
  32. --link "$cid":haproxy \
  33. "$clientImage" \
  34. curl -fsSL -X"$method" --connect-to '::haproxy:' "$@" "$proto://example.com/$url"
  35. }
  36. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  37. # Check that we can request / (which is proxying example.com)
  38. _request GET http '/' | grep '<h1>Example Domain</h1>' > /dev/null
  39. _request GET https '/' | grep '<h1>Example Domain</h1>' > /dev/null