run.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Use a client image with curl for testing
  6. clientImage='buildpack-deps:buster-curl'
  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 \
  21. --link "$cid":apache \
  22. "$clientImage" \
  23. curl -fs -X"$method" "$@" "http://apache/$url"
  24. }
  25. # Make sure that Apache is listening
  26. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  27. # Check that we can request /index.php with no params
  28. [ -n "$(_request GET "/index.php")" ]
  29. # Check that our index.php echoes the value of the "hello" param
  30. hello="world-$RANDOM-$RANDOM"
  31. [ "$(_request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]