run.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Build a client image with cgi-fcgi for testing
  6. client_image="librarytest/php-fpm-hello-web:fcgi"
  7. docker build -q -t "$client_image" - > /dev/null <<EOF
  8. FROM debian:jessie
  9. RUN set -x; apt-get update && apt-get install -y libfcgi0ldbl && rm -rf /var/lib/apt/lists/*
  10. ENTRYPOINT ["cgi-fcgi"]
  11. EOF
  12. # Create an instance of the container-under-test
  13. cname="php-fpm-container-$RANDOM-$RANDOM"
  14. cid="$(docker run -d -v "$dir/index.php":/var/www/html/index.php:ro --name "$cname" "$image")"
  15. trap "docker rm -f $cid > /dev/null" EXIT
  16. fcgi-request() {
  17. local method="$1"
  18. local url="$2"
  19. local queryString=
  20. if [[ "$url" == *\?* ]]; then
  21. queryString="${url#*\?}"
  22. url="${url%%\?*}"
  23. fi
  24. docker run --rm -i --link "$cname":fpm \
  25. -e REQUEST_METHOD="$method" \
  26. -e SCRIPT_NAME="$url" \
  27. -e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
  28. -e QUERY_STRING="$queryString" \
  29. "$client_image" \
  30. -bind -connect fpm:9000
  31. }
  32. # Check that we can request /index.php with no params
  33. [ -n "$(fcgi-request GET "/index.php")" ]
  34. # Check that our index.php echoes the value of the "hello" param
  35. hello="world-$RANDOM-$RANDOM"
  36. [ "$(fcgi-request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]