run.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # since we have curl in the php image, we'll use that
  6. clientImage="$1"
  7. serverImage="$("$dir/../image-name.sh" librarytest/php-apache-hello-web "$image")"
  8. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  9. FROM $image
  10. COPY dir/index.php /var/www/html/
  11. EOD
  12. # Create an instance of the container-under-test
  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 url="${1#/}"
  19. shift
  20. docker run --rm --link "$cid":apache "$clientImage" \
  21. curl -fs -X"$method" "$@" "http://apache/$url"
  22. }
  23. # Make sure that Apache is listening
  24. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  25. # Check that we can request /index.php with no params
  26. [ -n "$(_request GET "/index.php")" ]
  27. # Check that our index.php echoes the value of the "hello" param
  28. hello="world-$RANDOM-$RANDOM"
  29. [ "$(_request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]